任何人都可以劫持(通过 js)asp.net 表单 cookie 并更改过期日期吗?
任何人都可以劫持(通过 js)asp.net 表单 cookie 并更改过期日期吗?
什么可以阻止他们抓住它并更改过期日期? 即有效地让用户保持登录状态?
更新
.net框架是否形成auth。 cookie 依赖于 cookie 的过期日期还是对其进行加密?
Can anyone hijack (via js) the asp.net forms cookie and change the expire date?
What can stop them from grabbing it and changing the expire date? i.e. effectively letting the user stay logged in?
Update
Does the .net framework forms auth. cookie rely on the cookie's expiration date or does it encypt that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您可以采取一些措施来改善这种情况。
在 web.config 中,为 cookie 设置保护 =“全部”: http:// /msdn.microsoft.com/en-us/library/1d3t3c61.aspx。 这将进行加密和验证,使破解客户端变得更加困难。
此外,cookie 可以将 httpOnly 设置为 true。 这告诉浏览器 cookie 不能在 javascript 中操作。
<表格> web.config 中的元素也有一个超时设置(请参阅上面的链接)。 微软的实现可能足够聪明,不会仅仅依赖于cookie,但我不知道。
其他评论是正确的,即客户永远不应该被信任。 因此,为了做到无懈可击,您需要跟踪服务器上的“上次登录”并在一段时间后强制进行新登录。
There are a few things you can do to improve the situation.
In web.config, set protection="All" for the cookie: http://msdn.microsoft.com/en-us/library/1d3t3c61.aspx. This will encrypt and validate, making it harder to hack client-side.
Additionally, cookies can have httpOnly set to true. This tells the browser that the cookie cannot be manipulated in javascript.
The <forms> element in web.config also has a setting for timeout (see link above). It's possible that Microsoft's implementation is smart enough not to depend solely on the cookie, but I don't know.
The other comments are correct that the client should never be trusted. So to be airtight, you'll want to track "last login" on the server and force a new login after some time period.
Cookie 由客户端存储,您不能相信它们不会更改。
Firefox 的扩展允许您编辑 cookie,包括过期日期。 如果您希望他们强制它们过期,您也应该在服务器端跟踪它们并在那里使它们过期。
Cookies are stored by the client, you can't trust them not to change.
There are extensions for Firefox that let you edit cookies, including the expire dates. If you want them to force them to expire you should be tracking them server side too and expire them there.
在服务器端跟踪它。
Track it server side.
通过 JS (JavaScript) 是不可能的,至少在支持 ASP.NET 为 Forms cookie 设置的 HttpOnly 属性的浏览器中是不可能的。
Via JS (JavaScript) it is not possible, at least not in a browser that honors the HttpOnly attribute that ASP.NET sets for the Forms cookie.
不太确定 JavaScript,但您可以使用 Fire Fox 的 Cookie 编辑器附加功能进行
加密,
在 cookie 中设置一个额外的日期标志
well not sure about javascript but you can do it using Cookie Editor add on of Fire Fox
encrypt it
set a additional date flag inside the cookie
如果您想防止这种情况发生,请将过期日期散列到 cookie 值中。 然后,当您检索 cookie 时,如果散列到期日期与明文到期日期不匹配,则丢弃该 cookie。
If you want to prevent this, hash the expiration date into the cookie value. Then, when you retrieve the cookie, if the hashed expiration date doesn't match the plaintext expiration date, discard the cookie.