Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting 403 error when using CSRF filter with tomcat 6.0.32

This is my filer config in web.xml

<filter>
    <filter-name>CSRFPreventionFilter</filter-name>
    <filter-class>org.apache.catalina.filters.CsrfPreventionFilter</filter-class>
    <init-param>
        <param-name>entryPoints</param-name>
        <param-value>/login<param-value>
    </init-param>
</filter>

<filter-mapping>
    <filter-name>CSRFPreventionFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>
<filter>

Am I missing something? Are any code-changes necessary to enable csrf protection in tomcat

like image 309
sps Avatar asked Oct 31 '12 05:10

sps


1 Answers

Note that a 403 is the CSRFPreventionFilter response if a nonce is not provided and the filter expects one.

I don't know the current state of CSRFPreventionFilter, but according to this thread you need to specify each entryPoint resource individually (no wildcards) - or have the filter apply to a path that does not include /login

So:

<filter>
<filter-name>CSRFPreventionFilter</filter-name>
<filter-class>org.apache.catalina.filters.CsrfPreventionFilter</filter-class>
<init-param>
    <param-name>entryPoints</param-name>
    <param-value>/login/login.html,/login/image.png,/login/style.css</param-value>
</init-param>
</filter>

Or:

<filter-mapping>
<filter-name>CSRFPreventionFilter</filter-name>
<url-pattern>/csrf/*</url-pattern>
</filter-mapping>

Update Dec 2012:

Tomcat 7.0.32 fixes a security vulnerability in CSRFPreventionFilter

like image 83
pd40 Avatar answered Nov 14 '22 10:11

pd40