Repository navigation
fix(auth): check OAuth state before trading the code - #499
Merged
Merged
Conversation
- Verify the state JWT and CSRF cookie before the code reaches the provider. - Answer 400 when the provider refuses the code, including GitHub's 200 with an error body, and 502 when the provider cannot be reached. - Fuzz the OAuth callbacks with Schemathesis: a fuzzed state never verifies, so no request reaches GitHub or Google. Signed-off-by: Simon van Lierde <simonvanlierde@gmail.com>
Signed-off-by: Simon van Lierde <simonvanlierde@gmail.com>
docker-py gives up on an API call after 60 s. When the Docker daemon is busy, creating a container with a published port took about 90 s, so the integration tests failed before any test ran. Signed-off-by: Simon van Lierde <simonvanlierde@gmail.com>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The OAuth callbacks answered 500 to a made-up
code, because httpx-oauth trades the code with the provider before the app checksstate. This checksstatefirst and answers 400 when the provider refuses the code.Type of change
Why
base.pynow verifies the state JWT and CSRF cookie before the code goes to GitHub or Google. A 4xx from the provider gives 400, and no answer or a 5xx gives 502. GitHub's 200 with anerrorbody also gives 400.exclude(path_regex=...)and its TODO. A fuzzedstatenever verifies, so the fuzz never reaches the providers.Checklist
just ci)just test)Security, if relevant
stateno longer reaches the provider.stateor a refused code gives 400, a provider outage gives 502, never 500.tests/unit/auth/test_oauth_callback.py, plus the Schemathesis fuzz on the callbacks.Notes for reviewers
Tests: the 67 OAuth unit tests pass, and
pytest tests/integration -k schemathesispasses (2 tests, 140 subtests). With the oldbase.py, 7 unit tests and 11 fuzz cases fail with the 500. I didn't run the fulljust ci. The fuzz test doesn't block the network itself, so nothing stops a future change that lets a fuzzedstatereach the providers.