loopback icon indicating copy to clipboard operation
loopback copied to clipboard

Bearer tokens should not be decoded

Open ritch opened this issue 11 years ago • 9 comments

Currently bearer tokens are treated as base64 encoded strings. According to HTTP 1.1 and OAuth 2 they are not base64 but instead plain text with only base64 characters allowed.

Since access tokens already meet this requirement, the base64 encoding / decoding really has no real purpose AFAICT.

@rmg do you have any thoughts here?

ritch avatar Feb 20 '15 18:02 ritch

The code you linked to is for Basic auth only, the handler for Bearer is a few lines above.

This is done because Basic auth specifies base64, and if you give a token as your user/pass and let the browser/curl/library pass it as basic auth, it will base64 what you give it.

rmg avatar Feb 20 '15 18:02 rmg

@rmg I was looking at the wrong line... fixed the link.

ritch avatar Feb 20 '15 19:02 ritch

Ah, I see now. I don't recall modifying that line. Might have just been a whitespace change. I tried not to modify any behavior other than the Basic auth case.

rmg avatar Feb 20 '15 19:02 rmg

It's required by oAuth 2.0 Bearer token spec to be b64: https://tools.ietf.org/html/rfc6750#section-2.1

raymondfeng avatar Feb 20 '15 19:02 raymondfeng

By checking https://github.com/jaredhanson/passport-http-bearer/blob/master/lib/strategy.js#L89-L101, it seems that the token value is not b64 decoded. Maybe b64 is just a recommended format for bearer tokens.

raymondfeng avatar Feb 20 '15 20:02 raymondfeng

Maybe b64 is just a recommended format for bearer tokens.

Exactly. Should we remove the decoding then?

ritch avatar Feb 23 '15 19:02 ritch

+1 Having this same issue. Bearer Tokens are not supposed to be encoded/decoded.

wrensburg avatar May 07 '15 21:05 wrensburg

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Aug 23 '17 14:08 stale[bot]

This issue has been closed due to continued inactivity. Thank you for your understanding. If you believe this to be in error, please contact one of the code owners, listed in the CODEOWNERS file at the top-level of this repository.

stale[bot] avatar Sep 06 '17 14:09 stale[bot]