I'm trying to disable JBOSS HTTP OPTIONS method. Using the following syntax in the web.xml in JBoss, I can disable all the http-method except OPTIONS. Is there a way to successfully disable http-method OPTIONS?
<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>
Using the response of Ravikant Sharma (thanks)
Find the
server.xml
(in my case /jboss-5.1.0.GA/server/default/deploy/jbossweb.sar)Inside tags < Engine > and < Host > you could see a < valve > tag, you should insert a new valve tag like this:
< Valve className="org.jboss.web.rewrite.RewriteValve" />
Then in config folder in my case
/jboss-5.1.0.GA/server/default/conf/
. See if you have the following paths and file (if you don't, you need create it) -/jboss.web/localhost/rewrite.properties
Inside the above file add the below lines:
RewriteCond %{REQUEST_METHOD} ^(OPTIONS)$ [NC] RewriteRule .* - [F]
So before the configuration you see the below result:
curl -i -X OPTIONS http://192.168.133.1:8080
After configuration, you will see the below output:
curl -i -X OPTIONS http://192.168.133.1:8080
I'd suggest using mod_rewrite. It is cleaner.
Option 1 - Using RewriteValve (can apply globally)
You can use RewriteValve to disable the http methods. Take a look at documentation. You will need one RewriteCond directive and one RewriteRule.
In your RewriteCond directive you could specify all methods with use of the REQUEST_METHOD server variable, for example:
then your RewriteRule can mark those as forbidden (it immediately sends back a HTTP response of 403 (FORBIDDEN)), for example:
In case of Jboss EAP 6
Apart from this as said in above answer it can be done via web.xml per war wise.
To check above use