9 ms·
OAuth 2.0 Security Best Current Practice
- dijital 7y agoWorth bearing in mind: > This Internet-Draft is submitted in full conformance with the provisions of BCP 78 and BCP 79. > ... > It is inappropriate to use Internet-Drafts as reference material or to cite them other than as "work in progress."
- DCKing 7y agoAs a case in point: https://tools.ietf.org/html/draft-wkumari-not-a-draft-05 https://tools.ietf.org/html/draft-wkumari-not-a-draft-05 I think publishing an IETF RFC on security best practices is hard, but I hope these authors manage to pull through
- deng 7y agoTo this day I have no idea how one should handle client secrets in (F)OSS applications, and I'm often wondering if I'm the only one. I guess what this text says in 4.13 is "just don't put it somewhere for anyone to see", which means that the only solution is to make the id and secret configurable and let the user register the application with its OAuth provider, which of course most users wouldn't know how to do. As a result, applications like Thunderbird simply put the secret in the code with a comment above it "please don't copy these values for your own application". I really don't mean to shame Mozilla, what else are they supposed to do?
- nicolaslem 7y agoFrom my understanding the best practice for applications that run on clients' machines (Javascript SPA, mobile app, email client) is to not use a client secret at all. Just use a client id and assume that anyone can reuse it. Of course that is if the OAuth provider allows it.
- deng 7y ago> Of course that is if the OAuth provider allows it. That's the catch. Last time I checked, at least Google didn't. So how can you write a (F)OSS email application for accessing GMail via OAuth2, without putting the secrets into the code (which Google also forbids)?
- tptacek 7y agoGoogle Mail's OAuth2 instructions discuss this point explicitly.
- diafygi 7y agoHave a link?
- psanford 7y ago"The process results in a client ID and, in some cases, a client secret, which you embed in the source code of your application. (In this context, the client secret is obviously not treated as a secret.)"[0] [0]: https://developers.google.com/identity/protocols/oauth2 https://developers.google.com/identity/protocols/oauth2
- dwaite 7y agoThe conversation I had with a Google engineer implied the appropriate course of action was to embed the secret. https://github.com/openid/AppAuth-JS/issues/46 https://github.com/openid/AppAuth-JS/issues/46
- deng 7y agoThe Google engineer should read Google's terms of service which explicitly states that you may not do that (see my reply above).
- niftich 7y agoIn this situation, their guidance says to embed the secret, because in this context it's obviously not a secret. Here's the current page [1]; here's the earliest Archive.org snapshot of its one-earlier predecessor page from 2015 [2] -- the advice has been consistent. [1] https://developers.google.com/identity/protocols/oauth2/native-app https://developers.google.com/identity/protocols/oauth2/nati... [2] https://web.archive.org/web/20150520223809/https://developers.google.com/identity/protocols/OAuth2InstalledApp https://web.archive.org/web/20150520223809/https://developer...
- tptacek 7y agoIf it's a FOSS clientside application, like a mobile or desktop app, it's a public application and the client secret doesn't really apply. If it's a serverside application, a web app, then every instance of the app will be registered independently with auth servers, and will manage their own client secrets.
- njkleiner 7y agoIsn't that what PKCE is for?
- BiteCode_dev 7y agoUsually you put a service that hold the key, and the client application ask the service to do the request for it. If the user doesn't want to use your service, they configure their own key.
- diafygi 7y agoDo you have any examples of this?
- segphault 7y agoIt's not just an open source problem. It's fairly trivial to scrape the keys out of a lot of closed source applications. When Twitter first mandated OAuth, I was able to grep a key right out of the apk of their native Android client. OAuth with client secrets is fundamentally unsuitable for desktop and mobile applications, but that hasn't stopped virtually every major implementor from using it that way. The people who wrote the spec were too busy congratulating each other and downplaying concerns to seriously engage with this issue until it was much too late to do anything about it. It remains a deeply broken standard, and the people who were responsible for it at an early stage are entirely to blame. Several of them have removed their names from the spec, but I'll not forget the role they played in shouting down critics who raised concerns about this very issue.
- niftich 7y agoMuch of the deployment of OAuth2 was a shitshow, because early on, there was a huge debate about OAuth1 vs OAuth2, and the concepts and terminology used in the OAuth2 spec exceeded the mental load of people who were simply looking for a quickstart to some API. Docs by various providers either adopted the OAuth2 terminology wholesale without sufficiently explaining the new concepts and the best practices, or they simplified the client registration to just a few fields and offered no guidance as to make use of them in your app. The spec has been clear from the start that there are clients that can protect their secrets, and ones that can't [1]. Here's a choice quote: "A native application is a public client installed and executed on the device used by the resource owner. Protocol data and credentials are accessible to the resource owner. It is assumed that any client authentication credentials included in the application can be extracted." Unfortunately, much of the rest of the spec is a bit like a playing puzzle, where reading it in one sitting doesn't actually build your understanding, and you have to constantly cross-reference various sections to construct a complete picture of the process the spec is trying to set. It look a long time for people's familiarity with the spec to grow, and for providers and clients to improve in quality and adherence to the ideas and text of the spec. [1] https://tools.ietf.org/html/rfc6749#section-2.1 https://tools.ietf.org/html/rfc6749#section-2.1
- jzer0cool 7y agoYou would not embed the client secret to any application unless you are open for public to see and use the secret (most likely not for applications you distribute to public domain).
- guessmyname 7y agoI implemented more than a dozen OAuth integrations last year with multiple American and Chinese companies and oh boy it was painful. I do not know why so many engineers end up reading a clear specification document like RFC-6749 [1] and then ignore 80% of the instructions. I had to deal with so many weird bugs and bad OAuth server implementations, I lost count of how many emails went back and forth trying to make sense of unexpected behavior. Even Apple engineers got it wrong. They decided to create their own thing based on OpenID Connect for “Sign In With Apple” [2]. OpenID had to write an open letter [3] explaining the repercussions of their changes and fortunately were able to convince Apple to fix the implementation [4]. OpenID was lucky though, they had some leverage, but a no-one like me couldn’t possibly convince a gigantic conglomerate like Tencent to fix their web API. Talking with Tencent engineers has been one of the worst experiences in my career. The company apparently has a culture of constant job rotations, engineers are assigned projects for short periods of time with bonuses for early completion which encourage them to deploy half-finished code before moving to something else. [1] https://tools.ietf.org/html/rfc6749 https://tools.ietf.org/html/rfc6749 [2] https://developer.apple.com/sign-in-with-apple/ https://developer.apple.com/sign-in-with-apple/ [3] https://openid.net/2019/06/27/open-letter-from-the-openid-foundation-to-apple-regarding-sign-in-with-apple/ https://openid.net/2019/06/27/open-letter-from-the-openid-fo... [4] https://openid.net/2019/09/30/apple-successfully-implements-openid-connect-with-sign-in-with-apple/ https://openid.net/2019/09/30/apple-successfully-implements-...
- deleted 7y ago[deleted]
- mooreds 7y agoWere you implementing a client in all of these OAuth integrations? I thought the point of OAuth was to make it easy to build clients and push the complexity to the authorization servers :) ?
- guessmyname 7y agoI have implemented OAuth servers and also OAuth clients because our integrations go both ways: some parts of our systems rely on 3rd-party services and other companies rely on us as well. The take away from my comment is that even if the software specification is clear (I gave RFC 6749 as an example) some engineers will disregard the instructions and make something completely unexpected. The majority of developers expect good quality software from big companies with massive engineering teams, but people who have the opportunity —or should I say misfortune?— to work with them realize software engineering quality is often an illusion.
- tptacek 7y agoIt's not structurally all that great; it opens with a long section of recommendations backed by citations to later "attack model" sections in the text, which themselves include disjoint lists of recommendations.
- dwaite 7y agoIt is probably worth pointing out on this thread that there is a brand new draft (not yet on the working group) attempting to combine extensions and the best practices of OAuth (including these security practices) into a new "2.1" version. https://tools.ietf.org/html/draft-parecki-oauth-v2-1-02 https://tools.ietf.org/html/draft-parecki-oauth-v2-1-02
- anderspitman 7y ago> Clients MUST NOT pass access tokens in a URI query parameter I've been wondering about this lately. This makes sense from a security perspective, but the primary alternative is setting a header like Authorization: Bearer, which makes your request subject to browser cross-origin restrictions, and all the fun that comes with CORS. In my case, the extra round-trip required for the CORS preflight in this situation is simply a non-starter for my application. It would be nice if there was an escape hatch for developers who understand the risks. More background in this SO question I asked a couple days ago: https://stackoverflow.com/q/61563348/943814 https://stackoverflow.com/q/61563348/943814
- malinens 7y agoput it in a cookie (secure samesite) or in request body
- deleted 7y ago[deleted]
- anderspitman 7y agoCan you give more details on how you'd use a cookie here? SameSite=Strict/Lax can't be used cross domain, and none is no good for mutating requests due to CSRF. Request body works, but it forces you to split your API if you want to be cache friendly. What I mean is ideally you want public data to be GETable and thus cacheable. In the system I'm building, any given path can change back and forth from being public vs requiring authorization, so if I use requests bodies (ie POSTs), I would need to detect whether the data is public or not before making the request and choose between GET or POST at request time. That might not actually be that bad; I'll have to think about it more.
- patwillson22 7y agoThe road to hell is paved with best practices.
- znpy 7y agoSince we're talking oauth/openid: does anybody know if there's a way to get the OpenID spec in a format that is nicely formatted for printing? (ideally, just like rfc 6749...)
- deleted 7y ago[deleted]
- abhishektwr 7y agoI need to read this draft RFC a few times before I can grasp it completely. There is an existing RFC drafted in 2013 with a focus on OAuth 2.0 threat model and security considerations [1], and it looks like this new RFC is making more specific recommendations on top of it. May be read them together. To be honest, I was wishing for OAuth 2.5 if not OAuth 3.0 to consolidate already fragmented OAuth 2.0 spec and landscape [2]. At this stage, there are too many draft proposals and a majority of them led by vendors with some interest in standardizing their implementations. For example, this RFC suggests restricting issued access token to one resource at a time (using audience parameter). Well with Microservices landscape this gets really challenging. Your client application may be interacting with multiple resources. Neither OpenID Connect nor OAuth 2.0 offer solutions to issue multiple access tokens (not yet). An API Gateway may be a solution but still so much ambiguity. I think OpenID Community has done a better job to organize their specifications and working groups [3]. If you go on their specification page it tabulates really well what spec is final, currently under implementation, draft, or obsolete. Still, big vendors influence agenda and direction. (Disclaimer: I am the founder of https://axioms.io/ https://axioms.io/ which OAuth 2/OpenID Connect compliant identity management platform) [1]: https://tools.ietf.org/html/rfc6819 https://tools.ietf.org/html/rfc6819 [2]: RFC 6749, RFC 6750, RFC 6819, RFC 7662, RFC 7009, RFC 7519, RFC 8414, RFC 7591, RFC 7592, and 20 more. [3]: https://openid.net/developers/specs/ https://openid.net/developers/specs/
- niftich 7y agoAs posted by someone downthread [1], there's an ongoing effort to update the OAuth 2.0 spec with changes since, lessons learned, and best practices [2], in what's currently being called OAuth 2.1. Some more rationale and resources on oauth.net [3]. [1] https://news.ycombinator.com/item?id=23083245 https://news.ycombinator.com/item?id=23083245 [2] https://tools.ietf.org/html/draft-parecki-oauth-v2-1-02 https://tools.ietf.org/html/draft-parecki-oauth-v2-1-02 [3] https://oauth.net/2.1/ https://oauth.net/2.1/
- abhishektwr 7y agoThanks for the pointer. I am not sure if OAuth 2.1 is part of working group yet. Nonetheless, a good consolidated read compared to reading 20 different RFC specs.
- drivebycomment 7y agoThis is all good and useful, but I wish OAuth folks would fix the bugs in the spec like, e.g. "The authorization server MAY issue a new refresh token, in which case the client MUST discard the old refresh token and replace it with the new refresh token. The authorization server MAY revoke the old refresh token after issuing a new refresh token to the client." This sounds reasonable on the surface, and technically it might be correct (depending on your interpretation of the words). But if someone naively follows this instruction to implement the server - issue a new refresh token and revoke the old one in the same refresh request at the server, what happens is when the client doesn't receive the new refresh token due to any transient failure, the client effectively loses its authorization, since the old refresh token is revoked and they didn't get the new one. Thus the protocol becomes "leaky" - you lose users because of transient errors. i.e. "after issuing a new refresh token to the client" needs to be "after the new refresh token is being used at least once", or otherwise invent some other way to ensure the new refresh token is correctly received at the client before revoking the old.
- codebje 7y ago"… or otherwise invent some other way to ensure the new refresh token is correctly received at the client before revoking the old." These sorts of details will typically wind up in an implementation report document. It's rare that an IETF protocol specification document will attempt to pre-determine the solution to all such implementation details up front, and IMO, not good when they do. In some contexts, it may be much better to require the application to re-obtain resource owner authorisation than to allow a replay of a refresh token. In others, it may be much better to avoid requiring resource owner authorisation. What you see as a bug, others would see as a critical feature.
- jzer0cool 7y agoCould not find what you have quoted in article. What are you referencing?
- jzer0cool 7y agoThere are many parts to the spec for the full picture. This here specifies that server MAY issue a new refresh token (clarifying whether it is required), and if new refresh token is issued, the client MUST discard the old. I believe the intention here is not to verify whether it was used once as you state. And transient matters (how the client will detect if not received would be a different scope), for example, if client didn't receive (or lost), then likely here you may need restart auth cycle.
- kerkeslager 7y agoIf there was one perfect way to do third-party auth, we wouldn't need a standard, because all the big companies would be doing it, and the smaller companies would do it. The problem is, there's a bunch of decisions with auth, which have to be made, but aren't really important. What should the name of the auth token header be? What should be the format of the responses? These decisions are like deciding what side of the road to drive on: it doesn't matter which side of the road you drive on, as long as everyone drives on the same side of the road. The function of a standard is to decide what side of the road everyone drives on. OAuth isn't a standard. It's just a description of all the various homegrown third-party auth systems that anyone has implemented over HTTP, with only the absolute worst patterns weeded out. None of the shareholders wanted to re-implement their third-party auth, so they just made sure their flavor of auth made it into the standard. It's like if the Europeans and the Americans got together to standardize the side of the road that everyone drives on, and the standard they came up with is "You have two options for which side of the road to drive on, the right or the left." Until a group of visionaries with enough clout to make the world fall in line creates an actual standard, OAuth is going to continue to be crap. And there's strong disincentive to do that: if you agree to conform to a standard that isn't exactly what you've already implemented, then that means you have to reimplement. A few years' pain conforming everyone to a standard would significantly drive humanity forward--an incomprehensible amount of developer hours have been spent writing custom OAuth integrations, and an actual standard would allow us to write libraries around it that everyone could use. But corporations don't care about pushing humanity forward when it's contrary to their bottom line.
- sytringy05 7y agoI've been working with OAuth 2 for 7 years and I still don't really understand all the dark corners of the spec. Good to see Resource Owner grant type get called out for a "Do not use", although I dont think using it in a private, server side context is off the cards...
- jzer0cool 7y agoIs it weird I like reading such specs? Many people find it dense, but I find it rewarding to read. What CS job would be more tuned to spending time doing this leisure?
- ta17711771 7y agoSysadmin/devops
- georgianar 7y agoThis great herbal doctor cured me from herpes virus and he brought my ex lover back via Whatsapp Robinson buckler +12533361750