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

data-method whitelist to block adding CSRF #403

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

bwillis
Copy link

@bwillis bwillis commented Feb 16, 2015

If an attacker has the ability to create link tags and attributes they have the ability to intercept the CSRF token, even if CSP is enabled. By setting the href to another site and adding data-method='post' the CSRF token will automatically be added to the request and sent to an attackers site. It is important to note that this is only applicable to handleMethod (data-method) call as when done through handleRemote (data-remote) the CSP will block the request to the attackers domain.

This fix adds a configurable whitelist of hrefs to verify the link against before adding the CSRF token. The default is to allow everything to avoid break existing clients.

If an attacker has the ability to create link tags and attributes they
have the ability to intercept the CSRF token, even if CSP is enabled.
By setting the href to another site and adding `data-method='post'` the
CSRF token will automatically be added to the request and sent to an
attackers site. It is important to note that this is only applicable to
`handleMethod` (`data-method`) call as when done through `handleRemote`
(`data-remote`) the CSP will block the request to the attackers domain.

This fix adds a configurable whitelist of hrefs to verify the link
against before adding the CSRF token. The default is to allow
everything to avoid break existing clients.
@RSO
Copy link

RSO commented Feb 16, 2015

Should we be checking for the raw href here, or might there be a way to check for the domain of the href?

@bwillis
Copy link
Author

bwillis commented Feb 16, 2015

@RSO that's a good point, maybe we can make it user friendly whitelisting domains instead of hrefs, I'll try this out and update the diff.

It can be difficult to setup a whitelist of hrefs.

This change adds in hostname matching so it should be friendlier to
configure.
@RSO
Copy link

RSO commented Feb 16, 2015

👍

A potential attacker that can set the href or data-method attributes
can also use attack strings to cause any html to be created which could
allow bypassing of the whitelist.
@bwillis
Copy link
Author

bwillis commented Feb 18, 2015

We got external feedback from a security researcher, the way action, name and value attributes are being set can also be used for unsafe injection. I'll be updating the PR accordingly.

@JangoSteve
Copy link
Member

@bwillis Just to clarify (and unless I'm misunderstanding), this potential exploit only works if the application developer is allowing their users to submit raw HTML links with arbitrary attributes and passing it directly through to other users without doing any sort of escaping or sanitization, right? As in, you'd have to be calling html_safe on the arbitrary user input in order for their data-method attribute to actually make it through to other users (or have some sort of custom sanitization that allows the attribute to pass through unescaped).

@RSO
Copy link

RSO commented Feb 18, 2015

@JangoSteve You're right. The reason we spend time on actually fixing this was because of a recent XSS that was discovered in our markdown parsing (https://hackerone.com/reports/46072). Without the fix in this pull request every XSS in our markdown parser would be turned into a full-blown CSRF (through CSP bypass).

Do you have any hesitations that makes you doubt landing this fix?

@JangoSteve
Copy link
Member

@RSO Not at all. Just wanted to make sure I had a good understanding of the issue and sense of the severity.

@RSO
Copy link

RSO commented Feb 18, 2015

Cool!

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.

3 participants