【问题标题】:Security-constraint web.xml url-pattern safety安全约束 web.xml url-模式安全
【发布时间】:2013-05-23 09:58:16
【问题描述】:

我想知道以下配置是否安全:

/ManageXXXX.do/ManageYYYY.do、... 位置可访问的网页应该只能由 admin 角色访问,其他所有页面都可供任何人使用。

我已经这样配置了 web.xml 文件:

     <security-constraint>
        <web-resource-collection>
            <url-pattern>/Manage*</url-pattern>
        </web-resource-collection>
        <auth-constraint>
            <role-name>admin</role-name>    
        </auth-constraint>  
    </security-constraint>

现在我想知道这对于试图通过安检的人来说有多可靠。这可以保证阻止未经授权的用户访问我的Manage* 页面吗?我只是想知道这种模式匹配有多安全。

【问题讨论】:

    标签: apache tomcat struts web.xml security-constraint


    【解决方案1】:

    来自 Servlet API 规范: http://www.jcp.org/aboutJava/communityprocess/mrel/jsr154/

    SRV.11.2 Specification of Mappings
    In the Web application deployment descriptor, the following syntax is used to define
    mappings:
    • A string beginning with a ‘/’ character and ending with a ‘/*’ suffix is used for path mapping.
    • A string beginning with a ‘*.’ prefix is used as an extension mapping.
    • A string containing only the ’/’ character indicates the "default" servlet of
    the application. In this case the servlet path is the request URI minus the con-
    text path and the path info is null.
    • All other strings are used for exact matches only.
    

    根据 Servlet API 规范,模式 /Manage* 是“仅精确匹配”,这不是您想要的。 请将角色管理员的所有资源移至/Manage/ 并配置模式&lt;url-pattern&gt;/Manage/*&lt;/url-pattern&gt;

    【讨论】:

    • 奇怪,因为我现在设置它的方式是正确处理安全性,并将 url-pattern 设置为 /Manage* 用于 /ManageX.do、/ManageY.do 等页面。跨度>
    • 如您所见,它是从规范中复制的 :) 请确保没有管理员角色的用户无法访问它
    • 我已验证没有管理员角色的用户无法访问任何 /Manage* 页面。
    • 所以,实现不符合规范:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-18
    • 2012-11-23
    • 2023-03-30
    • 1970-01-01
    • 2013-05-19
    • 2011-11-01
    相关资源
    最近更新 更多