Skip to content

CSRF/XSS protection #374

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

Merged
merged 2 commits into from
Jun 26, 2017
Merged

CSRF/XSS protection #374

merged 2 commits into from
Jun 26, 2017

Conversation

andrewn
Copy link
Member

@andrewn andrewn commented Jun 26, 2017

It's difficult to work out what protections a Single Page Application communicating via an API requires. A lot of the documentation out there expects the server to generate an HTML form that can be submitted without JS.

However, these documents are good:

I'm not an expert though.

The Editor API only accepts incoming requests with a Content-Type of application/json. Other requests are rejected. Requests which have no Content-Type (like GET requests) are always allowed. This protects against HTML-only forms submitted by the browser which will have a application/x-www-form-urlencoded MIME type.

We implemented a whitelist of allowed domains to *.p5js.org in #324 so this should protect against some XSS attacks.

A CSRF token is sent as the cookie 'XSRF-TOKEN' on all HTML page requests. This token is picked up automatically by axios and sent to the API with all requests as an 'X-XSRF-TOKEN' header. The middleware runs on all routes and verifies that the token matches what's stored in the session.

I've clicked around the site and tested everything I can think of and things seem to work as intended. Changing some of the client API actions to send Content-Type: text/plain fails as expected. Altering the CSRF token in the console and then trying to sign in also fails with a CSRF error.

andrewn added 2 commits June 26, 2017 16:37
The CSRF token is sent as the cookie 'XSRF-TOKEN' on all HTML page
requests. This token is  picked up automatically by axios
and sent to the API with all requests as an 'X-XSRF-TOKEN' header.
The middleware runs on all routes and verifies that the token matches
what's stored in the session.
@catarak
Copy link
Member

catarak commented Jun 26, 2017

this looks great, thanks for doing the research on this!!

@catarak catarak merged commit 6cbc376 into processing:master Jun 26, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants