Why is this an issue?
localStorage
is a javascript function that allows you to save information based on a specific key, for example:
1
localStorage.setItem("bestInstanceAnalyzer", "CODA");
This way, at any time you can request for this information in the code:
1
var analyzer = localStorage.getItem("bestInstanceAnalyzer");
However, this is not the best way, since the data is saved exclusively on the client, which is a major security breach. Sensitive information and personal data are very exposed and with little protection.
Best practices
The safe way to do this type of operation is to save the data on the server side and then request this information on the client. There are different ways to do it, the best known are GlideAjax API and even the REST API. However in this article, we will bring an example of how to do it using the user session.
Basically, this method consists of saving the information in the user's session (through the server) and then requesting it via client.
On server-side, you can put information in session as show:
1
gs.getSession().putClientData("myData", "Hello, world!");
And in client-side, you can get this information:
1 2
//Variable `message` has a "Hello, world!" value var message = g_user.getClientData("myData");
That way, in client, you will only be reading the information, which will be stored only on the server.
You can also clear this session information (in server-side) by calling clearClientData()
and passing the data key as a parameter:
1
gs.getSession().clearClientData("myData");