question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

As detailed here and here, the default implementation of OAuth2 is vulnerable to CSRF attacks whereby a malicious host can compromise the developer’s site by grabbing a valid code from his own Facebook/Google/etc. account and tricking the victim into GETting it. This would enable the malicious user to use his own Facebook/Google/etc. account to login to the developer’s site as the victim.

The solution is to send a known value in the state parameter and assert that it comes back as expected.

It seems to me like this is something we should fix at the library level. Here’s one potential solution, but I’m interested in hearing others.

  1. When initializing an OAuth2Service, the developer passes in a CSRF_SECRET_KEY (or None to disable rauth’s CSRF protection).
  2. When the developer calls get_authorize_url, he passes in the current user’s ID (or None if the user is anonymous).
  3. If rauth receives an ID, it salts it with CSRF_SECRET_KEY, hashes it, and concatenates it onto the state param:
&state=__csrf__%3D95078fdf5cde38c1ca1694389cda1460;original_state_here
  1. Just before get_access_token returns, it salts and hashes the current user’s ID, and compares the results to __csrf__. 4a) If the hashes match, the __csrf__ string is removed from the state and it is passed unmolested back to the developer. 4b) If the hashes don’t match, return {'error': 'csrf_validation_failed'} to the developer.

I’m new to both the rauth project and OAuth2 implementation in general. I’d love to know if I’m off-base here. If not, I’d be happy to add support.

Please critique.

Issue Analytics

  • State:open
  • Created 11 years ago
  • Reactions:1
  • Comments:13 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
melutovichcommented, Jan 1, 2019

What became of this?

0reactions
marceloFAcommented, Aug 13, 2020

Repo owner, can I work on a fix for this?

Read more comments on GitHub >

github_iconTop Results From Across the Web

What is CSRF (Cross-site request forgery)? Tutorial & Examples
CSRF token is simply duplicated in a cookie ... In this situation, the attacker can again perform a CSRF attack if the web...
Read more >
Cross-Site Request Forgery Prevention Cheat Sheet
CSRF tokens prevent CSRF because without a token, an attacker cannot create valid requests to the backend server. For the Synchronised Token Pattern,...
Read more >
Cross-site request forgery - Wikipedia
Cross-site request forgery, also known as one-click attack or session riding and abbreviated as CSRF (sometimes pronounced sea-surf) or XSRF, ...
Read more >
CSRF Protection - The PHP Framework For Web Artisans
Cross-site request forgeries are a type of malicious exploit whereby unauthorized commands are performed on behalf of an authenticated user. Thankfully, Laravel ...
Read more >
Protecting Your Users Against CSRF - Hacksplaining
Protecting against CSRF (commonly pronounced “sea-surf”) requires two things: ensuring that GET requests are side-effect free, and ensuring that non-GET ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found