Can session storage be safe?

前端 未结 2 597
情书的邮戳
情书的邮戳 2021-01-31 05:02

I would like to use session storage to query user data in the database only once and then simply use JS to retrieve it, so I\'m thinking about using session storage. My question

2条回答
  •  一整个雨季
    2021-01-31 05:44

    Since the session storage can only be read by JavaScript that is running on your page, I think your question boils down to "How can JavaScript be excuted/inserted into my page?" There are two attack methods: XSS, meaning some way to inject JavaScript into your page through posting data to your site. If this data is not filtered, it may insert script tags or JavaScript events into your HTML. There are many ways to do this and to protect against it, so I can't be more specific.

    A lesser threat would be to trick the site into displaying or changing information through specially crafted links that call specific actions on your page. This technique is called CSRF. Example: Someone crafts a link to the "change email" page and tricks a user who is logged into clicking this link, this changing the email info in the session storage.

    If your application is public, anyone can open the session storage in his browser and look up the names of the keys. So unless they are randomized obscurity offers no protection here.

提交回复
热议问题