-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Fix #5226 by adding CSRF checking to api reqToken and add CSRF to the POST header for deadline #5250
Conversation
560514d
to
08dad8a
Compare
ping @cezar97 as well |
Codecov Report
@@ Coverage Diff @@
## master #5250 +/- ##
==========================================
- Coverage 37.64% 37.63% -0.01%
==========================================
Files 310 310
Lines 46042 46054 +12
==========================================
+ Hits 17331 17334 +3
- Misses 26235 26245 +10
+ Partials 2476 2475 -1
Continue to review full report at Codecov.
|
Thanks for the clarification. As it stands the CSRF token will only be checked if there is no BASIC Auth or token. I should actually check that definitely means that the user is logged in with a session, however I'd be surprised if csrf.Validate would pass if there was no session. |
Hmm ok looking again, I think there needs to be a check that the user is signed in before testing the CSRF, as it's possible to have a correct CSRF and session but not be logged in. Edit: I've just changed the PR to account for this. Now reqToken requires Basic, Apitoken or if not one of those requires the user to be signed in and a valid CSRF. |
@cezar97 :
Those GET urls aren't protected by reqToken so aren't affected by this change. There are a few GET urls which are protected by reqToken - however, I think these are pure API urls. (Edit: These all appear unused by the web UI. Apart from I do think it may be worth rationalising and refactoring the API req* functions though. I don't think reqToken is a very good name for what it is doing. Also, I suspect that routes protected by reqAdmin are CSRF exploitable... (Edit: they are - I've updated my PR to include reqToken protection on these.) |
Hmm would it be helpful to go through the API urls systematically looking at where there might still be CSRF issues? |
For clarity, @cezar97, the reqAdmin routes weren't being protected by reqToken and should have been. So I added that as a second commit. |
No, things like the repo search can expose private repos. Also these ones are dependent on a user session. |
Looks great! 🎉 @kolaente would you be able to review again? |
@cezar97 OK, I guess it doesn't make much of a difference if these are protected by CSRF or not. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Thanks for PR @zeripath. Now that this is merged, are you able to backport the commit to |
#4840 prevents CSRF attacks by preventing POSTs to API addresses without being logged in by Token or with BASIC auth. It did not add capability for providing a CSRF token.
This PR adds CSRF token checking in to the reqToken function within routers/api/v1/api.go and then adjusts the way deadlines are POSTed to pass in the CSRF token in as a header.
Fixes #5226, #5249
@beeonthego as far as I understand this would still prevent the CSRF attacks. Is this correct?
Edit: make clear #4840 was preventing CSRF attacks not XSS