servlet设置cookie安全吗?

发布于 2024-10-09 16:31:48 字数 203 浏览 0 评论 0原文

javax.servlet.http.Cookie implements java.lang.Cloneable

在Cookie方法中,有一个方法叫“setSecure”,它有什么用呢?如果我 setSecure(true),我需要在客户端(javascript)端做什么来读取 cookie?设置/不设置 setSecure 有什么不同?

javax.servlet.http.Cookie implements java.lang.Cloneable

In Cookie method, there is a method call "setSecure" , what does it use for? if i setSecure(true), is there anything i need to do on my client(javascript) side to read the cookie? what is different set/without setSecure?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

落墨 2024-10-16 16:31:48

所有这些 setSecure(true ) 的作用是告诉浏览器,只有使用“安全”协议(例如 https)时,才应将 cookie 发送回服务器。您的 JavaScript 代码不必做任何不同的事情。

All that setSecure(true) does is tell the browser that the cookie should only be sent back to the server if using a "secure" protocol, like https. Your JavaScript code doesn't have to do anything different.

智商已欠费 2024-10-16 16:31:48

是的,这可以确保您的会话 cookie 对攻击者不可见,例如中间人攻击。除了手动设置之外,您还可以配置 web.xml 以自动为您处理它。

<session-config>
   <cookie-config>
      <secure>true</secure>
   </cookie-config>
</session-config>

Yup this ensures that your session cookie is not visible to an attacker like man-in-the-middle attack. Instead of setting it manually You could alternatively configure your web.xml to handle it for you automatically.

<session-config>
   <cookie-config>
      <secure>true</secure>
   </cookie-config>
</session-config>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文