How to pass sensitive data from FreeMarker to JavaScript without exposing it in the browser

29 Views Asked by At

I'm getting a secure private key by executing server-side function in freemarker template. I have to pass the private key to other javascript file but the key is exposed in the DOM during the initial rendering of a FreeMarker template.

I want to prevent exposing it in the DOM and make sure that the generation function is not executed until it's explicitly called, keeping the secure value hidden from the DOM. Please let me know if there's any way to pass this secure key privately from freemarker to JS file.

My code in the default.ftl is below

<#include "../...">
..
..

<#assign> ...</#assign>

<html>
    <head>
        <script>
           /*generateSecureValue is the server-side function */
            const getSecureValue = () => '${generateSecureValue()}'
        </script>
    </head>
...
...
</html>

In the above code generateSecureValue is immediately executed and is exposed in the DOM. I cn only execute this function in freemarker template. How do i share this securely to other child components in javascript?

0

There are 0 best solutions below