Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can user modify the values of variables stored in sessionStorage

I'm using client-side JavaScript to store some variables using Web Storage, more specifically, the sessionStorage.

But I'm not sure whether a user can simply modify the value of such variables in any way? If so, please provide an example of how this could happen.

like image 203
skyork Avatar asked Feb 10 '13 18:02

skyork


People also ask

What should not be stored in session?

Things like Database Data such as User Rows should not be stored in the session and you should create a separate cache mechanism to do this for you. Save this answer.

What happens when sessionStorage is full?

The data is not stored and no existing data is overwritten. A QUOTA_EXCEEDED_ERR exception is thrown.

What is the main difference between localStorage and sessionStorage?

The difference between sessionStorage and localStorage is that localStorage data does not expire, whereas sessionStorage data is cleared when the page session ends. A unique page session gets created once a document is loaded in a browser tab. Page sessions are valid for only one tab at a time.


2 Answers

Yes, users can always modify the values of their own storage. I can think of three ways right off the bat:

  • use web browser console to run JS commands that modify storage
  • setup client-hosted site with client-specified DNS to run their own code that modifies storage
  • open the local storage files and manually edit them

What's important is that you don't trust client storage. If you're going to store session information on the client, then you need some way for your server-side code to verify that the information hasn't been tampered with. There are other reasons you may not want to store this information on the client side (privacy, for example), but assuming you've thought through those, you still need to make sure you either trust the client's data or that you make sure trust isn't necessary.

like image 138
hrunting Avatar answered Oct 10 '22 23:10

hrunting


Not exactly sure in your case, but as a rule sessions should always be handled server side and not client side. The one of the main points of sessions is to remove that data from the client side altogether for security reasons

like image 21
Tucker Avatar answered Oct 10 '22 23:10

Tucker