- Home
- RFC 9700
RFC 9700: BCP 240: Best Current Practice for OAuth 2.0 Security
- T. Lodderstedt,
- J. Bradley,
- A. Labunets,
- D. Fett
3 subscribed
Added to 4 Sets
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
-
OAuth implementations are being attacked through known implementation weaknesses and anti-patterns (i.e., well-known patterns that are considered insecure). Although most of these threats are discussed in the OAuth 2.0 Threat Model and Security Considerations [RFC6819], continued exploitation demonstrates a need for more specific recommendations, easier to implement mitigations, and more defense in depth.¶
-
OAuth is being used in environments with higher security requirements than considered initially, such as open banking, eHealth, eGovernment, and electronic signatures. Those use cases call for stricter guidelines and additional protection.¶
-
OAuth is being used in much more dynamic setups than originally anticipated, creating new challenges with respect to security. Those challenges go beyond the original scope of [RFC6749], [RFC6750], and [RFC6819].¶
OAuth initially assumed static relationships between clients, authorization servers, and resource servers. The URLs of the servers were known to the client at deployment time and built an anchor for the trust relationships among those parties. The validation of whether the client is talking to a legitimate server was based on TLS server authentication (see Section 4.5.4 of [RFC6819]). With the increasing adoption of OAuth, this simple model dissolved and, in several scenarios, was replaced by a dynamic establishment of the relationship between clients on one side and the authorization and resource servers of a particular deployment on the other side. This way, the same client could be used to access services of different providers (in case of standard APIs, such as email or OpenID Connect) or serve as a front end to a particular tenant in a multi-tenant environment. Extensions of OAuth, such as the OAuth 2.0 Dynamic Client Registration Protocol [RFC7591] and OAuth 2.0 Authorization Server Metadata [RFC8414] were developed to support the use of OAuth in dynamic scenarios.¶
-
Technology has changed. For example, the way browsers treat fragments when redirecting requests has changed, and with it, the implicit grant's underlying security model.¶
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
Naturally, not all existing ecosystems and implementations are compatible with the new requirements, and following the best practices described in this document may break interoperability. Nonetheless, it is RECOMMENDED that implementers upgrade their implementations and ecosystems as soon as feasible.¶
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¶
- use the
issparameter as a countermeasure according to [RFC9207], or¶ - use an alternative countermeasure based on an
issvalue in the authorization response (such as theissclaim in the ID Token in [OpenID.Core ] or in [OpenID.JARM ] responses), processing that value as described in [RFC9207].¶
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:¶
- Public clients MUST use PKCE [RFC7636] to this end, as motivated in Section 4.5.3.1.¶
- For confidential clients, the use of PKCE [RFC7636] is RECOMMENDED, as it provides strong protection against misuse and injection of authorization codes as described in Section 4.5.3.1. Also, as a side effect, it prevents CSRF even in the presence of strong attackers as described in Section 4.7.1.¶
- With additional precautions, described in Section 4.5.3.2,
confidential OpenID Connect [OpenID
.Core ] clients MAY use thenonceparameter and the respective Claim in the ID Token instead.¶
In any case, the PKCE challenge or OpenID Connect nonce MUST be
transaction-nonce.¶
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_ parameter in the
authorization request, the authorization server MUST enforce the correct usage
of code_ at the token endpoint.¶
Authorization servers MUST mitigate PKCE downgrade attacks by ensuring that a
token request containing a code_ parameter is accepted only if a
code_ 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_ 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 audience-aud claim as defined in [RFC9068] MAY be
used to audience-scope 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 authori 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
2.5. Client Authentication
Authorization servers SHOULD enforce client authentication if it is feasible, in
the particular deployment, to establish a process for issuanc
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 [OpenIDprivate_).
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 ensures that security features and other new OAuth features can be enabled automatically by compliant software libraries.¶
- It reduces chances for misconfigurations -- for example, misconfigured endpoint URLs (that might belong to an attacker) or misconfigured security features.¶
- It can help to facilitate rotation of cryptographic keys and to ensure cryptographic agility.¶
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_ 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_
Endpoint, and Dynamic Client Registration Endpoint MAY support the use of
Cross-Origin Resource Sharing (CORS) [WHATWG
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-
The aforementioned attackers (A1) and (A2) conform to the attacker model that was used in formal analysis
efforts for OAuth [arXiv
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:¶
- insufficient checking of redirect URIs (see Section 4.1);¶
- problems existing on mobile operating systems, where different apps can register themselves on the same URI; and¶
- URLs stored/logged by browsers (history), proxy servers, and operating systems.¶
- (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 misconfiguration, 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, along with potential countermeasures. Attacks and mitigations already covered in [RFC6819] are not listed here, except where new recommendations are made.¶
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-
- by directly sending the user agent to a URI under the attacker's control, or¶
- by exposing the OAuth credentials to an attacker by utilizing an open redirector at the client in conjunction with the way user agents handle URL fragments.¶
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 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 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". If an
attacker manages to establish a host or subdomain in
somesite, the attacker can impersonate the legitimate client. For example, this
could be caused by a subdomain takeover attack [researchexternal-)
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
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_ 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_t 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:¶
https://attacker.example/#access_token=2YotnFZFEjr1z...
The attacker's page at attacker 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:¶
- Web servers on which redirection URIs are hosted MUST NOT expose open redirectors (see Section 4.11).¶
- Browsers reattach URL fragments to Location redirection URLs only
if the URL in the Location header does not already contain a fragment.
Therefore, servers MAY prevent browsers from reattaching fragments
to redirection URLs by attaching an arbitrary fragment identifier,
for example
#_, to URLs in Location headers.¶ - Clients SHOULD use the authorization code response type instead of
response types that cause access token issuance at the authorization
endpoint. This offers countermeasures against the reuse of leaked
credentials through the exchange process with the authorization
server and against token replay through sender-
constraining of the access tokens.¶
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
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¶
- contains links to other pages under the attacker's control and a user 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 the
third-party content, the attacker receives the authorization response
URL and can extract code or state (and potentially access_).¶
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:¶
- Suppress the Referer header by applying an appropriate Referrer
Policy [W3C
.webappsec- ] to the document (either as part of the "referrer" meta attribute or by setting a Referrer-referrer- policy Policy header). For example, the header Referrer-in the response completely suppresses the Referer header in all requests originating from the resulting document.¶Policy: no-referrer - Use authorization code instead of response types causing access token issuance from the authorization endpoint.¶
- Bind the authorization code to a confidential client or PKCE challenge. In this case, the attacker lacks the secret to request the code exchange.¶
-
As described in Section 4.1.2 of [RFC6749], authorization codes MUST be invalidated by the authorization server after their first use at the token endpoint. For example, if an authorization server invalidated the code after the legitimate client redeemed it, the attacker would fail to exchange this code later.¶
This does not mitigate the attack if the attacker manages to exchange the code for a token before the legitimate client does so. Therefore, [RFC6749] further recommends that, when an attempt is made to redeem a code twice, the authorization server SHOULD revoke all tokens issued previously based on that code.¶
-
The
statevalue SHOULD be invalidated by the client after its first use at the redirection endpoint. If this is implemented, and an attacker receives a token through the Referer header from the client's website, thestatewas already used, invalidated by the client and cannot be used again by the attacker. (This does not help if thestateleaks from the authorization server's website, since then thestatehas not been used at the redirection endpoint at the client yet.)¶ -
Use the form post response mode instead of a redirect for the authorization response (see [OAuth
.Post ]).¶
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:¶
- Clients MUST NOT pass access tokens in a URI query parameter in
the way described in Section 2.3 of [RFC6750]. The authorization
code grant or alternative OAuth response modes like the form post
response mode [OAuth
.Post ] can be used to this end.¶