Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSRF protection in web application

I have application that have CSRF protection provided by apache modules. My application containt a few pages that allow to upload some files, looks like this:

<form:form method="post" action="my.controller" enctype="multipart/form-data" id="form">

All stuff worked fine by the time we have updated our apache version from httpd-2.2.3 to httpd-2.2.15.

I've googled some time, and found that issue can be related to multipart/form-data parameter in the my form. In this case the form send as not secured. Also I've found that spring can handle stuff as above via MultipartFilter from spring doc http://docs.spring.io/spring-security/site/docs/3.2.0.CI-SNAPSHOT/reference/html/csrf.html#csrf-multipartfilter

I am new in CSRF stuff. Will be good to know whehter it is possible to use spring CSRF protection with apache configuration to handle such cases.

Also I've found workaround where I can disable CSRF for needed URLs, like

RewriteRule /url/mycontroller.controller - [E=CSRF_IGNORE:yes]

But I am not sure wherer it will be correct one.

like image 542
fashuser Avatar asked Jun 10 '14 08:06

fashuser


People also ask

How do you prevent CSRF attack in web API?

To prevent CSRF attacks, use anti-forgery tokens with any authentication protocol where the browser silently sends credentials after the user logs in. This includes cookie-based authentication protocols, such as forms authentication, as well as protocols such as Basic and Digest authentication.

What actions can be taken to protect a website from CSRF attacks?

Preventing CSRF attacks The most robust way to defend against CSRF attacks is to include a CSRF token within relevant requests. The token should be: Unpredictable with high entropy, as for session tokens in general. Tied to the user's session.

What does CSRF protection do?

CSRF tokens can prevent CSRF attacks by making it impossible for an attacker to construct a fully valid HTTP request suitable for feeding to a victim user.

Does WAF protect against CSRF?

By using custom rules through a WAF, users are able to help prevent certain CSRF attacks.


1 Answers

Following are the suggestions I have:

Please remove the enctype if not required since multipart/form-data is not supported in some of the CSRF libraries including CSRF Guard.

If you are setting the CSRF token using hidden attribute, please try appending the token in the action attribute. Here is this link : https://code.google.com/p/csrf-filter/

If you still face the same issue, you may have to exclude the URL from CSRF check.

like image 64
MadhusudhanSB Avatar answered Oct 02 '22 02:10

MadhusudhanSB