Internet-Draft | oauth-security-topics | April 2020 |
Lodderstedt, et al. | Expires 7 October 2020 | [Page] |
This document describes best current security practice for OAuth 2.0.It updates and extends the OAuth 2.0 Security Threat Model toincorporate practical experiences gathered since OAuth 2.0 waspublished and covers new threats relevant due to the broaderapplication of OAuth 2.0.¶
This Internet-Draft is submitted in full conformance with the provisions of BCP 78 and BCP 79.¶
Internet-Drafts are working documents of the Internet Engineering Task Force (IETF). Note that other groups may also distribute working documents as Internet-Drafts. The list of current Internet-Drafts is athttps://datatracker.ietf.org/drafts/current/.¶
Internet-Drafts are draft documents valid for a maximum of six months and may be updated, replaced, or obsoleted by other documents at any time. It is inappropriate to use Internet-Drafts as reference material or to cite them other than as "work in progress."¶
This Internet-Draft will expire on 7 October 2020.¶
Copyright (c) 2020 IETF Trust and the persons identified as the document authors. All rights reserved.¶
This document is subject to BCP 78 and the IETF Trust's Legal Provisions Relating to IETF Documents (https://trustee.ietf.org/license-info) in effect on the date of publication of this document. Please review these documents carefully, as they describe your rights and restrictions with respect to this document. Code Components extracted from this document must include Simplified BSD License text as described in Section 4.e of the Trust Legal Provisions and are provided without warranty as described in the Simplified BSD License.¶
Since its publication in[RFC6749] and[RFC6750], OAuth 2.0("OAuth" in the following) has gotten massive traction in the marketand became the standard for API protection and the basis for federatedlogin using OpenID Connect[OpenID]. While OAuth is used in avariety of scenarios and different kinds of deployments, the followingchallenges can be observed:¶
OAuth implementations are being attacked through knownimplementation weaknesses and anti-patterns. Although most ofthese threats are discussed in the OAuth 2.0 Threat Model andSecurity Considerations[RFC6819], continued exploitationdemonstrates a need for more specific recommendations, easier toimplement mitigations, and more defense in depth.¶
OAuth is being used in environments with higher securityrequirements than considered initially, such as Open Banking,eHealth, eGovernment, and Electronic Signatures. Those use casescall for stricter guidelines and additional protection.¶
OAuth is being used in much more dynamic setups than originallyanticipated, creating new challenges with respect to security.Those challenges go beyond the original scope of[RFC6749],[RFC6750], and[RFC6819].¶
OAuth initially assumed a static relationship between client,authorization server and resource servers. The URLs of AS and RS wereknown to the client at deployment time and built an anchor for thetrust relationship among those parties. The validation whether theclient talks to a legitimate server was based on TLS serverauthentication (see[RFC6819], Section 4.5.4). With the increasingadoption of OAuth, this simple model dissolved and, in severalscenarios, was replaced by a dynamic establishment of the relationshipbetween clients on one side and the authorization and resource serversof a particular deployment on the other side. This way, the sameclient could be used to access services of different providers (incase of standard APIs, such as e-mail or OpenID Connect) or serve as afrontend to a particular tenant in a multi-tenancy environment.Extensions of OAuth, such as the OAuth 2.0 Dynamic Client RegistrationProtocol[RFC7591] and OAuth 2.0 Authorization Server Metadata[RFC8414] were developed in order to support the usage of OAuth indynamic scenarios.¶
Technology has changed. For example, the way browsers treatfragments when redirecting requests has changed, and with it, theimplicit grant's underlying security model.¶
This document provides updated security recommendations to addressthese challenges. It does not supplant the security advice given in[RFC6749],[RFC6750], and[RFC6819], but complements thosedocuments.¶
The remainder of this document is organized as follows: The nextsection summarizes the most important recommendations of the OAuthworking group for every OAuth implementor. Afterwards, the updated theOAuth attacker model is presented. Subsequently, a detailed analysisof the threats and implementation issues that can be found in the wildtoday is given along with a discussion of potential countermeasures.¶
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALLNOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED","MAY", and "OPTIONAL" in this document are to be interpreted asdescribed in BCP 14[RFC2119][RFC8174] when, and only when, theyappear in all capitals, as shown here.¶
This specification uses the terms "access token", "authorizationendpoint", "authorization grant", "authorization server", "client","client identifier" (client ID), "protected resource", "refreshtoken", "resource owner", "resource server", and "token endpoint"defined by OAuth 2.0[RFC6749].¶
This section describes the set of security mechanisms the OAuthworking group recommends to OAuth implementers.¶
When comparing client redirect URIs against pre-registered URIs,authorization servers MUST utilize exact string matching. This measurecontributes to the prevention of leakage of authorization codes andaccess tokens (seeSection 4.1). It can also help todetect mix-up attacks (seeSection 4.4).¶
Clients MUST NOT expose URLs that forward the user's browser toarbitrary URIs obtained from a query parameter ("open redirector").Open redirectors can enable exfiltration of authorization codes andaccess tokens, seeSection 4.9.1.¶
Clients MUST prevent Cross-Site Request Forgery (CSRF). In thiscontext, CSRF refers to requests to the redirection endpoint that donot originate at the authorization server, but a malicious third party(see Section 4.4.1.8. of[RFC6819] for details). Clients that haveensured that the authorization server supports PKCE[RFC7636] MAYrely the CSRF protection provided by PKCE. In OpenID Connect flows,thenonce
parameter provides CSRF protection. Otherwise, one-timeuse CSRF tokens carried in thestate
parameter that are securelybound to the user agent MUST be used for CSRF protection (seeSection 4.7.1).¶
In order to prevent mix-up attacks (seeSection 4.4), clients MUST only process redirectresponses of the authorization server they sent the respective requestto and from the same user agent this authorization request wasinitiated with. Clients MUST store the authorization server they sentan authorization request to and bind this information to the useragent and check that the authorization request was received from thecorrect authorization server. Clients MUST ensure that the subsequenttoken request, if applicable, is sent to the same authorizationserver. Clients SHOULD use distinct redirect URIs for eachauthorization server as a means to identify the authorization server aparticular response came from.¶
An AS that redirects a request potentially containing user credentialsMUST avoid forwarding these user credentials accidentally (seeSection 4.10 for details).¶
Clients MUST prevent injection (replay) of authorization codes intothe authorization response by attackers. The use of PKCE[RFC7636]is RECOMMENDED to this end. The OpenID Connectnonce
parameter andID Token Claim[OpenID] MAY be used as well. The PKCE challenge orOpenID Connectnonce
MUST be transaction-specific and securely boundto the client and the user agent in which the transaction was started.¶
Note: although PKCE so far was designed as a mechanism to protectnative apps, this advice applies to all kinds of OAuth clients,including web applications.¶
When using PKCE, clients SHOULD use PKCE code challenge methods thatdo not expose the PKCE verifier in the authorization request.Otherwise, attackers that can read the authorization request (cf.Attacker A4 inSection 3) can break the security providedby PKCE. Currently,S256
is the only such method.¶
Authorization servers MUST support PKCE[RFC7636].¶
Authorization servers MUST provide a way to detect their support forPKCE. To this end, they MUST either (a) publish the elementcode_challenge_methods_supported
in their AS metadata ([RFC8414])containing the supported PKCE challenge methods (which can be used bythe client to detect PKCE support) or (b) provide adeployment-specific way to ensure or determine PKCE support by the AS.¶
The implicit grant (response type "token") and other response typescausing the authorization server to issue access tokens in theauthorization response are vulnerable to access token leakage andaccess token replay as described inSection 4.1,Section 4.2,Section 4.3, andSection 4.6.¶
Moreover, no viable mechanism exists to cryptographically bind accesstokens issued in the authorization response to a certain client as itis recommended inSection 2.2. This makes replaydetection for such access tokens at resource servers impossible.¶
In order to avoid these issues, clients SHOULD NOT use the implicitgrant (response type "token") or other response types issuingaccess tokens in the authorization response, unless access token injectionin the authorization response is prevented and the aforementioned token leakagevectors are mitigated.¶
Clients SHOULD instead use the response type "code" (aka authorizationcode grant type) as specified inSection 2.1.1 or any other response type thatcauses the authorization server to issue access tokens in the tokenresponse, such as the "code id_token" response type. This allows theauthorization server to detect replay attempts by attackers andgenerally reduces the attack surface since access tokens are notexposed in URLs. It also allows the authorization server tosender-constrain the issued tokens (see next section).¶
A sender-constrained access token scopes the applicability of an accesstoken to a certain sender. This sender is obliged to demonstrate knowledgeof a certain secret as prerequisite for the acceptance of that token atthe recipient (e.g., a resource server).¶
Authorization and resource servers SHOULD use mechanisms forsender-constrained access tokens to prevent token replay as describedinSection 4.8.1.1.2. The use of Mutual TLS for OAuth 2.0[RFC8705] is RECOMMENDED. Refresh tokens MUST besender-constrained or use refresh token rotation as described inSection 4.12.¶
It is RECOMMENDED to use end-to-end TLS. If TLStraffic needs to be terminated at an intermediary, refer toSection 4.11 for further security advice.¶
The privileges associated with an access token SHOULD be restricted tothe minimum required for the particular application or use case. Thisprevents clients from exceeding the privileges authorized by theresource owner. It also prevents users from exceeding their privilegesauthorized by the respective security policy. Privilege restrictionsalso help to reduce the impact of access token leakage.¶
In particular, access tokens SHOULD be restricted to certain resourceservers (audience restriction), preferably to a single resourceserver. To put this into effect, the authorization server associatesthe access token with certain resource servers and every resourceserver is obliged to verify, for every request, whether the accesstoken sent with that request was meant to be used for that particularresource server. If not, the resource server MUST refuse to serve therespective request. Clients and authorization servers MAY utilize theparametersscope
orresource
as specified in[RFC6749] and[I-D.ietf-oauth-resource-indicators], respectively, to determine theresource server they want to access.¶
Additionally, access tokens SHOULD be restricted to certain resourcesand actions on resource servers or resources. To put this into effect,the authorization server associates the access token with therespective resource and actions and every resource server is obligedto verify, for every request, whether the access token sent with thatrequest was meant to be used for that particular action on theparticular resource. If not, the resource server must refuse to servethe respective request. Clients and authorization servers MAY utilizethe parameterscope
as specified in[RFC6749] andauthorization_details
as specified in[I-D.ietf-oauth-rar] to determine thoseresources and/or actions.¶
The resource owner password credentials grant MUST NOT be used. Thisgrant type insecurely exposes the credentials of the resource owner tothe client. Even if the client is benign, this results in an increasedattack surface (credentials can leak in more places than just the AS)and users are trained to enter their credentials in places other thanthe AS.¶
Furthermore, adapting the resource owner password credentials grant totwo-factor authentication, authentication with cryptographiccredentials (cf. WebCrypto[webcrypto], WebAuthn[webauthn]), andauthentication processes that require multiple steps can be hard orimpossible.¶
Authorization servers SHOULD use client authentication if possible.¶
It is RECOMMENDED to use asymmetric (public-key based) methods forclient authentication such as mTLS[RFC8705] orprivate_key_jwt
[OpenID]. When asymmetric methods for clientauthentication are used, authorization servers do not need to storesensitive symmetric keys, making these methods more robust against anumber of attacks.¶
Authorization servers SHOULD NOT allow clients to influence theirclient_id
orsub
value or any other claim if that can causeconfusion with a genuine resource owner (seeSection 4.13).¶
In[RFC6819], an attacker model is laid out that describes thecapabilities of attackers against which OAuth deployments must beprotected. In the following, this attacker model is updated to accountfor the potentially dynamic relationships involving multiple parties(as described inSection 1), to include new types of attackers and to definethe attacker model more clearly.¶
OAuth MUST ensure that the authorization of the resource owner (RO)(with a user agent) at the authorization server (AS) and the subsequentusage of the access token at the resource server (RS) is protected atleast against the following attackers:¶
(A1) Web Attackers that can set up and operate an arbitrary numberof network endpoints including browsers and servers (except forthe concrete RO, AS, and RS). Web attackers may set up web sitesthat are visited by the RO, operate their own user agents, andparticipate in the protocol.¶
Web attackers may, in particular, operate OAuth clients that areregistered at AS, and operate their own authorization and resourceservers that can be used (in parallel) by the RO and otherresource owners.¶
It must also be assumed that web attackers can lure the user toopen arbitrary attacker-chosen URIs at any time. In practice, thiscan be achieved in many ways, for example, by injecting maliciousadvertisements into advertisement networks, or by sendinglegit-looking emails.¶
Web attackers can use their own user credentials to create newmessages as well as any secrets they learned previously. Forexample, if a web attacker learns an authorization code of a userthrough a misconfigured redirect URI, the web attacker can thentry to redeem that code for an access token.¶
They cannot, however, read or manipulate messages that are nottargeted towards them (e.g., sent to a URL controlled by anon-attacker controlled AS).¶
(A2) Network Attackers that additionally have full control overthe network over which protocol participants communicate. They caneavesdrop on, manipulate, and spoof messages, except when theseare properly protected by cryptographic methods (e.g., TLS).Network attackers can also block arbitrary messages.¶
While an example for a web attacker would be a customer of an internetservice provider, network attackers could be the internet serviceprovider itself, an attacker in a public (wifi) network using ARPspoofing, or a state-sponsored attacker with access to internetexchange points, for instance.¶
These attackers conform to the attacker model that was used in formalanalysis efforts for OAuth[arXiv.1601.01229]. This is a minimalattacker model. Implementers MUST take into account all possibleattackers in the environment in which their OAuth implementations areexpected to run. Previous attacks on OAuth have shown that OAuthdeployments SHOULD in particular consider the following, strongerattackers in addition to those listed above:¶
(A3) Attackers that can read, but not modify, the contents of theauthorization response (i.e., the authorization response can leakto an attacker).¶
Examples for such attacks include open redirectorattacks, problems existing on mobile operating systems (wheredifferent apps can register themselves on the same URI), mix-up attacks (seeSection 4.4), where the client is tricked into sendingcredentials to a attacker-controlled AS, and the fact that URLsare often stored/logged by browsers (history), proxy servers, andoperating systems.¶
(A4) Attackers that can read, but not modify, the contents of theauthorization request (i.e., the authorization request can leak,in the same manner as above, to an attacker).¶
(A5) Attackers that can acquire an access token issued by AS. Forexample, a resource server can be compromised by an attacker, anaccess token may be sent to an attacker-controlled resource serverdue to a misconfiguration, or an RO is social-engineered intousing a attacker-controlled RS. See alsoSection 4.8.2.¶
(A3), (A4) and (A5) typically occur together with either (A1) or (A2).¶
Note that in this attacker model, an attacker (see A1) can be a RO oract as one. For example, an attacker can use his own browser to replaytokens or authorization codes obtained by any of the attacks describedabove at the client or RS.¶
This document focusses on threats resulting from these attackers.Attacks in an even stronger attacker model are discussed, for example,in[arXiv.1901.11520].¶
This section gives a detailed description of attacks on OAuthimplementations, along with potential countermeasures. Attacks andmitigations already covered in[RFC6819] are not listed here, exceptwhere new recommendations are made.¶
Some authorization servers allow clients to register redirect URIpatterns instead of complete redirect URIs. The authorization serversthen match the redirect URI parameter value at the authorizationendpoint against the registered patterns at runtime. This approachallows clients to encode transaction state into additional redirectURI parameters or to register a single pattern for multipleredirect URIs.¶
This approach turned out to be more complex to implement and moreerror prone to manage than exact redirect URI matching. Severalsuccessful attacks exploiting flaws in the pattern matchingimplementation or concrete configurations have been observed in thewild . Insufficient validation of the redirect URI effectively breaksclient identification or authentication (depending on grant and clienttype) and allows the attacker to obtain an authorization code oraccess token, either¶
by directly sending the user agent to a URI under the attackerscontrol, or¶
by exposing the OAuth credentials to an attacker by utilizing anopen redirector at the client in conjunction with the way useragents handle URL fragments.¶
These attacks are shown in detail in the following subsections.¶
For a client using the grant type code, an attack may work asfollows:¶
Assume the redirect URL patternhttps://*.somesite.example/*
isregistered for the client with the client IDs6BhdRkqt3
. Theintention is to allow any subdomain ofsomesite.example
to be avalid redirect URI for the client, for examplehttps://app1.somesite.example/redirect
. A naive implementation onthe authorization server, however, might interpret the wildcard*
as"any character" and not "any character valid for a domain name". Theauthorization server, therefore, might permithttps://attacker.example/.somesite.example
as a redirect URI,althoughattacker.example
is a different domain potentiallycontrolled by a malicious party.¶
The attack can then be conducted as follows:¶
First, the attacker needs to trick the user into opening a tamperedURL in his browser that launches a page under the attacker'scontrol, sayhttps://www.evil.example
(see Attacker A1.)¶
This URL initiates the following authorization request with the clientID of a legitimate client to the authorization endpoint (line breaksfor display only):¶
GET /authorize?response_type=code&client_id=s6BhdRkqt3&state=9ad67f13 &redirect_uri=https%3A%2F%2Fattacker.example%2F.somesite.example HTTP/1.1Host: server.somesite.example¶
The authorization server validates the redirect URI and compares it tothe registered redirect URL patterns for the clients6BhdRkqt3
.The authorization request is processed and presented to the user.¶
If the user does not see the redirect URI or does not recognize theattack, the code is issued and immediately sent to the attacker'sdomain. If an automatic approval of the authorization is enabled(which is not recommended for public clients according to[RFC6749]), the attack can be performed even without userinteraction.¶
If the attacker impersonated a public client, the attacker canexchange the code for tokens at the respective token endpoint.¶
This attack will not work as easily for confidential clients, sincethe code exchange requires authentication with the legitimate client'ssecret. The attacker can, however, use the legitimate confidentialclient to redeem the code by performing an authorization codeinjection attack, seeSection 4.5.¶
Note: Vulnerabilities of this kind can also exist if the authorizationserver handles wildcards properly. For example, assume that the clientregisters the redirect URL patternhttps://*.somesite.example/*
andthe authorization server interprets this as "allow redirect URIspointing to any host residing in the domainsomesite.example
". If anattacker manages to establish a host or subdomain insomesite.example
, he can impersonate the legitimate client. Thiscould be caused, for example, by a subdomain takeover attack[subdomaintakeover], where anoutdated CNAME record (say,external-service.somesite.example
)points to an external DNS name that does no longer exist (say,customer-abc.service.example
) and can be taken over by an attacker(e.g., by registering ascustomer-abc
with the external service).¶
The attack described above works for the implicit grant as well. Ifthe attacker is able to send the authorization response to a URI underhis control, he will directly get access to the fragment carrying theaccess token.¶
Additionally, implicit clients can be subject to a further kind ofattack. It utilizes the fact that user agents re-attach fragments tothe destination URL of a redirect if the location header does notcontain a fragment (see[RFC7231], Section 9.5). The attackdescribed here combines this behavior with the client as an openredirector (seeSection 4.9.1) in order to get access to access tokens. This allowscircumvention even of very narrow redirect URI patterns, but not strict URLmatching.¶
Assume the registered URL pattern for clients6BhdRkqt3
ishttps://client.somesite.example/cb?*
, i.e., any parameter is allowedfor redirects tohttps://client.somesite.example/cb
. Unfortunately,the client exposes an open redirector. This endpoint supports aparameterredirect_to
which takes a target URL and will send thebrowser to this URL using an HTTP Location header redirect 303.¶
The attack can now be conducted as follows:¶
First, and as above, the attacker needs to trick the user into openinga tampered URL in his browser that launches a page under theattacker's control, sayhttps://www.evil.example
.¶
Afterwards, the website initiates an authorization request that isvery similar to the one in the attack on the code flow. Different toabove, it utilizes the open redirector by encodingredirect_to=https://attacker.example
into the parameters of theredirect URI and it uses the response type "token" (line breaks for display only):¶
GET /authorize?response_type=token&state=9ad67f13 &client_id=s6BhdRkqt3 &redirect_uri=https%3A%2F%2Fclient.somesite.example %2Fcb%26redirect_to%253Dhttps%253A%252F %252Fattacker.example%252F HTTP/1.1Host: server.somesite.example¶
Now, since the redirect URI matches the registered pattern, theauthorization server permits the request and sends the resulting accesstoken in a 303 redirect (some response parameters omitted forreadability):¶
HTTP/1.1 303 See OtherLocation: https://client.somesite.example/cb? redirect_to%3Dhttps%3A%2F%2Fattacker.example%2Fcb #access_token=2YotnFZFEjr1zCsicMWpAA&...¶
At example.com, the request arrives at the open redirector. The endpoint willread the redirect parameter and will issue an HTTP 303 Location headerredirect to the URLhttps://attacker.example/
.¶
HTTP/1.1 303 See OtherLocation: https://attacker.example/¶
Since the redirector at client.somesite.example does not include afragment in the Location header, the user agent will re-attach theoriginal fragment#access_token=2YotnFZFEjr1zCsicMWpAA&...
tothe URL and will navigate to the following URL:¶
https://attacker.example/#access_token=2YotnFZFEjr1z...¶
The attacker's page atattacker.example
can now access thefragment and obtain the access token.¶
The complexity of implementing and managing pattern matching correctlyobviously causes security issues. This document therefore advises tosimplify the required logic and configuration by using exact redirectURI matching only. This means the authorization server MUST comparethe two URIs using simple string comparison as defined in[RFC3986],Section 6.2.1.¶
Additional recommendations:¶
Servers on which callbacks are hosted MUST NOT expose openredirectors (seeSection 4.9).¶
Browsers reattach URL fragments to Location redirection URLs onlyif the URL in the Location header does not already contain a fragment.Therefore, servers MAY prevent browsers from reattaching fragmentsto redirection URLs by attaching an arbitrary fragment identifier,for example#_
, to URLs in Location headers.¶
Clients SHOULD use the authorization code response type instead ofresponse types causing access token issuance at the authorizationendpoint. This offers countermeasures against reuse of leakedcredentials through the exchange process with the authorizationserver and token replay through sender-constraining of the accesstokens.¶
If the origin and integrity of the authorization request containingthe redirect URI can be verified, for example when using[I-D.ietf-oauth-jwsreq] or[I-D.ietf-oauth-par] with clientauthentication, the authorization server MAY trust the redirect URIwithout further checks.¶
The contents of the authorization request URI or the authorizationresponse URI can unintentionally be disclosed to attackers through theReferer HTTP header (see[RFC7231], Section 5.5.2), by leaking eitherfrom the AS's or the client's web site, respectively. Mostimportantly, authorization codes orstate
values can be disclosed inthis way. Although specified otherwise in[RFC7231], Section 5.5.2,the same may happen to access tokens conveyed in URI fragments due tobrowser implementation issues as illustrated by Chromium Issue 168213[bug.chromium].¶
Leakage from the OAuth client requires that the client, as a result ofa successful authorization request, renders a page that¶
contains links to other pages under the attacker's control and auser clicks on such a link, or¶
includes third-party content (advertisements in iframes, images,etc.), for example if the page contains user-generated content(blog).¶
As soon as the browser navigates to the attacker's page or loads thethird-party content, the attacker receives the authorization responseURL and can extractcode
orstate
(and potentiallyaccess token
).¶
In a similar way, an attacker can learnstate
from the authorizationrequest if the authorization endpoint at the authorization servercontains links or third-party content as above.¶
An attacker that learns a valid code or access token through aReferer header can perform the attacks as described inSection 4.1.1,Section 4.5, andSection 4.6. If the attacker learnsstate
, the CSRFprotection achieved by usingstate
is lost, resulting in CSRFattacks as described in[RFC6819], Section 4.4.1.8.¶
The page rendered as a result of the OAuth authorization response andthe authorization endpoint SHOULD NOT include third-party resources orlinks to external sites.¶
The following measures further reduce the chances of a successful attack:¶
Suppress the Referer header by applying an appropriate ReferrerPolicy[webappsec-referrer-policy] to the document (either aspart of the "referrer" meta attribute or by setting aReferrer-Policy header). For example, the headerReferrer-Policy:no-referrer
in the response completely suppresses the Refererheader in all requests originating from the resulting document.¶
Use authorization code instead of response types causing accesstoken issuance from the authorization endpoint.¶
Bind authorization code to a confidential client or PKCEchallenge. In this case, the attacker lacks the secret to requestthe code exchange.¶
As described in[RFC6749], Section 4.1.2, authorization codesMUST be invalidated by the AS after their first use at the tokenendpoint. For example, if an AS invalidated the code after thelegitimate client redeemed it, the attacker would fail exchangingthis code later.¶
This does not mitigate the attack if the attacker manages toexchange the code for a token before the legitimate client doesso. Therefore,[RFC6749] further recommends that, when anattempt is made to redeem a code twice, the AS SHOULD revoke alltokens issued previously based on that code.¶
Thestate
value SHOULD be invalidated by the client after itsfirst use at the redirection endpoint. If this is implemented, andan attacker receives a token through the Referer header from theclient's web site, thestate
was already used, invalidated bythe client and cannot be used again by the attacker. (This doesnot help if thestate
leaks from theAS's web site, since then thestate
has not been used at the redirection endpoint at the client yet.)¶
Use the form post response mode instead of a redirect for theauthorization response (see[oauth-v2-form-post-response-mode]).¶
Authorization codes and access tokens can end up in the browser'shistory of visited URLs, enabling the attacks described in thefollowing.¶
When a browser navigates toclient.example/redirection_endpoint?code=abcd
as a result of aredirect from a provider's authorization endpoint, the URL includingthe authorization code may end up in the browser's history. Anattacker with access to the device could obtain the code and try toreplay it.¶
Countermeasures:¶
Authorization code replay prevention as described in[RFC6819],Section 4.4.1.1, andSection 4.5.¶
Use form post response mode instead of redirect for the authorizationresponse (see[oauth-v2-form-post-response-mode]).¶
An access token may end up in the browser history if a client or a website that already has a token deliberately navigates to a page likeprovider.com/get_user_profile?access_token=abcdef
.[RFC6750]discourages this practice and advises to transfer tokens via a header,but in practice web sites often pass access tokens in queryparameters.¶
In case of the implicit grant, a URL likeclient.example/redirection_endpoint#access_token=abcdef
may also endup in the browser history as a result of a redirect from a provider'sauthorization endpoint.¶
Countermeasures:¶
Clients MUST NOT pass access tokens in a URI query parameter inthe way described in Section 2.3 of[RFC6750]. The authorizationcode grant or alternative OAuth response modes like the form postresponse mode[oauth-v2-form-post-response-mode] can be used tothis end.¶
Mix-up is an attack on scenarios where an OAuth client interacts withtwo or more authorization servers and at least one authorizationserver is under the control of the attacker. This can be the case,for example, if the attacker uses dynamic registration to register theclient at his own authorization server or if an authorization serverbecomes compromised.¶
The goal of the attack is to obtain an authorization code or an accesstoken for an uncompromised authorization server. This is achieved bytricking the client into sending those credentials to the compromisedauthorization server (the attacker) instead of using them at therespective endpoint of the uncompromised authorization/resourceserver.¶
The description here closely follows[arXiv.1601.01229], withvariants of the attack outlined below.¶
Preconditions: For this variant of the attack to work, we assume that¶
the implicit or authorization code grant are used with multiple ASof which one is considered "honest" (H-AS) and one is operated bythe attacker (A-AS),¶
the client stores the AS chosen by the user in a session bound tothe user's browser and uses the same redirection endpoint URI foreach AS, and¶
the attacker can intercept and manipulate the firstrequest/response pair from a user's browser to the client (inwhich the user selects a certain AS and is then redirected by theclient to that AS), as in Attacker A2.¶
The latter ability can, for example, be the result of aman-in-the-middle attack on the user's connection to the client. Notethat an attack variant exists that does not require this ability, seebelow.¶
In the following, we assume that the client is registered with H-AS(URI:https://honest.as.example
, client ID:7ZGZldHQ
) and withA-AS (URI:https://attacker.example
, client ID:666RVZJTA
).¶
Attack on the authorization code grant:¶
The user selects to start the grant using H-AS (e.g., by clicking on a button at theclient's website).¶
The attacker intercepts this request and changes the user'sselection to "A-AS" (see preconditions).¶
The client stores in the user's session that the user selected"A-AS" and redirects the user to A-AS's authorization endpointwith a Location header containing the URLhttps://attacker.example/authorize?response_type=code&client_id=666RVZJTA
.¶
Now the attacker intercepts this response and changes theredirection such that the user is being redirected to H-AS. Theattacker also replaces the client ID of the client at A-AS withthe client's ID at H-AS. Therefore, the browser receives aredirection (303 See Other
) with a Location header pointing tohttps://honest.as.example/authorize?response_type=code&client_id=7ZGZldHQ
¶
The user authorizes the client to access her resources atH-AS. H-AS issues a code and sends it (via the browser) back tothe client.¶
Since the client still assumes that the code was issued by A-AS,it will try to redeem the code at A-AS's token endpoint.¶
The attacker therefore obtains code and can either exchange thecode for an access token (for public clients) or perform anauthorization code injection attack as described inSection 4.5.¶
Variants:¶
Mix-Up Without Interception: A variant of the above attackworks even if the first request/response pair cannot beintercepted, for example, because TLS is used to protect thesemessages: Here, it is assumed that the user wants to start thegrant using A-AS (and not H-AS, see Attacker A1). After the clientredirected the user to the authorization endpoint at A-AS, theattacker immediately redirects the user to H-AS (changing theclient ID to7ZGZldHQ
). Note that a vigilant user might at thispoint detect that she intended to use A-AS instead of H-AS. Theattack now proceeds exactly as in Steps 3ff. of the attackdescription above.¶
Implicit Grant: In the implicit grant, the attacker receivesan access token instead of the code; the rest of the attack worksas above.¶
Per-AS Redirect URIs: If clients use different redirect URIsfor different ASs, do not store the selected AS in the user'ssession, and ASs do not check the redirect URIs properly,attackers can mount an attack called "Cross-Social Network RequestForgery". These attacks have been observed in practice. Refer to[oauth_security_jcs_14] for details.¶
OpenID Connect: There are variants that can be used to attackOpenID Connect. In these attacks, the attacker misuses features ofthe OpenID Connect Discovery mechanism or replays access tokens orID Tokens to conduct a Mix-Up Attack. The attacks are described indetail in[arXiv.1704.08539], Appendix A, and[arXiv.1508.04324v2], Section 6 ("Malicious Endpoints Attacks").¶
In scenarios where an OAuth client interacts with multipleauthorization servers, clients MUST prevent mix-up attacks.¶
To this end, clients SHOULD use distinct redirect URIs for each AS(with alternatives listed below). Clients MUST store, for eachauthorization request, the AS they sent the authorization request toand bind this information to the user agent. Clients MUST check thatthe authorization request was received from the correct authorizationserver and ensure that the subsequent token request, if applicable, issent to the same authorization server.¶
Unfortunately, distinct redirect URIs per AS do not work for all kindsof OAuth clients. They are effective for web and JavaScript apps andfor native apps with claimed URLs. Attacks on native apps using customschemes or redirect URIs on localhost cannot be prevented this way.¶
If clients cannot use distinct redirect URIs for each AS, the following options exist:¶
Authorization servers can be configured to return an ASidentitifier (iss
) as a non-standard parameter in theauthorization response. This enables complying clients to comparethis data to theiss
identifier of the AS it believed it sentthe user agent to.¶
In OpenID Connect, if an ID Token is returned in the authorizationresponse, it carries client ID and issuer. It can be used in thesame way as theiss
parameter.¶
In an authorization code injection attack, the attacker attempts toinject a stolen authorization code into the attacker's own sessionwith the client. The aim is to associate the attacker's session at theclient with the victim's resources or identity.¶
This attack is useful if the attacker cannot exchange theauthorization code for an access token himself. Examples include:¶
The code is bound to a particular confidential client and theattacker is unable to obtain the required client credentials toredeem the code himself.¶
The attacker wants to access certain functions in this particularclient. As an example, the attacker wants to impersonate hisvictim in a certain app or on a certain web site.¶
The authorization or resource servers are limited to certainnetworks that the attacker is unable to access directly.¶
In the following attack description and discussion, we assume thepresence of a web (A1) or network attacker (A2).¶
The attack works as follows:¶
The attacker obtains an authorization code by performing any ofthe attacks described above.¶
He performs a regular OAuth authorization process with thelegitimate client on his device.¶
The attacker injects the stolen authorization code in the responseof the authorization server to the legitimate client. Since thisresponse is passing through the attacker's device, the attackercan use any tool that can intercept and manipulate theauthorization response to this end. The attacker does not need tocontrol the network.¶
The legitimate client sends the code to the authorization server'stoken endpoint, along with the client's client ID, client secretand actualredirect_uri
.¶
The authorization server checks the client secret, whether thecode was issued to the particular client, and whether the actualredirect URI matches theredirect_uri
parameter (see[RFC6749]).¶
All checks succeed and the authorization server issues access andother tokens to the client. The attacker has now associated hissession with the legitimate client with the victim's resourcesand/or identity.¶
Obviously, the check in step (5.) will fail if the code was issued toanother client ID, e.g., a client set up by the attacker. The checkwill also fail if the authorization code was already redeemed by thelegitimate user and was one-time use only.¶
An attempt to inject a code obtained via a manipulated redirect URIshould also be detected if the authorization server stored thecomplete redirect URI used in the authorization request and comparesit with theredirect_uri
parameter.¶
[RFC6749], Section 4.1.3, requires the AS to "... ensure that theredirect_uri
parameter is present if theredirect_uri
parameterwas included in the initial authorization request as described inSection 4.1.1, and if included ensure that their values areidentical.". In the attack scenario described above, the legitimateclient would use the correct redirect URI it always uses forauthorization requests. But this URI would not match the tamperedredirect URI used by the attacker (otherwise, the redirect would notland at the attackers page). So the authorization server would detectthe attack and refuse to exchange the code.¶
Note: this check could also detect attempts to inject an authorizationcode which had been obtained from another instance of the same clienton another device, if certain conditions are fulfilled:¶
the redirect URI itself needs to contain a nonce or another kindof one-time use, secret data and¶
the client has bound this data to this particular instance of theclient.¶
But this approach conflicts with the idea to enforce exact redirectURI matching at the authorization endpoint. Moreover, it has beenobserved that providers very often ignore theredirect_uri
checkrequirement at this stage, maybe because it doesn't seem to besecurity-critical from reading the specification.¶
Other providers just pattern match theredirect_uri
parameteragainst the registered redirect URI pattern. This saves theauthorization server from storing the link between the actual redirectURI and the respective authorization code for every transaction. Butthis kind of check obviously does not fulfill the intent of thespecification, since the tampered redirect URI is not considered. Soany attempt to inject an authorization code obtained using theclient_id
of a legitimate client or by utilizing the legitimateclient on another device will not be detected in the respectivedeployments.¶
It is also assumed that the requirements defined in[RFC6749],Section 4.1.3, increase client implementation complexity as clientsneed to store or re-construct the correct redirect URI for the callto the token endpoint.¶
This document therefore recommends to instead bind every authorizationcode to a certain client instance on a certain device (or in a certainuser agent) in the context of a certain transaction using one of themechanisms described next.¶
There are two good technical solutions to achieve this goal:¶
PKCE: The PKCE parametercode_challenge
along with thecorrespondingcode_verifier
as specified in[RFC7636] can beused as a countermeasure. In contrast to its original intention,the verifier check fails although the client uses its correctverifier but the code is associated with a challenge that does notmatch. PKCE is a deployed OAuth feature, although its originalintended use was solely focused on securing native apps, not thebroader use recommended by this document.¶
Nonce: OpenID Connect's existingnonce
parameter can be usedfor the same purpose. Thenonce
value is one-time use andcreated by the client. The client is supposed to bind it to theuser agent session and sends it with the initial request to theOpenID Provider (OP). The OP bindsnonce
to the authorizationcode and attests this binding in the ID Token, which is issued aspart of the code exchange at the token endpoint. If an attackerinjected an authorization code in the authorization response, thenonce value in the client session and the nonce value in the IDtoken will not match and the attack is detected. The assumption isthat an attacker cannot get hold of the user agent state on thevictim's device, where he has stolen the respective authorizationcode.¶
Other solutions, like bindingstate
to the code, using token bindingfor the code, or per-instance client credentials are conceivable, butlack support and bring new security requirements.¶
PKCE is the most obvious solution for OAuth clients as it is availabletoday (originally intended for OAuth native apps) whereasnonce
isappropriate for OpenID Connect clients.¶
An attacker can circumvent the countermeasures described above if hecan modify thenonce
orcode_challenge
values that are used in thevictim's authorization request. The attacker can modify these valuesto be the same ones as those chosen by the client in his own sessionin Step 2 of the attack above. (This requires that the victim'ssession with the client begins after the attacker started his sessionwith the client.) If the attacker is then able to capture theauthorization code from the victim, the attacker will be able toinject the stolen code in Step 3 even if PKCE ornonce
are used.¶
This attack is complex and requires a close interaction between theattacker and the victim's session. Nonetheless, measures to preventattackers from reading the contents of the authorization responsestill need to be taken, as described inSection 4.1,Section 4.2,Section 4.3,Section 4.4, andSection 4.9.¶
In an access token injection attack, the attacker attempts to inject astolen access token into a legitimate client (that is not under theattacker's control). This will typically happen if the attacker wantsto utilize a leaked access token to impersonate a user in a certainclient.¶
To conduct the attack, the attacker starts an OAuth flow with theclient using the implicit grant and modifies the authorizationresponse by replacing the access token issued by the authorizationserver or directly makes up an authorization server response includingthe leaked access token. Since the response includes thestate
valuegenerated by the client for this particular transaction, the clientdoes not treat the response as a CSRF attack and uses the access tokeninjected by the attacker.¶
There is no way to detect such an injection attack on the OAuthprotocol level, since the token is issued without any binding to thetransaction or the particular user agent.¶
The recommendation is therefore to use the authorization code granttype instead of relying on response types issuing acess tokens at theauthorization endpoint. Authorization code injection can be detectedusing one of the countermeasures discussed inSection 4.5.¶
An attacker might attempt to inject a request to the redirect URI ofthe legitimate client on the victim's device, e.g., to cause theclient to access resources under the attacker's control. This is avariant of an attack known as Cross-Site Request Forgery (CSRF).¶
The traditional countermeasure are CSRF tokens that are bound to theuser agent and passed in thestate
parameter to the authorizationserver as described in[RFC6819]. The same protection is provided byPKCE or the OpenID Connectnonce
value.¶
When using PKCE instead ofstate
ornonce
for CSRF protection, it isimportant to note that:¶
Clients MUST ensure that the AS supports PKCE before using PKCE forCSRF protection. If an authorization server does not support PKCE,state
ornonce
MUST be used for CSRF protection.¶
Ifstate
is used for carrying application state, and integrity ofits contents is a concern, clients MUST protectstate
againsttampering and swapping. This can be achieved by binding thecontents of state to the browser session and/or signed/encryptedstate values[I-D.bradley-oauth-jwt-encoded-state].¶
AS therefore MUST provide a way to detect their support for PKCEeither via AS metadata according to[RFC8414] or provide adeployment-specific way to ensure or determine PKCE support.¶
Access tokens can leak from a resource server under certaincircumstances.¶
An attacker may setup his own resource server and trick a client intosending access tokens to it that are valid for other resource servers(see Attackers A1 and A5). If the client sends a valid access token tothis counterfeit resource server, the attacker in turn may use thattoken to access other services on behalf of the resource owner.¶
This attack assumes the client is not bound to one specific resourceserver (and its URL) at development time, but client instances areprovided with the resource server URL at runtime. This kind of latebinding is typical in situations where the client uses a serviceimplementing a standardized API (e.g., for e-Mail, calendar, health,or banking) and where the client is configured by a user oradministrator for a service which this user or company uses.¶
There are several potential mitigation strategies, which will bediscussed in the following sections.¶
An authorization server could provide the client with additionalinformation about the location where it is safe to use its accesstokens.¶
In the simplest form, this would require the AS to publish a list ofits known resource servers, illustrated in the following example usinga non-standard metadata parameterresource_servers
:¶
HTTP/1.1 200 OKContent-Type: application/json{ "issuer":"https://server.somesite.example", "authorization_endpoint": "https://server.somesite.example/authorize", "resource_servers":[ "email.somesite.example", "storage.somesite.example", "video.somesite.example" ] ...}¶
The AS could also return the URL(s) an access token is good for in thetoken response, illustrated by the example and non-standard returnparameteraccess_token_resource_server
:¶
HTTP/1.1 200 OKContent-Type: application/json;charset=UTF-8Cache-Control: no-storePragma: no-cache{ "access_token":"2YotnFZFEjr1zCsicMWpAA", "access_token_resource_server": "https://hostedresource.somesite.example/path1",...}¶
This mitigation strategy would rely on the client to enforce thesecurity policy and to only send access tokens to legitimatedestinations. Results of OAuth related security research (see forexample[oauth_security_ubc] and[oauth_security_cmu]) indicate alarge portion of client implementations do not or fail to properlyimplement security controls, likestate
checks. So relying onclients to prevent access token phishing is likely to fail as well.Moreover given the ratio of clients to authorization and resourceservers, it is considered the more viable approach to move as much aspossible security-related logic to those entities. Clearly, the clienthas to contribute to the overall security. But there are alternativecountermeasures, as described in the next sections, which provide abetter balance between the involved parties.¶
As the name suggests, sender-constrained access token scope theapplicability of an access token to a certain sender. This sender isobliged to demonstrate knowledge of a certain secret as prerequisitefor the acceptance of that token at a resource server.¶
A typical flow looks like this:¶
The authorization server associates data with the access tokenthat binds this particular token to a certain client. The bindingcan utilize the client identity, but in most cases the AS utilizeskey material (or data derived from the key material) known to theclient.¶
This key material must be distributed somehow. Either the keymaterial already exists before the AS creates the binding or theAS creates ephemeral keys. The way pre-existing key material isdistributed varies among the different approaches. For example,X.509 Certificates can be used in which case the distributionhappens explicitly during the enrollment process. Or the keymaterial is created and distributed at the TLS layer, in whichcase it might automatically happen during the setup of a TLSconnection.¶
The RS must implement the actual proof of possession check. Thisis typically done on the application level, often tied to specificmaterial provided by transport layer (e.g., TLS). The RS must alsoensure that replay of the proof of possession is not possible.¶
There exist several proposals to demonstrate the proof of possession in the scope of the OAuth working group:¶
OAuth 2.0 Mutual-TLS Client Authentication and Certificate-BoundAccess Tokens ([RFC8705]): The approach as specified in thisdocument allows the use of mutual TLS (mTLS) for both clientauthentication and sender-constrained access tokens. For thepurpose of sender-constrained access tokens, the client isidentified towards the resource server by the fingerprint of itspublic key. During processing of an access token request, theauthorization server obtains the client's public key from the TLSstack and associates its fingerprint with the respective accesstokens. The resource server in the same way obtains the public keyfrom the TLS stack and compares its fingerprint with thefingerprint associated with the access token.¶
DPoP ([I-D.ietf-oauth-dpop]): DPoP (Demonstration ofProof-of-Possession at the Application Layer) outlines anapplication-level sender-constraining for access and refreshtokens that can be used in cases where neither mTLS nor OAuthToken Binding (see below) are available. It usesproof-of-possession based on a public/private key pair andapplication-level signing. DPoP can be used with public clientsand, in case of confidential clients, can be combined with anyclient authentication method.¶
OAuth Token Binding ([I-D.ietf-oauth-token-binding]): In this approach, an accesstoken is, via the token binding ID, bound to keymaterial representing a long term association between a client anda certain TLS host. Negotiation of the key material and proof ofpossession in the context of a TLS handshake is taken care of bythe TLS stack. The client needs to determine the token binding IDof the target resource server and pass this data to the accesstoken request. The authorization server then associates the accesstoken with this ID. The resource server checks on every invocationthat the token binding ID of the active TLS connection and thetoken binding ID of associated with the access token match. Sinceall crypto-related functions are covered by the TLS stack, thisapproach is very client developer friendly. As a prerequisite,token binding as described in[RFC8473](including federated token bindings) must be supported on all ends(client, authorization server, resource server).¶
Signed HTTP Requests ([I-D.ietf-oauth-signed-http-request]):This approach utilizes[I-D.ietf-oauth-pop-key-distribution] andrepresents the elements of the signature in a JSON object. Thesignature is built using JWS. The mechanism has built-in supportfor signing of HTTP method, query parameters and headers. It alsoincorporates a timestamp as basis for replay prevention.¶
JWT Pop Tokens ([I-D.sakimura-oauth-jpop]): This draftdescribes different ways to constrain access token usage, namelyTLS or request signing. Note: Since the authors of this draftcontributed the TLS-related proposal to[RFC8705],this document only considers the request signing part. For requestsigning, the draft utilizes[I-D.ietf-oauth-pop-key-distribution] and[RFC7800]. Thesignature data is represented in a JWT and JWS is used forsigning. Replay prevention is provided by building the signatureover a server-provided nonce, client-provided nonce and a noncecounter.¶
At the time of writing, OAuth Mutual TLS is the most widelyimplemented and the only standardized sender-constraining method. Theuse of OAuth Mutual TLS therefore is RECOMMENDED.¶
Note that the security of sender-constrained tokens is undermined whenan attacker gets access to the token and the key material. This is inparticular the case for corrupted client software and cross-sitescripting attacks (when the client is running in the browser). If thekey material is protected in a hardware or software security module oronly indirectly accessible (like in a TLS stack), sender-constrainedtokens at least protect against a use of the token when the client isoffline, i.e., when the security module or interface is not availableto the attacker. This applies to access tokens as well as to refreshtokens (seeSection 4.12).¶
Audience restriction essentially restricts access tokens to aparticular resource server. The authorization server associates theaccess token with the particular resource server and the resourceserver SHOULD verify the intended audience. If the access token failsthe intended audience validation, the resource server must refuse toserve the respective request.¶
In general, audience restrictions limit the impact of token leakage.In the case of a counterfeit resource server, it may (as describedbelow) also prevent abuse of the phished access token at thelegitimate resource server.¶
The audience can be expressed using logical names orphysical addresses (like URLs). In order to prevent phishing, it isnecessary to use the actual URL the client will send requests to. Inthe phishing case, this URL will point to the counterfeit resourceserver. If the attacker tries to use the access token at thelegitimate resource server (which has a different URL), the resourceserver will detect the mismatch (wrong audience) and refuse to servethe request.¶
In deployments where the authorization server knows the URLs of allresource servers, the authorization server may just refuse to issueaccess tokens for unknown resource server URLs.¶
The client SHOULD tell the authorization server the intendedresource server. The proposed mechanism[I-D.ietf-oauth-resource-indicators] could be used or by encoding theinformation in the scope value.¶
Instead of the URL, it is also possible to utilize the fingerprint ofthe resource server's X.509 certificate as audience value. Thisvariant would also allow to detect an attempt to spoof the legitimateresource server's URL by using a valid TLS certificate obtained from adifferent CA. It might also be considered a privacy benefit to hidethe resource server URL from the authorization server.¶
Audience restriction may seem easier to use since it does not requireany crypto on the client-side. Still, since every access token isbound to a specific resource server, the client also needs to obtain asingle RS-specific access token when accessing several resourceservers. (Resource indicators, as specified in[I-D.ietf-oauth-resource-indicators], can help to achieve this.)[I-D.ietf-oauth-token-binding] has the same property since differenttoken binding ids must be associated with the access token. Using[RFC8705], on the other hand, allows a client to use theaccess token at multiple resource servers.¶
It shall be noted that audience restrictions, or generally speaking anindication by the client to the authorization server where it wants touse the access token, has additional benefits beyond the scope oftoken leakage prevention. It allows the authorization server to createdifferent access token whose format and content is specifically mintedfor the respective server. This has huge functional and privacyadvantages in deployments using structured access tokens.¶
An attacker may compromise a resource server to gain access to theresources of the respective deployment. Such a compromise may rangefrom partial access to the system, e.g., its log files, to fullcontrol of the respective server.¶
If the attacker were able to gain full control, including shellaccess, all controls can be circumvented and all resources beaccessed. The attacker would also be able to obtain other accesstokens held on the compromised system that would potentially be validto access other resource servers.¶
Preventing server breaches by hardening and monitoring server systemsis considered a standard operational procedure and, therefore, out ofthe scope of this document. This section focuses on the impact ofOAuth-related breaches and the replaying of captured access tokens.¶
The following measures should be taken into account by implementers inorder to cope with access token replay by malicious actors:¶
Sender-constrained access tokens as described inSection 4.8.1.1.2SHOULD be used to prevent the attacker from replaying the accesstokens on other resource servers. Depending on the severity of thepenetration, sender-constrained access tokens will also preventreplay on the compromised system.¶
Audience restriction as described inSection 4.8.1.1.3 SHOULD beused to prevent replay of captured access tokens on other resourceservers.¶
The resource server MUST treat access tokens like any othercredentials. It is considered good practice to not log them andnot store them in plain text.¶
The first and second recommendation also apply to other scenarioswhere access tokens leak (see Attacker A5).¶
The following attacks can occur when an AS or client has an openredirector. An open redirector is an endpoint that forwards a user'sbrowser to an arbitrary URI obtained from a query parameter.¶
Clients MUST NOT expose open redirectors. Attackers may use openredirectors to produce URLs pointing to the client and utilize them toexfiltrate authorization codes and access tokens, as described inSection 4.1.2. Another abuse case is to produce URLs thatappear to point to the client. This might trick users into trusting the URLand follow it in their browser. This can be abused for phishing.¶
In order to prevent open redirection, clients should only redirect ifthe target URLs are whitelisted or if the origin and integrity of arequest can be authenticated. Countermeasures against open redirectionare described by OWASP[owasp_redir].¶
Just as with clients, attackers could try to utilize a user's trust inthe authorization server (and its URL in particular) for performingphishing attacks. OAuth authorization servers regularly redirect usersto other web sites (the clients), but must do so in a safe way.¶
[RFC6749], Section 4.1.2.1, already prevents open redirects bystating that the AS MUST NOT automatically redirect the user agent in caseof an invalid combination ofclient_id
andredirect_uri
.¶
However, an attacker could also utilize a correctly registeredredirect URI to perform phishing attacks. The attacker could, forexample, register a client via dynamic client registration[RFC7591]and intentionally send an erroneous authorization request, e.g., byusing an invalid scope value, thus instructing the AS to redirect theuser agent to its phishing site.¶
The AS MUST take precautions to prevent this threat. Based on its riskassessment, the AS needs to decide whether it can trust the redirectURI and SHOULD only automatically redirect the user agent if it truststhe redirect URI. If the URI is not trusted, the AS MAY inform theuser and rely on the user to make the correct decision.¶
At the authorization endpoint, a typical protocol flow is that the ASprompts the user to enter her credentials in a form that is thensubmitted (using the HTTP POST method) back to the authorizationserver. The AS checks the credentials and, if successful, redirectsthe user agent to the client's redirection endpoint.¶
In[RFC6749], the HTTP status code 302 is used for this purpose, but"any other method available via the user-agent to accomplish thisredirection is allowed". When the status code 307 is used forredirection instead, the user agent will send the user credentials viaHTTP POST to the client.¶
This discloses the sensitive credentials to the client. If the relyingparty is malicious, it can use the credentials to impersonate the userat the AS.¶
The behavior might be unexpected for developers, but is defined in[RFC7231], Section 6.4.7. This status code does not require the useragent to rewrite the POST request to a GET request and thereby dropthe form data in the POST request body.¶
In the HTTP standard[RFC7231], only the status code 303unambigiously enforces rewriting the HTTP POST request to an HTTP GETrequest. For all other status codes, including the popular 302, useragents can opt not to rewrite POST to GET requests and therefore toreveal the user credentials to the client. (In practice, however, mostuser agents will only show this behaviour for 307 redirects.)¶
AS which redirect a request that potentially contains user credentialstherefore MUST NOT use the HTTP 307 status code for redirection. If anHTTP redirection (and not, for example, JavaScript) is used for such arequest, AS SHOULD use HTTP status code 303 "See Other".¶
A common deployment architecture for HTTP applications is to hide theapplication server behind a reverse proxy that terminates the TLSconnection and dispatches the incoming requests to the respectiveapplication server nodes.¶
This section highlights some attack angles of this deploymentarchitecture with relevance to OAuth and gives recommendations forsecurity controls.¶
In some situations, the reverse proxy needs to pass security-relateddata to the upstream application servers for further processing.Examples include the IP address of the request originator, tokenbinding ids, and authenticated TLS client certificates. This data isusually passed in custom HTTP headers added to the upstream request.¶
If the reverse proxy would pass through any header sent from theoutside, an attacker could try to directly send the faked headervalues through the proxy to the application server in order tocircumvent security controls that way. For example, it is standardpractice of reverse proxies to acceptX-Forwarded-For
headers and justadd the origin of the inbound request (making it a list). Depending onthe logic performed in the application server, the attacker couldsimply add a whitelisted IP address to the header and render a IPwhitelist useless.¶
A reverse proxy must therefore sanitize any inbound requests to ensurethe authenticity and integrity of all header values relevant for thesecurity of the application servers.¶
If an attacker was able to get access to the internal network betweenproxy and application server, the attacker could also try tocircumvent security controls in place. It is, therefore, essential toensure the authenticity of the communicating entities. Furthermore,the communication link between reverse proxy and application servermust be protected against eavesdropping, injection, and replay ofmessages.¶
Refresh tokens are a convenient and user-friendly way to obtain new accesstokens after the expiration of access tokens. Refresh tokens also addto the security of OAuth since they allow the authorization server to issueaccess tokens with a short lifetime and reduced scope thus reducing thepotential impact of access token leakage.¶
Refresh tokens are an attractive target for attackers since theyrepresent the overall grant a resource owner delegated to a certainclient. If an attacker is able to exfiltrate and successfully replay arefresh token, the attacker will be able to mint access tokens and usethem to access resource servers on behalf of the resource owner.¶
[RFC6749] already provides a robust baseline protection by requiring¶
confidentiality of the refresh tokens in transit and storage,¶
the transmission of refresh tokens over TLS-protected connections betweenauthorization server and client,¶
the authorization server to maintain and check the binding of a refresh tokento a certain client (i.e.,client_id
),¶
authentication of this client during token refresh, if possible, and¶
that refresh tokens cannot be generated, modified, or guessed.¶
[RFC6749] also lays the foundation for further (implementationspecific) security measures, such as refresh token expiration andrevocation as well as refresh token rotation by defining respectiveerror codes and response behavior.¶
This specification gives recommendations beyond the scope of[RFC6749] and clarifications.¶
Authorization servers SHOULD determine, based on a risk assessment,whether to issue refresh tokens to a certain client. If theauthorization server decides not to issue refresh tokens, the clientMAY refresh access tokens by utilizing other grant types, such as theauthorization code grant type. In such a case, the authorizationserver may utilize cookies and persistent grants to optimize the userexperience.¶
If refresh tokens are issued, those refresh tokens MUST be bound tothe scope and resource servers as consented by the resource owner.This is to prevent privilege escalation by the legitimate client and reducethe impact of refresh token leakage.¶
Authorization server MUST utilize one of these methods todetect refresh token replay by malicious actors for public clients:¶
Sender-constrained refresh tokens: the authorization servercryptographically binds the refresh token to a certain clientinstance by utilizing[I-D.ietf-oauth-token-binding] or[RFC8705].¶
Refresh token rotation: the authorization server issues a newrefresh token with every access token refresh response. Theprevious refresh token is invalidated but information about therelationship is retained by the authorization server. If a refreshtoken is compromised and subsequently used by both the attackerand the legitimate client, one of them will present an invalidatedrefresh token, which will inform the authorization server of thebreach. The authorization server cannot determine which partysubmitted the invalid refresh token, but it will revoke theactive refresh token. This stops the attack at the cost of forcingthe legitimate client to obtain a fresh authorization grant.¶
Implementation note: the grant to which a refresh token belongsmay be encoded into the refresh token itself. This can enable anauthorization server to efficiently determine the grant to which arefresh token belongs, and by extension, all refresh tokens thatneed to be revoked. Authorization servers MUST ensure theintegrity of the refresh token value in this case, for example,using signatures.¶
Authorization servers MAY revoke refresh tokens automatically in caseof a security event, such as:¶
Refresh tokens SHOULD expire if the client has been inactive for sometime, i.e., the refresh token has not been used to obtain fresh accesstokens for some time. The expiration time is at the discretion of theauthorization server. It might be a global value or determined basedon the client policy or the grant associated with the refresh token(and its sensitivity).¶
Resource servers may make access control decisions based on theidentity of the resource owner as communicated in thesub
claimreturned by the authorization server in a token introspection response[RFC7662] or other mechanisms. If a client is able to choose its ownclient_id
during registration with the authorization server, thenthere is a risk that it can register with the samesub
value as aprivileged user. A subsequent access token obtained under the clientcredentials grant may be mistaken for an access token authorized by theprivileged user if the resource server does not perform additionalchecks.¶
Authorization servers SHOULD NOT allow clients to influence theirclient_id
orsub
value or any other claim if that can causeconfusion with a genuine resource owner. Where this cannot be avoided,authorization servers MUST provide other means for the resource serverto distinguish between access tokens authorized by a resource ownerfrom access tokens authorized by the client itself.¶
As described in Section 4.4.1.9 of[RFC6819], the authorizationrequest is susceptible to clickjacking. An attacker can use thisvector to obtain the user's authentication credentials, change thescope of access granted to the client, and potentially access theuser's resources.¶
Authorization servers MUST prevent clickjacking attacks. Multiplecountermeasures are described in[RFC6819], including the use of theX-Frame-Options HTTP response header field and frame-bustingJavaScript. In addition to those, authorization servers SHOULD alsouse Content Security Policy (CSP) level 2[CSP-2] or greater.¶
To be effective, CSP must be used on the authorization endpoint and,if applicable, other endpoints used to authenticate the user andauthorize the client (e.g., the device authorization endpoint, loginpages, error pages, etc.). This prevents framing by unauthorizedorigins in user agents that support CSP. The client MAY permit beingframed by some other origin than the one used in its redirectionendpoint. For this reason, authorization servers SHOULD allowadministrators to configure allowed origins for particular clientsand/or for clients to register these dynamically.¶
Using CSP allows authorization servers to specify multiple origins ina single response header field and to constrain these using flexiblepatterns (see[CSP-2] for details). Level 2 of this standard providesa robust mechanism for protecting against clickjacking by usingpolicies that restrict the origin of frames (usingframe-ancestors
)together with those that restrict the sources of scripts allowed toexecute on an HTML page (by usingscript-src
). A non-normativeexample of such a policy is shown in the following listing:¶
HTTP/1.1 200 OKContent-Security-Policy: frame-ancestors https://ext.example.org:8000Content-Security-Policy: script-src 'self'X-Frame-Options: ALLOW-FROM https://ext.example.org:8000...¶
Because some user agents do not support[CSP-2], this techniqueSHOULD be combined with others, including those described in[RFC6819], unless such legacy user agents are explicitly unsupportedby the authorization server. Even in such cases, additionalcountermeasures SHOULD still be employed.¶
We would like to thank Jim Manico, Phil Hunt, Nat Sakimura, ChristianMainka, Doug McDorman, Johan Peeters, Joseph Heenan, Brock Allen,Vittorio Bertocci, David Waite, Nov Matake, Tomek Stojecki, DominickBaier, Neil Madden, William Dennis, Dick Hardt, Petteri Stenius,Annabelle Richard Backman, Aaron Parecki, George Fletscher, BrianCampbell, Konstantin Lapine, Tim Würtele, Guido Schmitz, HansZandbelt, Jared Jennings, Michael Peck, Pedram Hosseyni, MichaelB. Jones, and Travis Spencer for their valuable feedback.¶
This draft includes no request to IANA.¶
All relevant security considerations have been given in thefunctional specification.¶
[[ To be removed from the final specification ]]¶
-15¶
Added info about using CSP to prevent clickjacking¶
-14¶
Changes from WGLC feedback¶
Editorial changes¶
AS MUST announce PKCE support either in metadata or using deployment-specific ways (before: SHOULD)¶
-13¶
Discourage use of Resource Owner Password Credentials Grant¶
Added text on client impersonating resource owner¶
Recommend asymmetric methods for client authentication¶
Encourage use of PKCE mode "S256"¶
PKCE may replace state for CSRF protection¶
AS SHOULD publish PKCE support¶
Cleaned up discussion on auth code injection¶
AS MUST support PKCE¶
-12¶
Added updated attacker model¶
-11¶
Adapted section 2.1.2 to outcome of consensus call¶
more text on refresh token inactivity and implementation note on refresh token replay detection via refresh token rotation¶
-10¶
incorporated feedback by Joseph Heenan¶
changed occurrences of SHALL to MUST¶
added text on lack of token/cert binding support tokens issued in the authorization response as justification to not recommend issuing tokens there at all¶
added requirement to authenticate clients during code exchange (PKCE or client credential) to 2.1.1.¶
added section on refresh tokens¶
editorial enhancements to 2.1.2 based on feedback¶
-09¶
changed text to recommend not to use implicit but code¶
added section on access token injection¶
reworked sections 3.1 through 3.3 to be more specific on implicit grant issues¶
-08¶
added recommendations re implicit and token injection¶
uppercased key words in Section 2 according to RFC 2119¶
-07¶
incorporated findings of Doug McDorman¶
added section on HTTP status codes for redirects¶
added new section on access token privilege restriction based on comments from Johan Peeters¶
-06¶
reworked section 3.8.1¶
incorporated Phil Hunt's feedback¶
reworked section on mix-up¶
extended section on code leakage via referrer header to also cover state leakage¶
added Daniel Fett as author¶
replaced text intended to inform WG discussion by recommendations to implementors¶
modified example URLs to conform to RFC 2606¶
-05¶
Completed sections on code leakage via referrer header, attacks in browser, mix-up, and CSRF¶
Reworked Code Injection Section¶
Added reference to OpenID Connect spec¶
removed refresh token leakage as respective considerations have been given in section 10.4 of RFC 6749¶
first version on open redirection¶
incorporated Christian Mainka's review feedback¶
-04¶
-03¶
-02¶
Folded Mix up and Access Token leakage through a bad AS into new section for dynamic OAuth threats¶
reworked dynamic OAuth section¶
-01¶
Added references to mitigation methods for token leakage¶
Added reference to Token Binding for Authorization Code¶
incorporated feedback of Phil Hunt¶
fixed numbering issue in attack descriptions in section 2¶
-00 (WG document)¶
draft-ietf-oauth-security-topics-15
Document | Document type | This is an older version of an Internet-Draft that was ultimately published asRFC 9700. | |
---|---|---|---|
Select version | |||
Compare versions | |||
Authors | Torsten Lodderstedt,John Bradley,Andrey Labunets,Daniel Fett | ||
Replaces | draft-lodderstedt-oauth-security-topics | ||
RFC stream | |||
Other formats | |||
Additional resources | Mailing list discussion |