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

Authorization header use not conforming to HTTP standards #4630

Closed
vkrizan opened this issue Sep 7, 2023 · 6 comments
Closed

Authorization header use not conforming to HTTP standards #4630

vkrizan opened this issue Sep 7, 2023 · 6 comments
Assignees
Labels

Comments

@vkrizan
Copy link

vkrizan commented Sep 7, 2023

Describe the bug

Authorization header use with API tokens is out of HTTP standards of RFC 9110. The header lacks auth-scheme.

Steps to reproduce the bug

No response

Expected behavior

auth-scheme used in Authoriztion header. For API keys this could be Bearer.

Logs, error output, etc.

No response

Screenshots

No response

Additional context

Unleash version

5.4.2

Subscription type

Open source

Hosting type

Self-hosted

SDK information (language and version)

No response

@vkrizan vkrizan added the bug label Sep 7, 2023
@nunogois
Copy link
Member

nunogois commented Sep 8, 2023

Hi @vkrizan, thank you for raising this issue. I'll share this with the rest and then we'll get back to you.

@sighphyre
Copy link
Member

Hey @vkrizan, our auth protocol looks a lot like RFC 9110 but it isn't, it's a custom protocol we use. This isn't something that's likely to change in the near future since it's pretty deeply baked in at the moment. Is this actually causing problems for you?

@vkrizan
Copy link
Author

vkrizan commented Sep 8, 2023

Thank you for your response.

There are no problems considering the non-standard Authorization header used at the moment. I've raised it, as my assumption about the use of API keys (with the use of "Bearer") against Unleash were incorrect. Documentation about the use is only to be found in the Unleash API spec and on some examples.

I'm a bit concerned that not using the standard can lead to problems when implementing custom authentication methods, or at least create a tech-debt. Our folks have re-implemented a part of the toggle APIs with the Bearer support, with a fallback to using the header value as is: https://github.com/app-sre/unleash/blob/1a232f991ff224b634fd75b9da375b83e65d438f/index.js#L183.

I'd maybe suggest to start migrate to the standard, and have the fallback to header value to not break existing clients.
If you think that this is not such a big concern, feel free to close.

@sighphyre
Copy link
Member

Hey @vkrizan, gotta be honest, I was kind of hoping you'd point out a bunch of places that this caused huge problems. It's always felt a little weird to me that we do this but I've never had any real argument to change it and it always felt like a big, fragile change to everything that needs to auth to Unleash.

The code you've linked is actually a pretty neat idea, that would make this safe, I think.

Don't want to close this, I'll bring it up with the team and let's see if we can head in this direction (no promises, it's entirely possible one of the other engineers has an excellent reason for this being in place and I've just never heard it)

nunogois added a commit that referenced this issue Apr 2, 2024
Adds a bearer token middleware that adds support for tokens prefixed
with "Bearer" scheme. Prefixing with "Bearer" is optional and the old
way of authenticating still works, so we now support both ways.

Also, added as part of our OpenAPI spec which now displays authorization
as follows:

![image](https://github.com/Unleash/unleash/assets/455064/77b17342-2315-4c08-bf34-4655e12a1cc3)

Related to #4630. Doesn't fully close the issue as we're still using
some invalid characters for the RFC, in particular `*` and `[]`

For safety reasons this is behind a feature flag

---------

Co-authored-by: Gastón Fournier <gaston@getunleash.io>
@sighphyre
Copy link
Member

Hey @vkrizan, just to try and (partially) close this loop. Some of my rather clever colleagues took a stab at this. We've added support for using the header correctly in the linked pull request. There are some limitations in what we can support in the spec, we have a few non standard characters in our token scheme that make this more challenging than we'd like.

Pretty sure that the patch you folks are using will work just fine, but if you'd like to give this a spin so you don't have to maintain that, we've released this behind a flag. You should be able to use this by setting the UNLEASH_EXPERIMENTAL_BEARER_TOKEN_MIDDLEWARE envronment variable to true.

Thanks again for reporting this and nudging us to fix it!

@vkrizan
Copy link
Author

vkrizan commented Apr 11, 2024

Thank you @sighphyre

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done
Development

No branches or pull requests

4 participants