Spring CSRF is not working for me for multipart forms with file upload. It works fine for other requests. My web.xml looks like this -
<filter>
<filter-name>MultipartFilter</filter-name>
<filter-class>org.springframework.web.multipart.support.MultipartFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>MultipartFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
...
some more filters
...
<filter>
<filter-name>csrfFilter</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy
</filter-class>
</filter>
<filter-mapping>
<filter-name>csrfFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
I have defined this bean in my appcontext-servlet.xml -
<bean id="filterMultipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="maxUploadSize" value="100000000" />
</bean>
I also have csrfFilter defined. With the filterMultipartResolver bean defined, I get redirected to our default 404 page. Without the bean, I get an error page saying I sent a null token. When I see the request in chrome developer tools, it contains the following parts along with the rest of the form (the token has got attached twice because I am using javascript to do so once on page load and probably once while sending. What am I missing?
------WebKitFormBoundaryHMYSQ8eg6FXpxqDA Content-Disposition: form-data; name="_csrf"
16a983e0-a115-43d9-aa72-09c9576d53df ------WebKitFormBoundaryHMYSQ8eg6FXpxqDA Content-Disposition: form-data; name="_csrf"
16a983e0-a115-43d9-aa72-09c9576d53df