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

Raise ValueError if BasicAuth login has a ":" #1307

Merged
merged 1 commit into from
Oct 13, 2016
Merged

Raise ValueError if BasicAuth login has a ":" #1307

merged 1 commit into from
Oct 13, 2016

Conversation

kawadia
Copy link
Contributor

@kawadia kawadia commented Oct 12, 2016

What do these changes do?

Improves BasicAuth by raising ValueError if BasicAuth login has a ":". A colon is not allowed in login/username per RFC 1945#section-11.1.

Are there changes in behavior for the user?

Yes. Current BasicAuth would silently fail to authenticate if login has a ":". This change would would instead raise a clear error to the user.

Related issue number

Checklist

  • [*] I think the code is well written
  • [*] Unit tests for the changes exist
  • Documentation reflects the changes
  • [*] Add yourself to CONTRIBUTORS.txt
  • [*] Add a new entry to CHANGES.rst
    • Choose any open position to avoid merge conflicts with other PRs.
    • Add a link to the issue you are fixing (if any) using #isuue_number format at the end of changelog message. Use Pull Request number if there are no issues for PR or PR covers the issue only partially.

@codecov-io
Copy link

Current coverage is 98.50% (diff: 100%)

Merging #1307 into master will increase coverage by <.01%

@@             master      #1307   diff @@
==========================================
  Files            29         29          
  Lines          6497       6499     +2   
  Methods           0          0          
  Messages          0          0          
  Branches       1090       1091     +1   
==========================================
+ Hits           6400       6402     +2   
  Misses           47         47          
  Partials         50         50          

Powered by Codecov. Last update 63a0d5c...b724adb

@asvetlov asvetlov merged commit 1d47bf7 into aio-libs:master Oct 13, 2016
@asvetlov
Copy link
Member

Thanks!

@kawadia kawadia deleted the no_colon_in_basicauth branch October 13, 2016 05:22
@@ -47,6 +47,10 @@ def __new__(cls, login, password='', encoding='latin1'):
if password is None:
raise ValueError('None is not allowed as password value')

if ':' in login:
raise ValueError(
'A ":" is not allowed in login (RFC 1945#section-11.1)')
Copy link
Member

Choose a reason for hiding this comment

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

Sorry so being late for the party, but this is not very correct RFC reference since:

  1. it about HTTP 1/0
  2. there it disallows non-latin usernames, while we don't.
    Here is a better one: https://tools.ietf.org/html/rfc2617#section-2

Copy link
Member

Choose a reason for hiding this comment

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

Mean while newly https://tools.ietf.org/html/rfc7617#page-3 allows any characters for user/pass except control ones. And the colon : is allowed, but needs to be escaped.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks.
I'l use yarl.quote for both parts separately.

Copy link
Member

Choose a reason for hiding this comment

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

Hmm, after re-reading RFC 7617 I've found:

The user-id and password MUST NOT contain any control characters (see
"CTL" in Appendix B.1 of [RFC5234]).

Furthermore, a user-id containing a colon character is invalid, as the first colon in a user-pass string separates user-id and password from one another; text after the first colon is part of the password.

User-ids containing colons cannot be encoded in user-pass strings.

Looks like the PR is correct

Copy link
Member

Choose a reason for hiding this comment

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

There is nothing about user-id encoding like percent-quoting etc.

Copy link
Member

Choose a reason for hiding this comment

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

That's strange, because without percent-quoting you're not able to use non-ascii names and passwords what is quite awkward today. And since you actually can have them, quoting colon character doesn't breaks the parser while it's quoted.

Copy link
Member

Choose a reason for hiding this comment

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

No, translation is base64encode(user+':'+password).
Base64 converts utf8 strings into ascii looselessly.
But colon in user is forbidden.

@asvetlov asvetlov mentioned this pull request Oct 14, 2016
@lock
Copy link

lock bot commented Oct 29, 2019

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.

If you feel like there's important points made in this discussion,
please include those exceprts into that new issue.

@lock lock bot added the outdated label Oct 29, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 29, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants