Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs - Improve CSRF section 18.5.4 Multipart (file upload) #4265

Open
andreiepure opened this issue Apr 5, 2017 · 4 comments
Open

Docs - Improve CSRF section 18.5.4 Multipart (file upload) #4265

andreiepure opened this issue Apr 5, 2017 · 4 comments
Labels
in: docs An issue in Documentation or samples status: ideal-for-contribution An issue that we actively are looking for someone to help us with type: enhancement A general enhancement

Comments

@andreiepure
Copy link

andreiepure commented Apr 5, 2017

Summary

The current docs say that there are two options to handle CSRF protection with multipart/form-data - not having security on multi-part file transfer or sending the CSRF token with the URL. The second is a security breach, as the docs mention.

Expected Behavior

A third option should be added: adding the CSRF token to the XHR POST request header sent to the server. This option works, I have tested it with Spring-Boot 1.5.2.RELEASE. I detailed the steps on SO.

Basically, it follows the guideline of sending the CSRF token via an AJAX request (and submitting the multi-part form using an AJAX request).

Version

Spring Security 4.2.2 - 18.5.4 Multipart (file upload)

@andreiepure andreiepure changed the title Docs - Improve 18.5.4 Multipart (file upload) Docs - Improve CSRF section 18.5.4 Multipart (file upload) Apr 5, 2017
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label May 7, 2019
@ryanblais
Copy link

Including the CSRF token in the request header works for me as well (even if the MultipartFilter is not defined before the Spring Security filter). I agree that a third option should be added (and might be the best default suggestion). If there's a reason to avoid this approach I've overlooked it seems even more imperative to document it!

The relevant section is now under 13.1.5 CSRF Caveats - Multipart (file upload)

Tested using Spring Security 5.1.6

@olimination
Copy link

olimination commented Mar 12, 2020

This third approach with adding the HTTP X-XSRF-TOKEN header to the request worked for me too. But I also needed to configure properly the CORS settings with Access-Control-Allow-Credentials=true and also on the client side the XHR object needed the withCredentials=true property set because I was using it in a single page app.

Tested using Spring Security 5.2.2

@rwinch
Copy link
Member

rwinch commented Mar 16, 2020

Anyone here willing to submit a PR?

@rwinch rwinch added in: docs An issue in Documentation or samples status: ideal-for-contribution An issue that we actively are looking for someone to help us with type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels Mar 16, 2020
@signalman
Copy link

I'd love to work on this. Would it be possible?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: docs An issue in Documentation or samples status: ideal-for-contribution An issue that we actively are looking for someone to help us with type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

6 participants