-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Enhanced basic auth decode #3239
Conversation
tests/test_helpers.py
Outdated
def test_basic_auth_decode(): | ||
auth = helpers.BasicAuth.decode('Basic bmtpbTpwd2Q=') | ||
@pytest.mark.parametrize('header', ( | ||
'Basic bmtpbTpwd2Q=', 'basic bmtpbTpwd2Q=')) |
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.
Nitpick: if placed one under the other, sequence items are better readable.
).decode(encoding).partition(':') | ||
decoded = base64.b64decode( | ||
encoded_credentials.encode('ascii'), validate=True | ||
).decode(encoding) |
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.
Not sure whether it's applicable to current PR, but JFYI some browsers (Firefox) don't encode some of UTF-8 bytes correctly, assuming ISO-8859-1
for unicode input and loosely encodes that input, which cuts some bytes in two-byte encoded chars (try entering €öäü
in browser and see what you receive in server), which results in error during encoding since it cannot understand byte sequence when reaches those characters. Ref cherrypy/cherrypy#1680
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 for the reminder.
We discussed it 2 or 3 years ago and decided to do nothing until users report.
There is no blame yet :)
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 @webknjaz. noted, but it seems to be out of scope of this PR though.
Codecov Report
@@ Coverage Diff @@
## master #3239 +/- ##
==========================================
- Coverage 98.09% 98.05% -0.04%
==========================================
Files 43 43
Lines 7856 7871 +15
Branches 1353 1354 +1
==========================================
+ Hits 7706 7718 +12
- Misses 58 60 +2
- Partials 92 93 +1
Continue to review full report at Codecov.
|
@@ -34,6 +34,8 @@ branch = True | |||
source = aiohttp, tests | |||
omit = site-packages | |||
|
|||
[mypy] | |||
incremental = false |
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.
Related mypy issue: python/mypy#5534
Thanks! |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a [new issue] for related bugs. |
What do these changes do?
These changes prevent passing illegal chars in the base64 payload.
It was possible to use
Authorization: Basic ???
to getBasicAuth(login='', password='')
without exceptions.Also, the related RFC https://www.ietf.org/rfc/rfc2617.txt allows the username and password to be blank, but the colon must be present.
and
Are there changes in behavior for the user?
Related issue number
Checklist
CONTRIBUTORS.txt
CHANGES
folder<issue_id>.<type>
for example (588.bugfix)issue_id
change it to the pr id after creating the pr.feature
: Signifying a new feature..bugfix
: Signifying a bug fix..doc
: Signifying a documentation improvement..removal
: Signifying a deprecation or removal of public API..misc
: A ticket has been closed, but it is not of interest to users.