在 web.xml 中设置“HttpOnly”和“Secure”

问题描述 投票:0回答:2

我需要将“HttpOnly”和“Secure”属性设置为“true”,以防止出现 CWE-614:没有“安全”属性的 HTTPS 会话中的敏感 Cookie CWE-402:将私有资源传输到Veracode 报告中显示的 New Sphere 缺陷。

在网上搜索了一下,似乎最好的办法就是简单地在项目的 web.xml 文件中设置属性,如下所示:

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

但是,我在开始标签上收到一条错误消息,指出 “元素类型“session-config”的内容必须匹配“(session-timeout)?”

我不确定这到底是什么意思。我猜这与元素的顺序有关,但我真的不知道如何解决它。

有什么想法吗?

谢谢!

security session cookies web.xml httponly
2个回答
25
投票

对安全和仅 http 属性的支持仅在 http-servlet 规范中可用 3. 检查 web.xml 中的版本属性是否为“3.0”。

<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
            http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
     version="3.0">

0
投票

在 4.0 版本中使用

cookie-config
标签。

<session-config>
     <cookie-config>
         <http-only>true</http-only>
         <secure>true</secure>
     </cookie-config>
</session-config>
© www.soinside.com 2019 - 2024. All rights reserved.