在JSF应用程序中使所有cookie安全
如何在Java Web / JSF应用程序中使所有Cookies安全?
我在Web.xml中添加了以下行,以使JSessionId安全和HTTPonly。但是,其他饼干并不安全。
<session-config>
<session-timeout>
15
</session-timeout>
<cookie-config>
<http-only>true</http-only>
<secure>true</secure>
<max-age>6000</max-age>
</cookie-config>
</session-config>
如果可以通过更改web.xml文件来实现这一点,那将很棒。
How can I make all cookies secure in a Java Web / JSF Application?
I added the following lines to web.xml to make JSESSIONID secure and httpOnly. Yet, the other cookies are not secure.
<session-config>
<session-timeout>
15
</session-timeout>
<cookie-config>
<http-only>true</http-only>
<secure>true</secure>
<max-age>6000</max-age>
</cookie-config>
</session-config>
If that can be achieved by changing the web.xml file, that will be great.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
cookie可以由您的代码或您使用的框架代码任意创建并附加到响应上。根据 servlet api 。您可以使用
cookie.setsecure()
方法将此标志设置为true
对于任何特定的cookie,但是没有办法强制执行此标志以始终为true。您必须在每个特定情况下解决此问题。A cookie can be arbitrarily created and attached to the response by your code or by the code of the frameworks that you use. The default value of the
secure
flag isfalse
, according to the servlet API. You can useCookie.setSecure()
method to set this flag totrue
for any particular cookie, but there's no way to enforce this flag to always be true. You'd have to solve this issue for every particular case.我认为上面选择的答案对您的要求是正确的。的确,您可以使用该方法创建一个安全的cookie,但是您询问了会话cookie,这不是使用他描述的方法创建的。
不过,您拥有的配置是正确的,但仅当您的容器支持它时才有效。
我在最新版本的Tomcat 9上对此进行了测试,并且cookie的生产正确。
I don't believe this selected answer above is correct for what you're asking. It's true that you can create a secure cookie using that method, but you're asking about the session cookie, which is not created using the method he describes.
The configuration you have is correct though, but only works if your container supports it.
I tested this locally on the most recent version of Tomcat 9 and the cookie was produced correctly.