0

For security reasons i want to disable some http methods(e.x. OPTIONS,TRACE,HEAD) through application level. I want to do this for all files in directory "bundles/"

But this path is actually created by this

bundles.Add(new Bundle("~/bundles/Something").Include("~/Contents/Scripts/file.js"));
bundles.Add(new Bundle("~/bundles/Anything").Include("~/Areas/Import/Scripts/App/anotherfile.js"));

Fow now I tried this (in Web.config)

<system.web>
  <httpHandlers>
    <add path="bundles/" verb="OPTIONS,TRACE,HEAD" type="System.Web.HttpMethodNotAllowedHandler" />
  </httpHandlers>
</system.web>

but it doesn't work

So, I want user gets 405 Method Not Allowed when making OPTIONS, TRACE, HEAD requests for any link like myapp.com/bundles/example

Thank you

2 Answers2

2

I'd do this like that:

<system.web>
    <authorization>
        <deny verbs="OPTIONS" users="*" />
        <deny verbs="TRACE" users="*" />
        <deny verbs="HEAD" users="*" />
    </authorization>

...

    <httpHandlers>
        <add path="bundles" verb="OPTIONS" type="System.Web.DefaultHttpHandler" validate="true"/>
        <add path="bundles" verb="TRACE" type="System.Web.DefaultHttpHandler" validate="true"/>
        <add path="bundles" verb="HEAD" type="System.Web.DefaultHttpHandler" validate="true"/>
    </httpHandlers>
</system.web>
Lesmian
  • 3,932
  • 1
  • 17
  • 28
1

Try this

<add path="bundles" verb="OPTIONS" type="System.Web.DefaultHttpHandler" validate="true"/>
<add path="bundles" verb="TRACE" type="System.Web.DefaultHttpHandler" validate="true"/>
<add path="bundles" verb="HEAD" type="System.Web.DefaultHttpHandler" validate="true"/>
Ajay Gupta
  • 1,775
  • 1
  • 10
  • 22