在web.xml中设置'HttpOnly'和'Secure'

EH *_*ari 7 security cookies session web.xml httponly

我需要将'HttpOnly'和'Secure'属性设置为'true'以防止CWE-614:HTTPS会话中的敏感Cookie而没有'安全'属性CWE-402:将私有资源传输到新的Sphere漏洞显示在Veracode报告中.

在进行一些在线搜索之后,最好的办法是简单地在项目的web.xml文件中设置属性,如下所示:

<session-config>
    <cookie-config>
        <http-only>true</http-only>
        <secure>true</secure>
    </cookie-config>
 </session-config>
Run Code Online (Sandbox Code Playgroud)

但是,我在开始标记上收到一条错误消息,说"元素类型的内容"session-config"必须匹配"(session-timeout)?".

我不确定这究竟是什么意思.我猜它与元素的顺序有关,但我真的不知道如何修复它.

有什么想法吗?

谢谢!

小智 12

对secure-http-only属性的支持仅在http-servlet规范3上可用.检查web.xml中的version属性是否为"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">
Run Code Online (Sandbox Code Playgroud)