RFC 9700: BCP 240: Best Current Practice for OAuth 2.0 Security
- T. Lodderstedt,
- J. Bradley,
- A. Labunets,
- D. Fett
Abstract
This document describes best current security practice for OAuth 2.0. It updates and extends the threat model and security advice given in RFCs 6749, 6750, and 6819 to incorporate practical experiences gathered since OAuth 2.0 was published and covers new threats relevant due to the broader application of OAuth 2.0. Further, it deprecates some modes of operation that are deemed less secure or even insecure.¶
Status of This Memo
This memo documents an Internet Best Current Practice.¶
This document is a product of the Internet Engineering Task Force (IETF). It represents the consensus of the IETF community. It has received public review and has been approved for publication by the Internet Engineering Steering Group (IESG). Further information on BCPs is available in Section 2 of RFC 7841.¶
Information about the current status of this document, any
errata, and how to provide feedback on it may be obtained at
https://
Copyright Notice
Copyright (c) 2025 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://
1. Introduction
Since its publication in [RFC6749] and [RFC6750], OAuth 2.0 (referred to as simply "OAuth" in this document) has gained massive traction in the market and became the standard for API protection and the basis for federated login using OpenID Connect [OpenID.Core]. While OAuth is used in a variety of scenarios and different kinds of deployments, the following challenges can be observed:¶
This document provides updated security recommendations to address these challenges. It introduces new requirements beyond those defined in existing specifications such as OAuth 2.0 [RFC6749] and OpenID Connect [OpenID.Core] and deprecates some modes of operation that are deemed less secure or even insecure. However, this document does not supplant the security advice given in [RFC6749], [RFC6750], and [RFC6819], but complements those documents.¶
Naturally, not all existing ecosystems and implementations are
compatible with the new requirements, and following the best practices described in
this document may break interoperabilit
OAuth 2.1, under development as [OAUTH-V2.1], will incorporate security recommendations from this document.¶
1.1. Structure
The remainder of this document is organized as follows: Section 2
summarizes the most important best practices for every OAuth implementer.
Section 3 presents the updated OAuth attacker model. Section 4 is a
detailed analysis of the threats and implementation issues that can be found in
the wild (at the time of writing) along with a discussion of potential countermeasures
1.2. Conventions and Terminology
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in BCP 14 [RFC2119] [RFC8174] when, and only when, they appear in all capitals, as shown here.¶
This specification uses the terms "access token", "authorization endpoint", "authorization grant", "authorization server", "client", "client identifier" (client ID), "protected resource", "refresh token", "resource owner", "resource server", and "token endpoint" defined by OAuth 2.0 [RFC6749].¶
An "open redirector" is an endpoint on a web server that forwards a user's browser to an arbitrary URI obtained from a query parameter.¶
2. Best Practices
This section describes the core set of security mechanisms and measures that are considered to be best practices at the time of writing. Details about these security mechanisms and measures (including detailed attack descriptions) and requirements for less commonly used options are provided in Section 4.¶
2.1. Protecting Redirect-Based Flows
When comparing client redirection URIs against pre-registered URIs, authorization
servers MUST utilize exact string matching except for port numbers in
localhost redirection URIs of native apps (see Section 4.1.3). This
measure contributes to the prevention of leakage of authorization codes and
access tokens (see Section 4.1). It can also help to detect
mix-up attacks (see Section 4.4).¶
Clients and authorization servers MUST NOT expose URLs that forward the user's browser to arbitrary URIs obtained from a query parameter (open redirectors) as described in Section 4.11. Open redirectors can enable exfiltration of authorization codes and access tokens.¶
Clients MUST prevent Cross-Site Request Forgery (CSRF). In this
context, CSRF refers to requests to the redirection endpoint that do
not originate at the authorization server, but at a malicious third party
(see Section 4.4.1.8 of [RFC6819] for details). Clients that have
ensured that the authorization server supports Proof Key for Code Exchange (PKCE) [RFC7636] MAY
rely on the CSRF protection provided by PKCE. In OpenID Connect flows,
the nonce parameter provides CSRF protection. Otherwise, one-time
use CSRF tokens carried in the state parameter that are securely
bound to the user agent MUST be used for CSRF protection (see
Section 4.7.1).¶
When an OAuth client can interact with more than one authorization server, a defense against mix-up attacks (see Section 4.4) is REQUIRED. To this end, clients SHOULD¶
In the absence of these options, clients MAY instead use distinct redirection URIs to identify authorization endpoints and token endpoints, as described in Section 4.4.2.¶
An authorization server that redirects a request potentially containing user credentials MUST avoid forwarding these user credentials accidentally (see Section 4.12 for details).¶
2.1.1. Authorization Code Grant
Clients MUST prevent authorization code injection attacks (see Section 4.5) and misuse of authorization codes using one of the following options:¶
In any case, the PKCE challenge or OpenID Connect nonce MUST be
transactionnonce.¶
Note: Although PKCE was designed as a mechanism to protect native apps, this advice applies to all kinds of OAuth clients, including web applications.¶
When using PKCE, clients SHOULD use PKCE code challenge methods that
do not expose the PKCE verifier in the authorization request.
Otherwise, attackers that can read the authorization request (cf. Attacker (A4) in Section 3) can break the security provided
by PKCE. Currently, S256 is the only such method.¶
Authorization servers MUST support PKCE [RFC7636].¶
If a client sends a valid PKCE code_challenge parameter in the
authorization request, the authorization server MUST enforce the correct usage
of code_verifier at the token endpoint.¶
Authorization servers MUST mitigate PKCE downgrade attacks by ensuring that a
token request containing a code_verifier parameter is accepted only if a
code_challenge parameter was present in the authorization request; see
Section 4.8.2 for details.¶
Authorization servers MUST provide a way to detect their support for
PKCE. It is RECOMMENDED for authorization servers to publish the element
code in their Authorization Server Metadata [RFC8414]
containing the supported PKCE challenge methods (which can be used by
the client to detect PKCE support). Authorization servers MAY instead provide a
deployment
2.1.2. Implicit Grant
The implicit grant (response type token) and other response types
causing the authorization server to issue access tokens in the
authorization response are vulnerable to access token leakage and
access token replay as described in Sections 4.1,
4.2, 4.3, and
4.6.¶
Moreover, no standardized method for sender
In order to avoid these issues, clients SHOULD NOT use the implicit
grant (response type token) or other response types issuing
access tokens in the authorization response, unless access token injection
in the authorization response is prevented and the aforementioned token leakage
vectors are mitigated.¶
Clients SHOULD instead use the response type code (i.e., authorization
code grant type) as specified in Section 2.1.1 or any other response type that
causes the authorization server to issue access tokens in the token
response, such as the code id_token response type. This allows the
authorization server to detect replay attempts by attackers and
generally reduces the attack surface since access tokens are not
exposed in URLs. It also allows the authorization server to
sender
2.2. Token Replay Prevention
2.2.1. Access Tokens
A sender
Authorization and resource servers SHOULD use mechanisms for sender
2.2.2. Refresh Tokens
Refresh tokens for public clients MUST be sender
2.3. Access Token Privilege Restriction
The privileges associated with an access token SHOULD be restricted to the minimum required for the particular application or use case. This prevents clients from exceeding the privileges authorized by the resource owner. It also prevents users from exceeding their privileges authorized by the respective security policy. Privilege restrictions also help to reduce the impact of access token leakage.¶
In particular, access tokens SHOULD be audienceaud claim as defined in [RFC9068] MAY be
used to audiencescope or resource as specified in [RFC6749] and
[RFC8707], respectively, to determine the
resource server they want to access.¶
Additionally, access tokens SHOULD be restricted to certain resources
and actions on resource servers or resources. To put this into effect,
the authorization server associates the access token with the
respective resource and actions and every resource server is obliged
to verify, for every request, whether the access token sent with that
request was meant to be used for that particular action on the
particular resource. If not, the resource server must refuse to serve
the respective request. Clients and authorization servers MAY utilize
the parameter scope as specified in [RFC6749] and authorization as specified in [RFC9396] to determine those
resources and/or actions.¶
2.4. Resource Owner Password Credentials Grant
The resource owner password credentials grant [RFC6749] MUST NOT be used. This grant type insecurely exposes the credentials of the resource owner to the client. Even if the client is benign, usage of this grant results in an increased attack surface (i.e., credentials can leak in more places than just the authorization server) and in training users to enter their credentials in places other than the authorization server.¶
Furthermore, the resource owner password credentials grant is not designed to work with two-factor authentication and authentication processes that require multiple user interaction steps. Authentication with cryptographic credentials (cf. WebCrypto [W3C.WebCrypto], WebAuthn [W3C.WebAuthn]) may be impossible to implement with this grant type, as it is usually bound to a specific web origin.¶
2.5. Client Authentication
Authorization servers SHOULD enforce client authentication if it is feasible, in
the particular deployment, to establish a process for issuance
It is RECOMMENDED to use asymmetric cryptography for
client authentication, such as mutual TLS for OAuth 2.0 [RFC8705] or signed JWTs
("Private Key JWT") in accordance with [RFC7521] and [RFC7523]. The latter is defined in [OpenID.Core] as the client authentication method private_key_jwt).
When asymmetric cryptography for client authentication is used, authorization
servers do not need to store sensitive symmetric keys, making these
methods more robust against leakage of keys.¶
2.6. Other Recommendations
The use of OAuth Authorization Server Metadata [RFC8414] can help to improve the security of OAuth deployments:¶
It is therefore RECOMMENDED that authorization servers publish OAuth Authorization Server Metadata according to [RFC8414] and that clients make use of this Authorization Server Metadata (when available) to configure themselves.¶
Under the conditions described in Section 4.15.1,
authorization servers SHOULD NOT allow clients to influence their client_id or
any other claim that could cause confusion with a genuine resource owner.¶
It is RECOMMENDED to use end-to-end TLS according to [BCP195] between the client and the resource server. If TLS traffic needs to be terminated at an intermediary, refer to Section 4.13 for further security advice.¶
Authorization responses MUST NOT be transmitted over unencrypted network
connections. To this end, authorization servers MUST NOT allow redirection URIs that use the http
scheme except for native clients that use loopback interface redirection as
described in Section 7.3 of [RFC8252].¶
If the authorization response is sent with in-browser communication techniques
like postMessage [WHATWG
To support browser-based clients, endpoints directly accessed by such clients
including the Token Endpoint, Authorization Server Metadata Endpoint, jwks_uri
Endpoint, and Dynamic Client Registration Endpoint MAY support the use of
Cross-Origin Resource Sharing (CORS) [WHATWG.CORS].
However, CORS MUST NOT be
supported at the authorization endpoint, as the client does not access this
endpoint directly; instead, the client redirects the user agent to it.¶
3. The Updated OAuth 2.0 Attacker Model
In [RFC6819], a threat model is laid out that describes the threats against which OAuth deployments must be protected. While doing so, [RFC6819] makes certain assumptions about attackers and their capabilities, i.e., it implicitly establishes an attacker model. In the following, this attacker model is made explicit and is updated and expanded to account for the potentially dynamic relationships involving multiple parties (as described in Section 1), to include new types of attackers, and to define the attacker model more clearly.¶
The goal of this document is to ensure that the authorization of a resource owner (with a user agent) at an authorization server and the subsequent usage of the access token at a resource server is protected, as well as practically possible, at least against the following attackers.¶
- (A1)
-
Web attackers that can set up and operate an arbitrary number of network endpoints (besides the "honest" ones) including browsers and servers. Web attackers may set up websites that are visited by the resource owner, operate their own user agents, and participate in the protocol.¶
In particular, web attackers may operate OAuth clients that are registered at the authorization server, and they may operate their own authorization and resource servers that can be used (in parallel to the "honest" ones) by the resource owner and other resource owners.¶
It must also be assumed that web attackers can lure the user to navigate their browser to arbitrary attacker-chosen URIs at any time. In practice, this can be achieved in many ways, for example, by injecting malicious advertisements into advertisement networks or by sending legitimate
-looking emails.¶ Web attackers can use their own user credentials to create new messages as well as any secrets they learned previously. For example, if a web attacker learns an authorization code of a user through a misconfigured redirection URI, the web attacker can then try to redeem that code for an access token.¶
They cannot, however, read or manipulate messages that are not targeted towards them (e.g., sent to a URL of an authorization server not under control of an attacker).¶
- (A2)
-
Network attackers that additionally have full control over the network over which protocol participants communicate. They can eavesdrop on, manipulate, and spoof messages, except when these are 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 internet service provider, network attackers could be the internet service provider itself, an attacker in a public (Wi-Fi) network using ARP spoofing, or a state-sponsored attacker with access to internet exchange points, for instance.¶
The aforementioned attackers (A1) and (A2) conform to the attacker model that was used in formal analysis
efforts for OAuth [arXiv.1601.01229]. This is a minimal attacker model.
Implementers MUST take into account all possible types of attackers in the
environment of their OAuth implementations
However, previous attacks on OAuth have shown that the following types of attackers are relevant in particular:¶
- (A3)
-
Attackers that can read, but not modify, the contents of the authorization response (i.e., the authorization response can leak to an attacker).¶
Examples of such attacks include open redirector attacks and mix-up attacks (see Section 4.4), where the client is tricked into sending credentials to an attacker
-controlled authorization server.¶ Also, this includes attacks that take advantage of:¶
- (A4)
-
Attackers that can read, but not modify, the contents of the authorization 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 an authorization server. For example, a resource server may be compromised by an attacker, an access token may be sent to an attacker
-controlled resource server due to a misconfiguratio n, or social engineering may be used to get a resource owner to use an attacker -controlled resource server. Also see Section 4.9.2.¶
(A3), (A4), and (A5) typically occur together with either (A1) or (A2). Attackers can collaborate to reach a common goal.¶
Note that an Attacker (A1) or (A2) can be a resource owner or act as one. For example, such an attacker can use their own browser to replay tokens or authorization codes obtained by any of the attacks described above at the client or resource server.¶
This document focuses on threats resulting from Attackers (A1) to (A5).¶
4. Attacks and Mitigations
This section gives a detailed description of attacks on OAuth implementations
This section further defines additional requirements (beyond those defined in Section 2) for certain cases and protocol options.¶
4.1. Insufficient Redirection URI Validation
Some authorization servers allow clients to register redirection URI patterns instead of complete redirection URIs. The authorization servers then match the redirection URI parameter value at the authorization endpoint against the registered patterns at runtime. This approach allows clients to encode transaction state into additional redirect URI parameters or to register a single pattern for multiple redirection URIs.¶
This approach turned out to be more complex to implement and more
error-prone to manage than exact redirection URI matching. Several
successful attacks exploiting flaws in the pattern
These attacks are shown in detail in the following subsections.¶
4.1.1. Redirect URI Validation Attacks on Authorization Code Grant
For a client using the grant type code, an attack may work as
follows:¶
Assume the redirection URL pattern https:// is
registered for the client with the client ID s6BhdRkqt3. The
intention is to allow any subdomain of somesite.example to be a
valid redirection URI for the client, for example,
https://. However, a naive implementation on
the authorization server might interpret the wildcard * as
"any character" and not "any character valid for a domain name". The
authorization server, therefore, might permit
https:// as a redirection URI,
although attacker.example is a different domain potentially
controlled by a malicious party.¶
The attack can then be conducted as follows:¶
To begin, the attacker needs to trick the user into opening a tampered
URL in their browser that launches a page under the attacker's
control, say, https:// (see attacker A1 in Section 3).¶
This URL initiates the following authorization request with the client ID of a legitimate client to the authorization endpoint (line breaks for display only):¶
The authorization server validates the redirection URI and compares it to
the registered redirection URL patterns for the client s6BhdRkqt3.
The authorization request is processed and presented to the user.¶
If the user does not see the redirection URI or does not recognize the attack, the code is issued and immediately sent to the attacker's domain. 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 user interaction.¶
If the attacker impersonates a public client, the attacker can exchange the code for tokens at the respective token endpoint.¶
This attack will not work as easily for confidential clients, since the code exchange requires authentication with the legitimate client's secret. However, the attacker can use the legitimate confidential client to redeem the code by performing an authorization code injection attack; see Section 4.5.¶
It is important to note that redirection URI validation vulnerabilities can also exist if the authorization
server handles wildcards properly. For example, assume that the client
registers the redirection URL pattern https:// and
the authorization server interprets this as "allow redirection URIs
pointing to any host residing in the domain somesite.example". If an
attacker manages to establish a host or subdomain in
somesite.example, the attacker can impersonate the legitimate client. For example, this
could be caused by a subdomain takeover attack [research.udel], where an
outdated CNAME record (say, external)
points to an external DNS name that no longer exists (say,
customer) and can be taken over by an attacker
(e.g., by registering as customer-abc with the external service).¶
4.1.2. Redirect URI Validation Attacks on Implicit Grant
The attack described above works for the implicit grant as well. If
the attacker is able to send the authorization response to an attacker
Additionally, implicit grants (and also other grants when using response as defined in [OAuth.Responses]) can be subject to a further kind of
attack. The attack utilizes the fact that user agents reattach fragments to
the destination URL of a redirect if the location header does not
contain a fragment (see Section 17.11 of [RFC9110]). The attack
described here combines this behavior with the client as an open
redirector (see Section 4.11.1) in order to obtain access tokens. This allows
circumvention even of very narrow redirection URI patterns, but not of strict URL
matching.¶
Assume the registered URL pattern for client s6BhdRkqt3 is
https://, i.e., any parameter is allowed
for redirects to https://. Unfortunately,
the client exposes an open redirector. This endpoint supports a
parameter redirect_to which takes a target URL and will send the
browser to this URL using an HTTP Location header redirect 303.¶
The attack can now be conducted as follows:¶
To begin, as above, the attacker needs to trick the user into opening
a tampered URL in their browser that launches a page under the
attacker's control, say, https://.¶
Afterwards, the website initiates an authorization request that is
very similar to the one in the attack on the code flow. Different to
above, it utilizes the open redirector by encoding
redirect_to=http into the parameters of the
redirection URI, and it uses the response type token (line breaks for display only):¶
Then, since the redirection URI matches the registered pattern, the authorization server permits the request and sends the resulting access token in a 303 redirect (some response parameters omitted for readability):¶
At clienthttps://.¶
Since the redirector at client#access to
the URL and will navigate to the following URL:¶
The attacker's page at attacker.example can then access the
fragment and obtain the access token.¶
4.1.3. Countermeasures
The complexity of implementing and managing pattern matching correctly obviously
causes security issues. This document therefore advises simplifying the required
logic and configuration by using exact redirection URI matching. This means the
authorization server MUST ensure that the two URIs are equal; see Section 6.2.1 of [RFC3986], Simple String Comparison, for details. The only exception is
native apps using a localhost URI: In this case, the authorization server MUST allow variable
port numbers as described in Section 7.3 of [RFC8252].¶
Additional recommendations
If the origin and integrity of the authorization request containing the redirection URI can be verified, for example, when using [RFC9101] or [RFC9126] with client authentication, the authorization server MAY trust the redirection URI without further checks.¶
4.2. Credential Leakage via Referer Headers
The contents of the authorization request URI or the authorization
response URI can unintentionally be disclosed to attackers through the
Referer HTTP header (see Section 10.1.3 of [RFC9110]), by leaking from either the authorization server's or the client's website, respectively. Most
importantly, authorization codes or state values can be disclosed in
this way. Although specified otherwise in Section 10.1.3 of [RFC9110],
the same may happen to access tokens conveyed in URI fragments due to
browser implementation issues, as illustrated by a (now fixed) issue in the Chromium project [bug.chromium].¶
4.2.1. Leakage from the OAuth Client
Leakage from the OAuth client requires that the client, as a result of a successful authorization request, renders a page that¶
As soon as the browser navigates to the attacker's page or loads the
third-party content, the attacker receives the authorization response
URL and can extract code or state (and potentially access_token).¶
4.2.3. Consequences
An attacker that learns a valid code or access token through a
Referer header can perform the attacks as described in Sections
4.1.1, 4.5 and
4.6. If the attacker learns state, the CSRF
protection achieved by using state is lost, resulting in CSRF
attacks as described in Section 4.4.1.8 of [RFC6819].¶
4.2.4. Countermeasures
The page rendered as a result of the OAuth authorization response and the authorization endpoint SHOULD NOT include third-party resources or links to external sites.¶
The following measures further reduce the chances of a successful attack:¶
4.3. Credential Leakage via Browser History
Authorization codes and access tokens can end up in the browser's history of visited URLs, enabling the attacks described in the following.¶
4.3.2. Access Token in Browser History
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 like
provider. [RFC6750]
discourages this practice and advises transferring tokens via a header,
but in practice websites often pass access tokens in query
parameters.¶
In the case of implicit grant, a URL like
client may also end
up in the browser history as a result of a redirect from a provider's
authorization endpoint.¶
Countermeasures:¶
4.4. Mix-Up Attacks
Mix-up attacks can occur in scenarios where an OAuth client interacts with two or more authorization servers and at least one authorization server is under the control of the attacker. This can be the case, for example, if the attacker uses dynamic registration to register the client at their own authorization server or if an authorization server becomes compromised.¶
The goal of the attack is to obtain an authorization code or an access
token for an uncompromised authorization server. This is achieved by
tricking the client into sending those credentials to the compromised
authorization server (the attacker) instead of using them at the
respective endpoint of the uncompromised authorization
4.4.1. Attack Description
The description here follows [arXiv.1601.01229], with variants of the attack outlined below.¶
Preconditions: For this variant of the attack to work, it is assumed that¶
In the following, it is further assumed that the client is registered with H-AS (URI:
https://, client ID: 7ZGZldHQ) and with A-AS (URI:
https://, client ID: 666RVZJTA). URLs shown in the following
example are shortened for presentation to include only parameters relevant to the
attack.¶
Attack on the authorization code grant:¶
Variants:¶
4.4.2. Countermeasures
When an OAuth client can only interact with one authorization server, a mix-up defense is not required. In scenarios where an OAuth client interacts with two or more authorization servers, however, clients MUST prevent mix-up attacks. Two different methods are discussed below.¶
For both defenses, clients MUST store, for each authorization request, the
issuer they sent the authorization request to and bind this information to the
user agent. The issuer serves, via the associated metadata, as an abstract
identifier for the combination of the authorization endpoint and token endpoint
that are to be used in the flow. If an issuer identifier is not available (for
example, if neither OAuth Authorization Server Metadata [RFC8414] nor OpenID Connect Discovery [OpenID.Discovery] is
used), a different unique identifier for this tuple or the tuple itself can be
used instead. For brevity of presentation, such a deployment
It is important to note that just storing the authorization server URL is not sufficient to identify mix-up attacks. An attacker might declare an uncompromised authorization server's authorization endpoint URL as "their" authorization server URL, but declare a token endpoint under their own control.¶
4.4.2.1. Mix-Up Defense via Issuer Identification
This defense requires that the authorization server sends its issuer identifier in the authorization response to the client. When receiving the authorization response, the client MUST compare the received issuer identifier to the stored issuer identifier. If there is a mismatch, the client MUST abort the interaction.¶
There are different ways this issuer identifier can be transported to the client:¶
In both cases, the iss value MUST be evaluated according to [RFC9207].¶
While this defense may require deploying new OAuth features to transport the issuer information, it is a robust and relatively simple defense against mix-up.¶
4.4.2.2. Mix-Up Defense via Distinct Redirect URIs
For this defense, clients MUST use a distinct redirection URI for each issuer they interact with.¶
Clients MUST check that the authorization response was received from the correct issuer by comparing the distinct redirection URI for the issuer to the URI where the authorization response was received on. If there is a mismatch, the client MUST abort the flow.¶
While this defense builds upon existing OAuth functionality, it cannot be used in scenarios where clients only register once for the use of many different issuers (as in some open banking schemes) and due to the tight integration with the client registration, it is harder to deploy automatically.¶
Furthermore, an attacker might be able to circumvent the protection offered by this defense by registering a new client with the "honest" authorization server using the redirect URI that the client assigned to the attacker's authorization server. The attacker could then run the attack as described above, replacing the client ID with the client ID of their newly created client.¶
This defense SHOULD therefore only be used if other options are not available.¶
4.5. Authorization Code Injection
An attacker who has gained access to an authorization code contained in an authorization response (see Attacker (A3) in Section 3) can try to redeem the authorization code for an access token or otherwise make use of the authorization code.¶
In the case that the authorization code was created for a public client, the attacker can send the authorization code to the token endpoint of the authorization server and thereby get an access token. This attack was described in Section 4.4.1.1 of [RFC6819].¶
For confidential clients, or in some special situations, the attacker can execute an authorization code injection attack, as described in the following.¶
In an authorization code injection attack, the attacker attempts to inject a stolen authorization code into the attacker's own session with the client. The aim is to associate the attacker's session at the client with the victim's resources or identity, thereby giving the attacker at least limited access to the victim's resources.¶
Besides circumventing the client authentication of confidential clients, other use cases for this attack include:¶
Except in these special cases, authorization code injection is usually not interesting when the code is created for a public client, as sending the code to the token endpoint is a simpler and more powerful attack, as described above.¶
4.5.1. Attack Description
The authorization code injection attack works as follows:¶
4.5.2. Discussion
Obviously, the check-in step (Step 5) will fail if the code was issued to another client ID, e.g., a client set up by the attacker. The check will also fail if the authorization code was already redeemed by the legitimate user and was one-time use only.¶
An attempt to inject a code obtained via a manipulated redirection URI
should also be detected if the authorization server stored the
complete redirection URI used in the authorization request and compares
it with the redirect_uri parameter.¶
Section 4.1.3 of [RFC6749] requires the authorization server to¶
ensure that the "redirect_uri" parameter is present if the "redirect_uri" parameter was included in the initial authorization request as described in Section 4.1.1, and if included ensure that their values are identical.¶
In the attack scenario described in Section 4.5.1, the legitimate client would use the correct redirection URI it always uses for authorization requests. But this URI would not match the tampered redirection URI used by the attacker (otherwise, the redirect would not land at the attacker's page). So, the authorization server would detect the attack and refuse to exchange the code.¶
This check could also detect attempts to inject an authorization code that had been obtained from another instance of the same client on another device if certain conditions are fulfilled:¶
But, this approach conflicts with the idea of enforcing exact redirect
URI matching at the authorization endpoint. Moreover, it has been
observed that providers very often ignore the redirect_uri check
requirement at this stage, maybe because it doesn't seem to be
security
Other providers just pattern match the redirect_uri parameter
against the registered redirection URI pattern. This saves the
authorization server from storing the link between the actual redirect
URI and the respective authorization code for every transaction. However,
this kind of check obviously does not fulfill the intent of the
specification, since the tampered redirection URI is not considered. So,
any attempt to inject an authorization code obtained using the
client_id of a legitimate client or by utilizing the legitimate
client on another device will not be detected in the respective
deployments.¶
It is also assumed that the requirements defined in Section 4.1.3 of [RFC6749] increase client implementation complexity as clients need to store or reconstruct the correct redirection URI for the call to the token endpoint.¶
Asymmetric methods for client authentication do not stop this attack, as the legitimate client authenticates at the token endpoint.¶
This document therefore recommends instead binding every authorization code to a certain client instance on a certain device (or in a certain user agent) in the context of a certain transaction using one of the mechanisms described next.¶
4.5.3. Countermeasures
There are two good technical solutions to binding authorization codes to client instances, as follows.¶
4.5.3.1. PKCE
The PKCE mechanism specified in [RFC7636] can be used as a countermeasure
(even though it was originally designed to secure native apps). When the
attacker attempts to inject an authorization code, the check of the
code_verifier fails: the client uses its correct verifier, but the code is
associated with a code_challenge that does not match this verifier.¶
PKCE not only protects against the authorization code injection attack but
also protects authorization codes created for public clients: PKCE ensures that
an attacker cannot redeem a stolen authorization code at the token endpoint of
the authorization server without knowledge of the code_verifier.¶
4.5.3.2. Nonce
OpenID Connect's existing nonce parameter can protect against authorization
code injection attacks. The nonce value is one-time use and is created by the
client. The client is supposed to bind it to the user agent session and send it
with the initial request to the OpenID Provider (OP). The OP puts the received nonce value into the ID Token that is issued
as part of the code exchange at the token endpoint.
If an attacker injects an
authorization code in the authorization response, the nonce value in the client
session and the nonce value in the ID Token received from the token endpoint will not match, and the attack is
detected. The assumption is that an attacker cannot get hold of the user agent
state on the victim's device (from which the attacker has stolen the respective authorization
code).¶
It is important to note that this countermeasure only works if the client
properly checks the nonce parameter in the ID Token obtained from the token endpoint and does not use any
issued token until this check has succeeded. More precisely, a client protecting
itself against code injection using the nonce parameter¶
It is important to note that nonce does not protect authorization codes of
public clients, as an attacker does not need to execute an authorization code
injection attack. Instead, an attacker can directly call the token endpoint with
the stolen authorization code.¶
4.5.3.3. Other Solutions
Other solutions like binding state to the code, sender
PKCE is the most obvious solution for OAuth clients, as it is available
at the time of writing, while nonce is
appropriate for OpenID Connect clients.¶
4.5.4. Limitations
An attacker can circumvent the countermeasures described above if they
can modify the nonce or code_challenge values that are used in the
victim's authorization request. The attacker can modify these values
to be the same ones as those chosen by the client in their own session
in Step 2 of the attack above. (This requires that the victim's
session with the client begins after the attacker started their session
with the client.) If the attacker is then able to capture the
authorization code from the victim, the attacker will be able to
inject the stolen code in Step 3 even if PKCE or nonce are used.¶
This attack is complex and requires a close interaction between the attacker and the victim's session. Nonetheless, measures to prevent attackers from reading the contents of the authorization response still need to be taken, as described in Sections 4.1, 4.2, 4.3, 4.4, and 4.11.¶
4.6. Access Token Injection
In an access token injection attack, the attacker attempts to inject a stolen access token into a legitimate client (that is not under the attacker's control). This will typically happen if the attacker wants to utilize a leaked access token to impersonate a user in a certain client.¶
To conduct the attack, the attacker starts an OAuth flow with the
client using the implicit grant and modifies the authorization
response by replacing the access token issued by the authorization
server or directly making up an authorization server response including
the leaked access token. Since the response includes the state value
generated by the client for this particular transaction, the client
does not treat the response as a CSRF attack and uses the access token
injected by the attacker.¶
4.6.1. Countermeasures
There is no way to detect such an injection attack in pure-OAuth flows since the token is issued without any binding to the transaction or the particular user agent.¶
In OpenID Connect, the attack can be mitigated, as the authorization response
additionally contains an ID Token containing the at_hash claim. The attacker
therefore needs to replace both the access token as well as the ID Token in the
response. The attacker cannot forge the ID Token, as it is signed or encrypted
with authentication. The attacker also cannot inject a leaked ID Token matching
the stolen access token, as the nonce claim in the leaked ID Token will
contain (with a very high probability) a different value than the one expected
in the authorization response.¶
Note that further protection, like sender
The recommendations in Section 2.1.2 follow from this.¶
4.7. Cross-Site Request Forgery
An attacker might attempt to inject a request to the redirection URI of the legitimate client on the victim's device, e.g., to cause the client to access resources under the attacker's control. This is a variant of an attack known as Cross-Site Request Forgery (CSRF).¶
4.7.1. Countermeasures
The longstate parameter that links the request to
the redirection URI to the user agent session as described. This
countermeasure is described in detail in Section 5.3.5 of [RFC6819]. The
same protection is provided by PKCE or the OpenID Connect nonce value.¶
When using PKCE instead of state or nonce for CSRF protection, it is
important to note that:¶
The authorization server therefore MUST provide a way to detect their support for PKCE. Using Authorization Server Metadata according to [RFC8414] is RECOMMENDED, but authorization servers MAY instead provide a
deployment
PKCE provides robust protection against CSRF attacks even in the presence of an attacker that
can read the authorization response (see Attacker (A3) in Section 3). When
state is used or an ID Token is returned in the authorization response (e.g.,
response), the attacker either learns the state value and
can replay it into the forged authorization response, or can extract the nonce
from the ID Token and use it in a new request to the authorization server to
mint an ID Token with the same nonce. The new ID Token can then be used for
the CSRF attack.¶
4.8. PKCE Downgrade Attack
An authorization server that supports PKCE but does not make its use mandatory for all flows can be susceptible to a PKCE downgrade attack.¶
The first prerequisite for this attack is that there is an attackercode_challenge parameter lends
itself for this purpose, i.e., the authorization server enables and enforces PKCE if this
parameter is present in the authorization request, but it does not enforce PKCE if
the parameter is missing.¶
The second prerequisite for this attack is that the client is not using state
at all (e.g., because the client relies on PKCE for CSRF prevention) or that the
client is not checking state correctly.¶
Roughly speaking, this attack is a variant of a CSRF attack. The attacker achieves the same goal as in the attack described in Section 4.7: The attacker injects an authorization code (and with that, an access token) that is bound to the attacker's resources into a session between their victim and the client.¶
4.8.2. Countermeasures
Using state properly would prevent this attack. However, practice has shown
that many OAuth clients do not use or check state properly.¶
Therefore, authorization servers MUST mitigate this attack.¶
Note that from the view of the authorization server, in the attack described above, a
code_verifier parameter is received at the token endpoint although no
code_challenge parameter was present in the authorization request for the
OAuth flow in which the authorization code was issued.¶
This fact can be used to mitigate this attack. [RFC7636] already mandates that¶
Beyond this, to prevent PKCE downgrade attacks, the authorization server MUST ensure that
if there was no code_challenge in the authorization request, a request to
the token endpoint containing a code_verifier is rejected.¶
Authorization servers that mandate the use of PKCE (in general or for particular clients) implicitly implement this security measure.¶
4.9. Access Token Leakage at the Resource Server
Access tokens can leak from a resource server under certain circumstances.¶
4.9.1. Access Token Phishing by Counterfeit Resource Server
An attacker may set up their own resource server and trick a client into sending access tokens to it that are valid for other resource servers (see Attackers (A1) and (A5) in Section 3). If the client sends a valid access token to this counterfeit resource server, the attacker in turn may use that token to access other services on behalf of the resource owner.¶
This attack assumes the client is not bound to one specific resource server (and its URL) at development time, but client instances are provided with the resource server URL at runtime. This kind of late binding is typical in situations where the client uses a service implementing a standardized API (e.g., for email, calendaring, eHealth, or open banking) and where the client is configured by a user or administrator.¶
4.9.2. Compromised Resource Server
An attacker may compromise a resource server to gain access to the resources of the respective deployment. Such a compromise may range from partial access to the system, e.g., its log files, to full control over the respective server, in which case all controls can be circumvented and all resources can be accessed. The attacker would also be able to obtain other access tokens held on the compromised system that would potentially be valid to access other resource servers.¶
Preventing server breaches by hardening and monitoring server systems is considered a standard operational procedure and, therefore, out of the scope of this document. Section 4.9 focuses on the impact of OAuth-related breaches and the replaying of captured access tokens.¶
4.9.3. Countermeasures
The following measures should be taken into account by implementers in order to cope with access token replay by malicious actors:¶
The first and second recommendations also apply to other scenarios where access tokens leak (see Attacker (A5) in Section 3).¶
4.10. Misuse of Stolen Access Tokens
Access tokens can be stolen by an attacker in various ways, for example,
via the attacks described in Sections 4.1,
4.2, 4.3, 4.4, and
4.9. Some of these attacks can be mitigated by
specific security measures, as described in the respective sections.
However, in some cases, these measures are not sufficient or are not
implemented correctly. Authorization servers therefore SHOULD ensure that
access tokens are sender
4.10.1. Sender-Constrained Access Tokens
As the name suggests, sender
A typical flow looks like this:¶
Two methods for sender
Note that the security of sender
4.10.2. Audience-Restricted Access Tokens
Audience restriction essentially restricts access tokens to a particular resource server. The authorization server associates the access token with the particular resource server, and the resource server is then supposed to verify the intended audience. If the access token fails the intended audience validation, the resource server refuses to serve the respective request.¶
In general, audience restriction limits the impact of token leakage. In the case of a counterfeit resource server, it may (as described below) also prevent abuse of the phished access token at the legitimate resource server.¶
The audience can be expressed using logical names or physical addresses (like URLs). To prevent phishing, it is necessary to use the actual URL the client will send requests to. In the phishing case, this URL will point to the counterfeit resource server. If the attacker tries to use the access token at the legitimate resource server (which has a different URL), the resource server will detect the mismatch (wrong audience) and refuse to serve the request.¶
In deployments where the authorization server knows the URLs of all resource servers, the authorization server may just refuse to issue access tokens for unknown resource server URLs.¶
For this to work, the client needs to tell the authorization server the intended resource server. The mechanism in [RFC8707] can be used for this or the information can be encoded in the scope value (Section 3.3 of [RFC6749]).¶
Instead of the URL, it is also possible to utilize the fingerprint of the resource server's X.509 certificate as the audience value. This variant would also allow detection of an attempt to spoof the legitimate resource server's URL by using a valid TLS certificate obtained from a different CA. It might also be considered a privacy benefit to hide the resource server URL from the authorization server.¶
Audience restriction may seem easier to use since it does not require any cryptography on the client side. Still, since every access token is bound to a specific resource server, the client also needs to obtain a single resource server-specific access token when accessing several resource servers. (Resource indicators, as specified in [RFC8707], can help to achieve this.) [TOKEN-BINDING] had the same property since different token-binding IDs must be associated with the access token. Using mutual TLS for OAuth 2.0 [RFC8705], on the other hand, allows a client to use the access token at multiple resource servers.¶
It should be noted that audience restrictions -- or, generally speaking, an indication by the client to the authorization server where it wants to use the access token -- have additional benefits beyond the scope of token leakage prevention. They allow the authorization server to create a different access token whose format and content are specifically minted for the respective server. This has huge functional and privacy advantages in deployments using structured access tokens.¶
4.10.3. Discussion: Preventing Leakage via Metadata
An authorization server could provide the client with additional information about the locations where it is safe to use its access tokens. This approach, and why it is not recommended, is discussed in the following.¶
In the simplest form, this would require the authorization server to publish a list of
its known resource servers, illustrated in the following example using
a non-standard Authorization Server Metadata parameter resource_servers:¶
The authorization server could also return the url(/Education?url=https%3A%2F%2Fwww.rfc-editor.org%2Finfo%2Frfc9700%2Fs) an access token is good for in the
token response, illustrated by the example and non-standard return
parameter access:¶
This mitigation strategy would rely on the client to enforce the
security policy and to only send access tokens to legitimate
destinations. Results of OAuth-related security research (see, for
example, [research.ubc] and [research.cmu]) indicate a
large portion of client implementations do not or fail to properly
implement security controls, like state checks. So, relying on
clients to prevent access token phishing is likely to fail as well.
Moreover, given the ratio of clients to authorization and resource servers,
it is considered the more viable approach to move as much as possible
security
4.11. Open Redirection
The following attacks can occur when an authorization server or client has an open redirector. Such endpoints are sometimes implemented, for example, to show a message before a user is then redirected to an external website, or to redirect users back to a URL they were intending to visit before being interrupted, e.g., by a login prompt.¶
4.11.1. Client as Open Redirector
Clients MUST NOT expose open redirectors. Attackers may use open redirectors to produce URLs pointing to the client and utilize them to exfiltrate authorization codes and access tokens, as described in Section 4.1.2. Another abuse case is to produce URLs that appear to point to the client. This might trick users into trusting the URL and following it in their browser. This can be abused for phishing.¶
In order to prevent open redirection, clients should only redirect if the target URLs are allowed or if the origin and integrity of a request can be authenticated. Countermeasures against open redirection are described by OWASP [owasp.redir].¶
4.12. 307 Redirect
At the authorization endpoint, a typical protocol flow is that the authorization server prompts the user to enter their credentials in a form that is then submitted (using the HTTP POST method) back to the authorization server. The authorization server checks the credentials and, if successful, redirects the user agent to the client's redirection endpoint.¶
In [RFC6749], the HTTP status code 302 (Found) is used for this purpose, but "any other method available via the user-agent to accomplish this redirection is allowed". When the status code 307 is used for redirection instead, the user agent will send the user's credentials via HTTP POST to the client.¶
This discloses the sensitive credentials to the client. If the client is malicious, it can use the credentials to impersonate the user at the authorization server.¶
The behavior might be unexpected for developers but is defined in Section 15.4.8 of [RFC9110]. This status code (307) does not require the user agent to rewrite the POST request to a GET request and thereby drop the form data in the POST request body.¶
In the HTTP standard [RFC9110], only the status code 303 unambiguously enforces rewriting the HTTP POST request to an HTTP GET request. For all other status codes, including the popular 302, user agents can opt not to rewrite POST to GET requests, thereby causing the user's credentials to be revealed to the client. (In practice, however, most user agents will only show this behavior for 307 redirects.)¶
Authorization servers that redirect a request that potentially contains the user's credentials therefore MUST NOT use the HTTP 307 status code for redirection. If an HTTP redirection (and not, for example, JavaScript) is used for such a request, the authorization server SHOULD use HTTP status code 303 (See Other).¶
4.13. TLS Terminating Reverse Proxies
A common deployment architecture for HTTP applications is to hide the application server behind a reverse proxy that terminates the TLS connection and dispatches the incoming requests to the respective application server nodes.¶
This section highlights some attack angles of this deployment architecture with relevance to OAuth and gives recommendations for security controls.¶
In some situations, the reverse proxy needs to pass security
If the reverse proxy passes through any header sent from the
outside, an attacker could try to directly send the faked header
values through the proxy to the application server in order to
circumvent security controls that way. For example, it is standard
practice of reverse proxies to accept X-Forwarded-For headers and just
add the origin of the inbound request (making it a list). Depending on
the logic performed in the application server, the attacker could
simply add an allowed IP address to the header and render the protection useless.¶
A reverse proxy MUST therefore sanitize any inbound requests to ensure the authenticity and integrity of all header values relevant for the security of the application servers.¶
If an attacker were able to get access to the internal network between the proxy and application server, the attacker could also try to circumvent security controls in place. Therefore, it is essential to ensure the authenticity of the communicating entities. Furthermore, the communication link between the reverse proxy and application server MUST be protected against eavesdropping, injection, and replay of messages.¶
4.14. Refresh Token Protection
Refresh tokens are a convenient and user-friendly way to obtain new access tokens. They also add to the security of OAuth, since they allow the authorization server to issue access tokens with a short lifetime and reduced scope, thus reducing the potential impact of access token leakage.¶
4.14.1. Discussion
Refresh tokens are an attractive target for attackers because they represent the full scope of access granted to a certain client, and they are not further constrained to a specific resource. If an attacker is able to exfiltrate and successfully replay a refresh token, the attacker will be able to mint access tokens and use them to access resource servers on behalf of the resource owner.¶
[RFC6749] already provides robust baseline protection by requiring¶
[RFC6749] also lays the foundation for further
This specification gives recommendations beyond the scope of [RFC6749] and clarifications.¶
4.14.2. Recommendations
Authorization servers MUST determine, based on a risk assessment, whether to issue refresh tokens to a certain client. If the authorization server decides not to issue refresh tokens, the client MAY obtain a new access token by utilizing other grant types, such as the authorization code grant type. In such a case, the authorization server may utilize cookies and persistent grants to optimize the user experience.¶
If refresh tokens are issued, those refresh tokens MUST be bound to the scope and resource servers as consented by the resource owner. This is to prevent privilege escalation by the legitimate client and reduce the impact of refresh token leakage.¶
For confidential clients, [RFC6749] already requires that refresh tokens can only be used by the client for which they were issued.¶
Authorization servers MUST utilize one of these methods to detect refresh token replay by malicious actors for public clients:¶
Authorization servers MAY revoke refresh tokens automatically in case of a security event, such as:¶
Refresh tokens SHOULD expire if the client has been inactive for some time, i.e., the refresh token has not been used to obtain fresh access tokens for some time. The expiration time is at the discretion of the authorization server. It might be a global value or determined based on the client policy or the grant associated with the refresh token (and its sensitivity).¶
4.15. Client Impersonating Resource Owner
Resource servers may make access control decisions based on the identity of a
resource owner for which an access token was issued, or based on the identity of
a client in the client credentials grant. For example, [RFC9068] (JSON Web
Token (JWT) Profile for OAuth 2.0 Access Tokens) describes a data structure for
access tokens containing a sub claim defined as follows:¶
In cases of access tokens obtained through grants where a resource owner is involved, such as the authorization code grant, the value of "sub" SHOULD correspond to the subject identifier of the resource owner. In cases of access tokens obtained through grants where no resource owner is involved, such as the client credentials grant, the value of "sub" SHOULD correspond to an identifier the authorization server uses to indicate the client application.¶
If both options are possible, a resource server may mistake a client's identity
for the identity of a resource owner. For example, if a client is able to choose
its own client_id during registration with the authorization server, a
malicious client may set it to a value identifying a resource owner (e.g., a
sub value if OpenID Connect is used). If the resource server cannot properly
distinguish between access tokens obtained with involvement of the resource
owner and those without, the client may accidentally be able to access resources
belonging to the resource owner.¶
This attack potentially affects not only implementations using [RFC9068], but also similar, bespoke solutions.¶
4.15.1. Countermeasures
Authorization servers SHOULD NOT allow clients to influence their client_id or
any other claim that could cause confusion with a genuine resource owner if a common
namespace for client IDs and user identifiers exists, such as in the sub claim
example from [RFC9068] shown in Section 4.15 above. Where this cannot be avoided, authorization servers MUST provide
other means for the resource server to distinguish between the two types of
access tokens.¶
4.16. Clickjacking
As described in Section 4.4.1.9 of [RFC6819], the authorization request is
susceptible to clickjacking attacks, also called user interface redressing. In
such an attack, an attacker embeds the authorization endpoint user interface in
an innocuous context. A user believing to interact with that context, for
example, by clicking on buttons, inadvertently interacts with the authorization
endpoint user interface instead. The opposite can be achieved as well: A user
believing to interact with the authorization endpoint might inadvertently type a
password into an attacker
An attacker can use this vector to obtain the user's authentication credentials, change the scope of access granted to the client, and potentially access the user's resources.¶
Authorization servers MUST prevent clickjacking attacks. Multiple countermeasures are described in [RFC6819], including the use of the X-Frame-Options HTTP response header field and frame-busting JavaScript. In addition to those, authorization servers SHOULD also use Content Security Policy (CSP) level 2 [W3C.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 and authorize the client (e.g., the device authorization endpoint, login pages, error pages, etc.). This prevents framing by unauthorized origins in user agents that support CSP. The client MAY permit being framed by some other origin than the one used in its redirection endpoint. For this reason, authorization servers SHOULD allow administrators to configure allowed origins for particular clients and/or for clients to register these dynamically.¶
Using CSP allows authorization servers to specify multiple origins in
a single response header field and to constrain these using flexible
patterns (see [W3C.CSP-2] for details). Level 2 of CSP provides
a robust mechanism for protecting against clickjacking by using
policies that restrict the origin of frames (by using frame-ancestors)
together with those that restrict the sources of scripts allowed to
execute on an HTML page (by using script-src). A non-normative
example of such a policy is shown in the following listing:¶
Because some user agents do not support [W3C.CSP-2], this technique SHOULD be combined with others, including those described in [RFC6819], unless such legacy user agents are explicitly unsupported by the authorization server. Even in such cases, additional countermeasures SHOULD still be employed.¶
4.17. Attacks on In-Browser Communication Flows
If the authorization response is sent with in-browser communication techniques
like postMessage [WHATWG
4.17.1. Examples
The following non-normative pseudocode examples of attacks using in-browser communication are described in [research.rub].¶
4.17.1.1. Insufficient Limitation of Receiver Origins
When sending the authorization response or token response via postMessage, the authorization server sends the response to the wildcard origin "*" instead of the client's origin. When the window to which the response is sent is controlled by an attacker, the attacker can read the response.¶
4.17.1.2. Insufficient URI Validation
When sending the authorization response or token response via postMessage, the authorization server may not check the receiver origin against the redirection URI and instead, for example, may send the response to an origin provided by an attacker. This is analogous to the attack described in Section 4.1.¶
4.17.1.3. Injection after Insufficient Validation of Sender Origin
A client that expects the authorization response or token response via postMessage may not validate the sender origin of the message. This may allow an attacker to inject an authorization response or token response into the client.¶
In the case of a maliciously injected authorization response, the attack is a variant of the CSRF attacks described in Section 4.7. The countermeasures described in Section 4.7 apply to this attack as well.¶
In the case of a maliciously injected token response, sender
4.17.2. Recommendations
When comparing client receiver origins against pre-registered origins, authorization servers MUST utilize exact string matching as described in Section 4.1.3. Authorization servers MUST send postMessages to trusted client receiver origins, as shown in the following, non-normative example:¶
Wildcard origins like "*" in postMessage MUST NOT be used, as attackers can use them to leak a victim's in-browser message to malicious origins. Both measures contribute to the prevention of leakage of authorization codes and access tokens (see Section 4.1).¶
Clients MUST prevent injection of in-browser messages on the client receiver endpoint. Clients MUST utilize exact string matching to compare the initiator origin of an in-browser message with the authorization server origin, as shown in the following, non-normative example:¶
Since in-browser communication flows only apply a different communication technique (i.e., postMessage instead of HTTP redirect), all measures protecting the authorization response listed in Section 2.1 MUST be applied equally.¶
5. IANA Considerations
This document has no IANA actions.¶
7. References
7.1. Normative References
- [BCP195]
-
Best Current Practice 195, <https://
www >..rfc -editor .org /info /bcp195
At the time of writing, this BCP comprises the following:Moriarty, K. and S. Farrell, "Deprecating TLS 1.0 and TLS 1.1", BCP 195, RFC 8996, DOI 10.17487 , , <https:///RFC8996 www >..rfc -editor .org /info /rfc8996 Sheffer, Y., Saint-Andre, P., and T. Fossati, "Recommendations for Secure Use of Transport Layer Security (TLS) and Datagram Transport Layer Security (DTLS)", BCP 195, RFC 9325, DOI 10.17487 , , <https:///RFC9325 www >..rfc -editor .org /info /rfc9325 - [RFC3986]
-
Berners-Lee, T., Fielding, R., and L. Masinter, "Uniform Resource Identifier (URI): Generic Syntax", STD 66, RFC 3986, DOI 10
.17487 , , <https:///RFC3986 www >..rfc -editor .org /info /rfc3986 - [RFC6749]
-
Hardt, D., Ed., "The OAuth 2.0 Authorization Framework", RFC 6749, DOI 10
.17487 , , <https:///RFC6749 www >..rfc -editor .org /info /rfc6749 - [RFC6750]
-
Jones, M. and D. Hardt, "The OAuth 2.0 Authorization Framework: Bearer Token Usage", RFC 6750, DOI 10
.17487 , , <https:///RFC6750 www >..rfc -editor .org /info /rfc6750 - [RFC6819]
-
Lodderstedt, T., Ed., McGloin, M., and P. Hunt, "OAuth 2.0 Threat Model and Security Considerations", RFC 6819, DOI 10
.17487 , , <https:///RFC6819 www >..rfc -editor .org /info /rfc6819 - [RFC7521]
-
Campbell, B., Mortimore, C., Jones, M., and Y. Goland, "Assertion Framework for OAuth 2.0 Client Authentication and Authorization Grants", RFC 7521, DOI 10
.17487 , , <https:///RFC7521 www >..rfc -editor .org /info /rfc7521 - [RFC7523]
-
Jones, M., Campbell, B., and C. Mortimore, "JSON Web Token (JWT) Profile for OAuth 2.0 Client Authentication and Authorization Grants", RFC 7523, DOI 10
.17487 , , <https:///RFC7523 www >..rfc -editor .org /info /rfc7523 - [RFC8252]
-
Denniss, W. and J. Bradley, "OAuth 2.0 for Native Apps", BCP 212, RFC 8252, DOI 10
.17487 , , <https:///RFC8252 www >..rfc -editor .org /info /rfc8252 - [RFC8414]
-
Jones, M., Sakimura, N., and J. Bradley, "OAuth 2.0 Authorization Server Metadata", RFC 8414, DOI 10
.17487 , , <https:///RFC8414 www >..rfc -editor .org /info /rfc8414 - [RFC8705]
-
Campbell, B., Bradley, J., Sakimura, N., and T. Lodderstedt, "OAuth 2.0 Mutual-TLS Client Authentication and Certificate
-Bound , RFC 8705, DOI 10Access Tokens" .17487 , , <https:///RFC8705 www >..rfc -editor .org /info /rfc8705 - [RFC9068]
-
Bertocci, V., "JSON Web Token (JWT) Profile for OAuth 2.0 Access Tokens", RFC 9068, DOI 10
.17487 , , <https:///RFC9068 www >..rfc -editor .org /info /rfc9068
7.2. Informative References
- [ar
Xiv .1508 .04324v2] -
Mladenov, V., Mainka, C., and J. Schwenk, "On the security of modern Single Sign-On Protocols: Second-Order Vulnerabilities in OpenID Connect", ar
Xiv , DOI 10:1508 .04324v2 .48550 , , <https:///ar Xiv .1508 .04324 arxiv >..org /abs /1508 .04324v2 / - [ar
Xiv .1601 .01229] -
Fett, D., Küsters, R., and G. Schmitz, "A Comprehensive Formal Security Analysis of OAuth 2.0", arXiv:1601.01229, DOI 10
.48550 , , <https:///ar Xiv .1601 .01229 arxiv >..org /abs /1601 .01229 / - [ar
Xiv .1704 .08539] -
Fett, D., Küsters, R., and G. Schmitz, "The Web SSO Standard OpenID Connect: In-Depth Formal Security Analysis and Security Guidelines", arXiv:1704.08539, DOI 10
.48550 , , <https:///ar Xiv .1704 .08539 arxiv >..org /abs /1704 .08539 / - [ar
Xiv .1901 .11520] -
Fett, D., Hosseyni, P., and R. Küsters, "An Extensive Formal Security Analysis of the OpenID Financial-grade API", arXiv:1901.11520, DOI 10
.48550 , , <https:///ar Xiv .1901 .11520 arxiv >..org /abs /1901 .11520 / - [bug.chromium]
-
"Referer header includes URL fragment when opening link using New Tab", Chromium Issue Tracker, Issue ID: 40076763, <https://
issues >..chromium .org /issues /40076763 - [JWT
-ENCODED -STATE] -
Bradley, J., Lodderstedt, T., and H. Zandbelt, "Encoding claims in the OAuth 2 state parameter using a JWT", Work in Progress, Internet-Draft, draft
-bradley , , <https://-oauth -jwt -encoded -state -09 datatracker >..ietf .org /doc /html /draft -bradley -oauth -jwt -encoded -state -09 - [OAUTH-V2.1]
-
Hardt, D., Parecki, A., and T. Lodderstedt, "The OAuth 2.1 Authorization Framework", Work in Progress, Internet-Draft, draft
-ietf , , <https://-oauth -v2 -1 -12 datatracker >..ietf .org /doc /html /draft -ietf -oauth -v2 -1 -12 - [OAuth.Post]
-
Jones, M. and B. Campbell, "OAuth 2.0 Form Post Response Mode", The OpenID Foundation, , <https://
openid >..net /specs /oauth -v2 -form -post -response -mode -1 _0 .html - [OAuth
.Responses] -
de Medeiros, B., Ed., Scurtescu, M., Tarjan, P., and M. Jones, "OAuth 2.0 Multiple Response Type Encoding Practices", The OpenID Foundation, , <https://
openid >..net /specs /oauth -v2 -multiple -response -types -1 _0 .html - [OpenID.Core]
-
Sakimura, N., Bradley, J., Jones, M., de Medeiros, B., and C. Mortimore, "OpenID Connect Core 1.0 incorporating errata set 2", The OpenID Foundation, , <https://
openid >..net /specs /openid -connect -core -1 _0 .html - [Open
ID .Discovery] -
Sakimura, N., Bradley, J., Jones, M., and E. Jay, "OpenID Connect Discovery 1.0 incorporating errata set 2", The OpenID Foundation, , <https://
openid >..net /specs /openid -connect -discovery -1 _0 .html - [OpenID.JARM]
-
Lodderstedt, T. and B. Campbell, "Financial-grade API: JWT Secured Authorization Response Mode for OAuth 2.0 (JARM)", The OpenID Foundation, , <https://
openid >..net /specs /openid -financial -api -jarm .html - [owasp.redir]
-
OWASP Foundation, "Unvalidated Redirects and Forwards Cheat Sheet", OWASP Cheat Sheet Series, <https://
cheatsheetseries >..owasp .org /cheatsheets /Unvalidated _Redirects _and _Forwards _Cheat _Sheet .html - [research.cmu]
-
Chen, E., Pei, Y., Chen, S., Tian, Y., Kotcher, R., and P. Tague, "OAuth Demystified for Mobile Application Developers", CCS '14: Proceedings of the 2014 ACM SIGSAC Conference on Computer and Communications Security, pp. 892-903, DOI 10
.1145 , , <https:///2660267 .2660323 www >..microsoft .com /en -us /research /wp -content /uploads /2016 /02 /OAuth Demystified .pdf - [research
.jcs _14] -
Bansal, C., Bhargavan, K., Delignat-Lavaud, A., and S. Maffeis, "Discovering concrete attacks on website authorization by formal analysis", Journal of Computer Security, vol. 22, no. 4, pp. 601-657, DOI 10
.3233 , , <https:///JCS -140503 www >..doc .ic .ac .uk /~maffeis /papers /jcs14 .pdf - [research.rub]
-
Jannett, L., Mladenov, V., Mainka, C., and J. Schwenk, "DISTINCT: Identity Theft using In-Browser Communications in Dual-Window Single Sign-On", CCS '22: Proceedings of the 2022 ACM SIGSAC Conference on Computer and Communications Security, DOI 10
.1145 , , <https:///3548606 .3560692 dl >..acm .org /doi /pdf /10 .1145 /3548606 .3560692 - [research.rub2]
-
Fries, C., "Security Analysis of Real-Life OpenID Connect Implementations
" , Master's thesis, Ruhr-Universität , , <https://Bochum (RUB) www >..nds .rub .de /media /ei /arbeiten /2021 /05 /03 /masterthesis .pdf - [research.ubc]
-
Sun, S.-T. and K. Beznosov, "The Devil is in the
(Implementation , Proceedings of the 2012 ACM conference on Computer and communications security (CCS '12), pp. 378-390, DOI 10) Details: An Empirical Analysis of OAuth SSO Systems" .1145 , , <https:///2382196 .2382238 css >..csail .mit .edu /6 .858 /2012 /readings /oauth -sso .pdf - [research.udel]
-
Liu, D., Hao, S., and H. Wang, "All Your DNS Records Point to Us: Understanding the Security Threats of Dangling DNS Records", CCS '16: Proceedings of the 2016 ACM SIGSAC Conference on Computer and Communications Security, pp. 1414-1425, DOI 10
.1145 , , <https:///2976749 .2978387 dl >..acm .org /doi /pdf /10 .1145 /2976749 .2978387 - [RFC2119]
-
Bradner, S., "Key words for use in RFCs to Indicate Requirement Levels", BCP 14, RFC 2119, DOI 10
.17487 , , <https:///RFC2119 www >..rfc -editor .org /info /rfc2119 - [RFC7591]
-
Richer, J., Ed., Jones, M., Bradley, J., Machulak, M., and P. Hunt, "OAuth 2.0 Dynamic Client Registration Protocol", RFC 7591, DOI 10
.17487 , , <https:///RFC7591 www >..rfc -editor .org /info /rfc7591 - [RFC7636]
-
Sakimura, N., Ed., Bradley, J., and N. Agarwal, "Proof Key for Code Exchange by OAuth Public Clients", RFC 7636, DOI 10
.17487 , , <https:///RFC7636 www >..rfc -editor .org /info /rfc7636 - [RFC8174]
-
Leiba, B., "Ambiguity of Uppercase vs Lowercase in RFC 2119 Key Words", BCP 14, RFC 8174, DOI 10
.17487 , , <https:///RFC8174 www >..rfc -editor .org /info /rfc8174 - [RFC8707]
-
Campbell, B., Bradley, J., and H. Tschofenig, "Resource Indicators for OAuth 2.0", RFC 8707, DOI 10
.17487 , , <https:///RFC8707 www >..rfc -editor .org /info /rfc8707 - [RFC9101]
-
Sakimura, N., Bradley, J., and M. Jones, "The OAuth 2.0 Authorization Framework: JWT-Secured Authorization Request (JAR)", RFC 9101, DOI 10
.17487 , , <https:///RFC9101 www >..rfc -editor .org /info /rfc9101 - [RFC9110]
-
Fielding, R., Ed., Nottingham, M., Ed., and J. Reschke, Ed., "HTTP Semantics", STD 97, RFC 9110, DOI 10
.17487 , , <https:///RFC9110 www >..rfc -editor .org /info /rfc9110 - [RFC9126]
-
Lodderstedt, T., Campbell, B., Sakimura, N., Tonge, D., and F. Skokan, "OAuth 2.0 Pushed Authorization Requests", RFC 9126, DOI 10
.17487 , , <https:///RFC9126 www >..rfc -editor .org /info /rfc9126 - [RFC9207]
-
Meyer zu Selhausen, K. and D. Fett, "OAuth 2.0 Authorization Server Issuer Identification", RFC 9207, DOI 10
.17487 , , <https:///RFC9207 www >..rfc -editor .org /info /rfc9207 - [RFC9396]
-
Lodderstedt, T., Richer, J., and B. Campbell, "OAuth 2.0 Rich Authorization Requests", RFC 9396, DOI 10
.17487 , , <https:///RFC9396 www >..rfc -editor .org /info /rfc9396 - [RFC9440]
-
Campbell, B. and M. Bishop, "Client-Cert HTTP Header Field", RFC 9440, DOI 10
.17487 , , <https:///RFC9440 www >..rfc -editor .org /info /rfc9440 - [RFC9449]
-
Fett, D., Campbell, B., Bradley, J., Lodderstedt, T., Jones, M., and D. Waite, "OAuth 2.0 Demonstrating Proof of Possession (DPoP)", RFC 9449, DOI 10
.17487 , , <https:///RFC9449 www >..rfc -editor .org /info /rfc9449 - [TOKEN-BINDING]
-
Jones, M., Campbell, B., Bradley, J., and W. Denniss, "OAuth 2.0 Token Binding", Work in Progress, Internet-Draft, draft
-ietf , , <https://-oauth -token -binding -08 datatracker >..ietf .org /doc /html /draft -ietf -oauth -token -binding -08 - [W3C.CSP-2]
-
West, M., Barth, A., and D. Veditz, "Content Security Policy Level 2", W3C Recommendation, , <https://
www >. Latest version available at <https://.w3 .org /TR /2016 /REC -CSP2 -20161215 / www >..w3 .org /TR /CSP2 / - [W3C
.webappsec -referrer -policy] -
Eisinger, J. and E. Stark, "Referrer Policy", , <https://
www >. Latest version available at <https://.w3 .org /TR /2017 /CR -referrer -policy -20170126 / www >..w3 .org /TR /referrer -policy / - [W3C.WebAuthn]
-
Hodges, J., Jones, J.C., Jones, M.B., Kumar, A., and E. Lundberg, "Web Authentication: An API for accessing Public Key Credentials Level 2", W3C Recommendation, , <https://
www >. Latest version available at <https://.w3 .org /TR /2021 /REC -webauthn -2 -20210408 / www >..w3 .org /TR /webauthn -2 / - [W3C.WebCrypto]
-
Watson, M., Ed., "Web Cryptography API", W3C Recommendation, , <https://
www >. Latest version available at <https://.w3 .org /TR /2017 /REC -Web Crypto API -20170126 / www >..w3 .org /TR /Web Crypto API / - [WHATWG.CORS]
-
WHATWG, "CORS protocol", Fetch: Living Standard, Section 3.2, , <https://
fetch >..spec .whatwg .org /#http -cors -protocol - [WHATWG
.postmessage _api] -
WHATWG, "Cross-document messaging", HTML: Living Standard, Section 9.3, , <https://
html >..spec .whatwg .org /multipage /web -messaging .html#web -messaging
Acknowledgements
We would like to thank Brock Allen, Annabelle Richard Backman, Dominick Baier, Vittorio Bertocci, Brian Campbell, Bruno Crispo, William Dennis, George Fletcher, Matteo Golinelli, Dick Hardt, Joseph Heenan, Pedram Hosseyni, Phil Hunt, Tommaso Innocenti, Louis Jannett, Jared Jennings, Michael B. Jones, Engin Kirda, Konstantin Lapine, Neil Madden, Christian Mainka, Jim Manico, Nov Matake, Doug McDorman, Karsten Meyer zu Selhausen, Ali Mirheidari, Vladislav Mladenov, Kaan Onarioglu, Aaron Parecki, Michael Peck, Johan Peeters, Nat Sakimura, Guido Schmitz, Jörg Schwenk, Rifaat Shekh-Yusef, Travis Spencer, Petteri Stenius, Tomek Stojecki, David Waite, Tim Würtele, and Hans Zandbelt for their valuable feedback.¶