首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >web.xml中的白名单安全约束

web.xml中的白名单安全约束
EN

Stack Overflow用户
提问于 2011-11-10 02:21:21
回答 3查看 42.3K关注 0票数 26

我正在为我的Struts2应用程序使用Tomcat。web.xml包含某些条目,如下所示:

代码语言:javascript
复制
<security-constraint>
    <web-resource-collection>
        <web-resource-name>restricted methods</web-resource-name>
        <url-pattern>/*</url-pattern>
        <http-method>PUT</http-method>
        <http-method>DELETE</http-method>
        <http-method>TRACE</http-method>
    </web-resource-collection>
    <auth-constraint />
</security-constraint>
<security-constraint>
   <web-resource-collection>
       <web-resource-name>no_access</web-resource-name>
       <url-pattern>/jsp/*</url-pattern>
   </web-resource-collection>
   <auth-constraint/>
</security-constraint>
    <security-constraint>
   <web-resource-collection>
       <web-resource-name>no_access</web-resource-name>
       <url-pattern>/myrrunner/*</url-pattern>
   </web-resource-collection>
   <auth-constraint/>
</security-constraint>

如何将上述黑名单部分改为只使用白名单部分…例如,我需要将其他方法列入白名单,而不是将PUTDELTE http方法列入黑名单,但我不确定将它们列入白名单的语法&应该将哪些方法列入白名单。

对于我上面的web.xml片段,如果有人能为我提供上面xml的白化对应部分,我将不胜感激。

编辑:另外,我如何真正验证解决方案是否有效?

谢谢

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2011-11-10 04:53:37

我会尝试以下几点:

代码语言:javascript
复制
<security-constraint>
    <web-resource-collection>
        <url-pattern>/*</url-pattern>
        <http-method>GET</http-method>
        <http-method>POST</http-method>
    </web-resource-collection>
    <!-- no auth-constraint tag here -->
</security-constraint>

<security-constraint>
    <web-resource-collection>
        <web-resource-name>restricted methods</web-resource-name>
        <url-pattern>/*</url-pattern>
    </web-resource-collection>
   <auth-constraint/>
</security-constraint>

第一个security-constraint没有任何auth-constraint,因此任何没有登录的人都可以使用GET和POST方法。第二个限制了所有人都可以使用的其他http方法。(我还没试过。)

票数 23
EN

Stack Overflow用户

发布于 2013-10-22 08:05:30

Java EE 6的新特性简化了应用程序的安全配置。您现在可以在您的web.xml中设置允许的HTTP方法的白名单和黑名单:

代码语言:javascript
复制
<security-constraint>
    <web-resource-collection>
        <web-resource-name>Disable unneeded HTTP methods by 403 Forbidden them</web-resource-name>
        <url-pattern>*</url-pattern>
        <http-method-omission>GET</http-method-omission>
        <http-method-omission>HEAD</http-method-omission>
        <http-method-omission>POST</http-method-omission>
    </web-resource-collection>
    <auth-constraint />
</security-constraint>

参考:https://docs.oracle.com/cd/E19798-01/821-1841/bncbk/index.html#6nmq2cpkb

票数 15
EN

Stack Overflow用户

发布于 2016-04-20 04:28:11

对接受的答案稍作调整(将第二个security-constraint中的url-pattern设置为映射到默认的servlet "/")对JBoss和Weblogic有效,但对Websphere无效:

代码语言:javascript
复制
<security-constraint>
    <web-resource-collection>
        <web-resource-name>Allowed methods</web-resource-name>
        <url-pattern>/*</url-pattern>
        <http-method>GET</http-method>
        <http-method>POST</http-method>
    </web-resource-collection>
    <!-- no auth-constraint tag here -->
</security-constraint>
<security-constraint>
    <web-resource-collection>
        <web-resource-name>Restricted methods</web-resource-name>
        <url-pattern>/</url-pattern>
    </web-resource-collection>
    <auth-constraint />
</security-constraint>

有了上面的安全约束配置,我不确定为什么Websphere允许所有的HTTP方法,而JBoss和Weblogic只允许GETPOST

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8069640

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档