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

Handles ValueErrors with invalid hex values in query strings (#954) #963

Merged
merged 9 commits into from
Oct 19, 2021
Merged

Handles ValueErrors with invalid hex values in query strings (#954) #963

merged 9 commits into from
Oct 19, 2021

Conversation

duck-nukem
Copy link
Contributor

Fixes #954

Description of the Change

Invalid hex values result in HTTP 500 errors, the purpose of this PR is to convert them to HTTP 400 ones.

Checklist

  • PR only contains one change (considered splitting up PR)
  • unit-test added
  • documentation updated
  • CHANGELOG.md updated (only for user relevant changes)
  • author name in AUTHORS

Comment on lines 20 to 21
except ValueError as error:
raise SuspiciousOperation(error)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As raised in #954 (comment) is catching all ValueErrors too broad? I think it should be fine, but it might end up exposing error messages users were never meant to see, possibly resulting in security flaws?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm also a bit worried about this catching "real issues" and causing them to end up not being logged (for example in one Django setup I know SuspiciousOperation won't get logged into Sentry but a raw ValueError would). So I could imagine some time lost as this absorbs a real error.

The minimalist approach here would be to check if error.message == "invalid hex string" (or whatever) and only transform the error then (otherwise just reraising the ValueError). But to be honest this might not be a major thing.

Copy link
Contributor Author

@duck-nukem duck-nukem Apr 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated it now to check the message of the error, otherwise re-raises the exception as-is.

@auvipy auvipy requested a review from n2ygk April 16, 2021 09:26
Copy link
Contributor

@auvipy auvipy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you please fix the conflict in changelog

@codecov
Copy link

codecov bot commented Sep 27, 2021

Codecov Report

Merging #963 (e5cca4e) into master (6085a2d) will increase coverage by 0.02%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #963      +/-   ##
==========================================
+ Coverage   96.56%   96.58%   +0.02%     
==========================================
  Files          31       31              
  Lines        1718     1729      +11     
==========================================
+ Hits         1659     1670      +11     
  Misses         59       59              
Impacted Files Coverage Δ
oauth2_provider/backends.py 100.00% <100.00%> (ø)
oauth2_provider/views/mixins.py 99.24% <100.00%> (+0.02%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6085a2d...e5cca4e. Read the comment docs.

@auvipy
Copy link
Contributor

auvipy commented Sep 27, 2021

can you plz fix he flake8 errors in py3.8?

@duck-nukem
Copy link
Contributor Author

I made some updates @auvipy , but I’m flying a bit blind, as flake8 didn’t report these issues locally. I read the errors from the CI run, and did my best to fix them.

@auvipy
Copy link
Contributor

auvipy commented Oct 19, 2021

ok wait for the CI

@auvipy auvipy merged commit d35f030 into jazzband:master Oct 19, 2021
@auvipy
Copy link
Contributor

auvipy commented Oct 19, 2021

thanks a lot everyone involved

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.

ValueError from oauthlib when validating querystrings is raised as 500 instead of 400 HTTP error
3 participants