Skip to content

Handle basic credentials with colon character in the password. #78

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

rudism
Copy link

@rudism rudism commented Dec 4, 2018

Per RFC 2617 Section 2: Basic Authentication Scheme, after decoding the basic authentication base64 credentials value, the userid is comprised of everything up to but not including the first : character, and the password is everything after that first : character. It seems that a strict reading would imply that passwords could themselves contain : characters as they would be part of the text that follows the first : character.

      user-pass   = userid ":" password
      userid      = *<TEXT excluding ":">
      password    = *TEXT

This patch (which closes issue #20) changes the behavior of the basic authentication strategy to more closely adhere to the RFC quoted above.

Previously it was splitting the base64 decoded string on the : character and using the 0th element as the username, the 1st element as the password, and dropping everything else, including part of the password if it contained another : character. After this patch it will only split the decoded value on the first : character and include everything afterwards in the password even if it contains additional : characters.

I have added a new test to verify that passwords with : characters now authenticate correctly. I have not added any new documentation as this is a pretty minor code change to fix a small problem and does not significantly add to or alter any existing functionality.

Checklist

  • I have read the CONTRIBUTING guidelines.
  • I have added test cases which verify the correct operation of this feature or patch.
  • I have added documentation pertaining to this feature or patch.
  • The automated test suite ($ make test) executes successfully.
  • The automated code linting ($ make lint) executes successfully.

@rudism
Copy link
Author

rudism commented Dec 4, 2018

I'll note that there are older PRs #67 and #69 to address this same issue, but this patch doesn't involve re-assembling the split password or adding new failure conditions, I think it's the least impactful way to address it.

MatthiasKunnen added a commit to MatthiasKunnen/passport-http-2 that referenced this pull request Dec 20, 2018
Previous implementation:
empty user-pass  -> error basic realm
no " " separator -> error 400
no : separator   -> error basic realm
empty password   -> error basic realm
empty username   -> error basic realm

New implementation:
empty user-pass  -> error 400
no " " separator -> error 400
no : separator   -> error 400
empty password   -> success
empty username   -> success

Also fixed passwords containing ':' being truncated.

This fixes:
- jaredhanson/passport-http#20
- jaredhanson/passport-http#41
- jaredhanson/passport-http#42
- jaredhanson/passport-http#63
- jaredhanson/passport-http#78

The new implemementation complies with
https://tools.ietf.org/html/rfc2617#section-2.
MatthiasKunnen added a commit to MatthiasKunnen/passport-http-2 that referenced this pull request Dec 20, 2018
Previous implementation:
empty user-pass  -> error basic realm
no " " separator -> error 400
no : separator   -> error basic realm
empty password   -> error basic realm
empty username   -> error basic realm

New implementation:
empty user-pass  -> error 400
no " " separator -> error 400
no : separator   -> error 400
empty password   -> success
empty username   -> success

Also fixed passwords containing ':' being truncated.

This fixes:
- jaredhanson/passport-http#20
- jaredhanson/passport-http#41
- jaredhanson/passport-http#42
- jaredhanson/passport-http#63
- jaredhanson/passport-http#78

The new implemementation complies with
https://tools.ietf.org/html/rfc2617#section-2.
@neemah
Copy link

neemah commented Feb 4, 2019

Is this ever get merged?

@bodo22
Copy link

bodo22 commented Nov 7, 2019

@jaredhanson ist there anything I can help with to get this MR merged and released to npm?

@MatthiasKunnen
Copy link

@bodo22, I've created a fork in which I fixed some behavior including this issue. See: https://www.npmjs.com/package/passport-http-2.

@bodo22
Copy link

bodo22 commented Nov 7, 2019

Thanks! I've created a fork myself already :). As this project has 50k npm downloads a week it would be really nice to see the changes be applied here.

@la-bibe
Copy link

la-bibe commented May 3, 2020

Can we know when will this be merged please ?

@gkTim
Copy link

gkTim commented Jun 19, 2020

Please merge this fix!

AaronDewes pushed a commit to AaronDewes/modern-passport-http that referenced this pull request Feb 6, 2021
This is mostly the following change:

Corrected handling of HTTP Basic edge cases

Previous implementation:
empty user-pass  -> error basic realm
no " " separator -> error 400
no : separator   -> error basic realm
empty password   -> error basic realm
empty username   -> error basic realm

New implementation:
empty user-pass  -> error 400
no " " separator -> error 400
no : separator   -> error 400
empty password   -> success
empty username   -> success

Also fixed passwords containing ':' being truncated.

This fixes:
- jaredhanson#20
- jaredhanson#41
- jaredhanson#42
- jaredhanson#63
- jaredhanson#78

The new implemementation complies with
https://tools.ietf.org/html/rfc2617#section-2.
@kvanrobbroeck
Copy link

Would be awesome to see this merged too, we're going to get a fork for this as well, but thanks to @rudism for having done the work already!

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.

7 participants