首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在JBoss中禁用HTTP OPTIONS方法?

如何在JBoss中禁用HTTP OPTIONS方法?
EN

Stack Overflow用户
提问于 2016-12-08 17:14:02
回答 5查看 10.8K关注 0票数 2

我正在尝试禁用JBOSS HTTP选项方法。在JBoss的web.xml中使用以下语法,我可以禁用除选项之外的所有http方法。有没有办法成功禁用http-method选项?

click here for screenshot

代码语言:javascript
复制
<security-constraint>  
<web-resource-collection>  
    <web-resource-name>Restricted</web-resource-name>  
    <description>Declarative security tests</description>  
    <url-pattern>/EVE/*</url-pattern>       
    <http-method>PUT</http-method>  
    <http-method>DELETE</http-method>
    <http-method>OPTIONS</http-method>
    <http-method>TRACE</http-method>    
</web-resource-collection>  
<auth-constraint>  
    <description>Only authenticated users can access secure content</description>  
    <role-name>AuthorizedUser</role-name>  
</auth-constraint>  
<user-data-constraint>  
    <description>no description</description>  
    <transport-guarantee>NONE</transport-guarantee>  
</user-data-constraint>  
</security-constraint>  <security-constraint>  
<web-resource-collection>  
    <web-resource-name>Restricted 2</web-resource-name>  
    <description>Declarative security tests</description>  
    <url-pattern>/*</url-pattern>        
    <http-method>PUT</http-method>  
    <http-method>DELETE</http-method> 
    <http-method>OPTIONS</http-method>
    <http-method>TRACE</http-method>  
</web-resource-collection>  
<auth-constraint>  
    <description>Only authenticated users can access secure content</description>  
    <role-name>AuthorizedUser</role-name>  
</auth-constraint>  
<user-data-constraint>  
    <description>no description</description>  
    <transport-guarantee>NONE</transport-guarantee>  
</user-data-constraint>  
</security-constraint>
EN

回答 5

Stack Overflow用户

发布于 2016-12-15 13:13:43

选项1-使用RewriteValve (可全局应用)

可以使用RewriteValve禁用http方法。看看documentation吧。您将需要一个RewriteCond指令和一个RewriteRule。

在RewriteCond指令中,您可以使用REQUEST_METHOD服务器变量指定所有方法,例如:

代码语言:javascript
复制
RewriteCond %{REQUEST_METHOD} ^(PUT|DELETE|TRACE|OPTIONS)$ [NC]

然后,您的RewriteRule可以将这些标记为禁止的(它立即返回一个403 (禁止的)的HTTP响应),例如:

代码语言:javascript
复制
RewriteRule .* - [F]

如果是Jboss EAP 6

代码语言:javascript
复制
<subsystem xmlns="urn:jboss:domain:web:1.1" default-virtual-server="default-host" native="false">
    <connector name="http" protocol="HTTP/1.1" scheme="http" socket-binding="http"/>
    <virtual-server name="default-host" enable-welcome-root="true">
        <rewrite pattern=".*" substitution="-" flags="F">
            <condition test="%{REQUEST_METHOD}" pattern="^(PUT|DELETE|TRACE|OPTIONS)$" flags="NC" />
    </rewrite>
    </virtual-server>
</subsystem>

除此之外,正如在上面的回答中所说的,它可以通过每个战争的web.xml完成。

要检查以上内容,请使用

代码语言:javascript
复制
curl -v -X TRACE http://hostname:port/appContext
curl -v -X DELETE http://hostname:port/appContex
票数 4
EN

Stack Overflow用户

发布于 2016-12-08 19:44:51

代码语言:javascript
复制
here are the following ways to limit HTTP methods in a web application:

1. Adding security constraints in web.xml

<security-constraint>
    <web-resource-collection>
        <web-resource-name>NoAccess</web-resource-name>
        <url-pattern>/*</url-pattern>
          <http-method>DELETE</http-method>
          <http-method>TRACE</http-method>
          <http-method>OPTIONS</http-method>
    </web-resource-collection>
    <auth-constraint/>
</security-constraint>

Here DELETE, TRACE and OPTIONS are restricted for all urls. curl -kvv -X DELETE <url> will give 403 Forbidden

2. Using Rewrite rules in domain.xml 

<subsystem xmlns="urn:jboss:domain:web:1.1" default-virtual-server="default-host" native="false">
    <connector name="http" protocol="HTTP/1.1" scheme="http" socket-binding="http"/>
    <virtual-server name="default-host" enable-welcome-root="true">
        <rewrite pattern=".*" substitution="-" flags="F">
            <condition test="%{REQUEST_METHOD}" pattern="^(DELETE|TRACE|OPTIONS)$" flags="NC" />
    </rewrite>
    </virtual-server>
</subsystem>

3. Using mod_rewrite in httpd
    RewriteEngine On
    RewriteCond %{REQUEST_METHOD} ^(DELETE|TRACE|OPTIONS)$ [NC]
    RewriteRule .* - [F]
票数 2
EN

Stack Overflow用户

发布于 2016-12-08 17:16:51

我建议使用mod_rewrite。它更干净。

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

https://stackoverflow.com/questions/41035666

复制
相关文章

相似问题

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