dongranding3909 2014-07-17 11:27
浏览 110

哪里可以在浏览器上存储敏感数据?

I have some data like UserId, tokenId, sessionId which i have to pass which every ajax call that used for validation /authentication/processing.

I stored that data in global JS object. So when user view source of page , this will visible to them.

According to penetration security team of my organisation , its security threat to show sensitive data like us UserId, tokenId, sessionId on viewing source.

How to store that data in js/browser that on viewing source it will not visible? How different approaches used by web development company to store data like userId? Storing this data in cookie or encryption will be performance hit as its heavily used.

tokenId is an CRSF token ID and sessionId is the session ID.

  • 写回答

1条回答 默认 最新

  • dpg98445 2014-07-18 12:19
    关注

    I'll have to answer this based on a lot of assumptions, but I'll update my answer if you edit your question and let me know.

    What is UserId?

    If this is a cleartext ID of the user then it could be a risk to your system.

    e.g. if your admin account had ID 0 and then a malicious user set their UserId cookie to 0 - would this enable the malicious user to act admin?

    You haven't said what tokenId or sessionId are either so it is difficult to comment further, but for the purposes of this answer I will assume that tokenId is an Anti-CRSF token and sessionId is the authentication session ID.

    If this is the case, then UserId should not come from a cookie value or from a hidden field on your page - it should be derived server-side from sessionId and should come from whichever session the current user has authenticated with.

    There is no inherent risk of displaying tokenId and sessionId in source if you have set the appropriate headers to disable public caching, but if these values are already available in cookies then there is no need to set them again in code. This smells of a potential business logic flaw as your AJAX request will be sending the values in two ways (request and cookie) - so make sure that you are only using one way to ensure all your logic is consistent.

    So to summarise, the most "secure" place for session data is actually in cookies because they will not be cached outside of the cookie mechanism (such as within the source of cached pages). However, make sure that these cookies are only sent over HTTPS and are not available over the DOM by setting the Secure and HTTP Only flags.

    评论

报告相同问题?

悬赏问题

  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题