<?xml version="1.0" encoding="utf-8"?>
<!-- name="GENERATOR" content="github.com/mmarkdown/mmark Mmark Markdown Processor - mmark.miek.nl" -->
<rfc version="3" ipr="trust200902" docName="draft-ietf-oauth-security-topics-22" submissionType="IETF" category="bcp" xml:lang="en" xmlns:xi="http://www.w3.org/2001/XInclude" consensus="true">

<front>
<title abbrev="oauth-security-topics">OAuth 2.0 Security Best Current Practice</title><seriesInfo value="draft-ietf-oauth-security-topics-22" stream="IETF" status="bcp" name="Internet-Draft"></seriesInfo>
<author initials="T." surname="Lodderstedt" fullname="Torsten Lodderstedt"><organization>yes.com</organization><address><postal><street></street>
</postal><email>torsten@lodderstedt.net</email>
</address></author>
<author initials="J." surname="Bradley" fullname="John Bradley"><organization>Yubico</organization><address><postal><street></street>
</postal><email>ve7jtb@ve7jtb.com</email>
</address></author>
<author initials="A." surname="Labunets" fullname="Andrey Labunets"><organization>Independent Researcher</organization><address><postal><street></street>
</postal><email>isciurus@gmail.com</email>
</address></author>
<author initials="D." surname="Fett" fullname="Daniel Fett"><organization>yes.com</organization><address><postal><street></street>
</postal><email>mail@danielfett.de</email>
</address></author>
<date/>
<area>Security</area>
<workgroup>Web Authorization Protocol</workgroup>
<keyword>security</keyword>
<keyword>oauth2</keyword>
<keyword>best current practice</keyword>

<abstract>
<t>This document describes best current security practice for OAuth 2.0.
It updates and extends the OAuth 2.0 Security Threat Model 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.</t>
</abstract>

</front>

<middle>

<section anchor="Introduction"><name>Introduction</name>
<t>Since its publication in <xref target="RFC6749"></xref> and <xref target="RFC6750"></xref>, OAuth 2.0
(&quot;OAuth&quot; in the following) has gotten massive traction in the market
and became the standard for API protection and the basis for federated
login using OpenID Connect <xref target="OpenID.Core"></xref>. While OAuth is used in a
variety of scenarios and different kinds of deployments, the following
challenges can be observed:</t>

<ul>
<li><t>OAuth implementations are being attacked through known implementation
  weaknesses and anti-patterns. Although most of these threats are discussed
  in the OAuth 2.0 Threat Model and Security Considerations <xref target="RFC6819"></xref>,
	continued exploitation demonstrates a need for more specific
  recommendations, easier to implement mitigations, and more defense in depth.</t>
</li>
<li><t>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.</t>
</li>
<li><t>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 <xref target="RFC6749"></xref>, <xref target="RFC6750"></xref>, and <xref target="RFC6819"></xref>.</t>
<t>OAuth initially assumed static relationships between client,
authorization server, and resource servers. The URLs of the AS and RS 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 talks to a legitimate server was based on TLS server
authentication (see <xref target="RFC6819"></xref>, Section 4.5.4). 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 e-mail 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 <xref target="RFC7591"></xref> and OAuth 2.0 Authorization Server Metadata
<xref target="RFC8414"></xref> were developed to support the use of OAuth in
dynamic scenarios.</t>
</li>
<li><t>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.</t>
</li>
</ul>
<t>This document provides updated security recommendations to address
these challenges. It does not supplant the security advice given in
<xref target="RFC6749"></xref>, <xref target="RFC6750"></xref>, and <xref target="RFC6819"></xref>, but complements those
documents.</t>
<t>This document introduces new requirements beyond those defined in existing
specifications such as OAuth 2.0 <xref target="RFC6749"></xref> and OpenID Connect <xref target="OpenID.Core"></xref>
and deprecates some modes of operation that are deemed less secure or even
insecure. 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 when feasible.</t>

<section anchor="structure"><name>Structure</name>
<t>The remainder of this document is organized as follows: The next section
summarizes the most important best practices for every OAuth implementor.
Afterwards, the updated the OAuth attacker model is presented. Subsequently, a
detailed analysis of the threats and implementation issues that can be found in
the wild today is given along with a discussion of potential countermeasures.</t>
</section>

<section anchor="conventions-and-terminology"><name>Conventions and Terminology</name>
<t>The key words &quot;MUST&quot;, &quot;MUST NOT&quot;, &quot;REQUIRED&quot;, &quot;SHALL&quot;, &quot;SHALL
NOT&quot;, &quot;SHOULD&quot;, &quot;SHOULD NOT&quot;, &quot;RECOMMENDED&quot;, &quot;NOT RECOMMENDED&quot;,
&quot;MAY&quot;, and &quot;OPTIONAL&quot; in this document are to be interpreted as
described in BCP 14 <xref target="RFC2119"></xref> <xref target="RFC8174"></xref> when, and only when, they
appear in all capitals, as shown here.</t>
<t>This specification uses the terms &quot;access token&quot;, &quot;authorization
endpoint&quot;, &quot;authorization grant&quot;, &quot;authorization server&quot;, &quot;client&quot;,
&quot;client identifier&quot; (client ID), &quot;protected resource&quot;, &quot;refresh
token&quot;, &quot;resource owner&quot;, &quot;resource server&quot;, and &quot;token endpoint&quot;
defined by OAuth 2.0 <xref target="RFC6749"></xref>.</t>
</section>
</section>

<section anchor="recommendations"><name>Best Practices</name>
<t>This section describes the set of security mechanisms and measures the OAuth
working group considers best practices at the time of writing.</t>

<section anchor="rec_redirect"><name>Protecting Redirect-Based Flows</name>
<t>When comparing client redirect URIs against pre-registered URIs, authorization
servers MUST utilize exact string matching except for port numbers in
<tt>localhost</tt> redirection URIs of native apps, see <xref target="iuv_countermeasures"></xref>. This
measure contributes to the prevention of leakage of authorization codes and
access tokens (see <xref target="insufficient_uri_validation"></xref>). It can also help to detect
mix-up attacks (see <xref target="mix_up"></xref>).</t>
<t>Clients and AS MUST NOT expose URLs that forward the user's browser to
arbitrary URIs obtained from a query parameter (&quot;open redirector&quot;) as
described in <xref target="open_redirection"></xref>. Open redirectors can enable
exfiltration of authorization codes and access tokens.</t>
<t>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 a malicious third party
(see Section 4.4.1.8. of <xref target="RFC6819"></xref> for details). Clients that have
ensured that the authorization server supports PKCE <xref target="RFC7636"></xref> MAY
rely on the CSRF protection provided by PKCE. In OpenID Connect flows,
the <tt>nonce</tt> parameter provides CSRF protection. Otherwise, one-time
use CSRF tokens carried in the <tt>state</tt> parameter that are securely
bound to the user agent MUST be used for CSRF protection (see
<xref target="csrf_countermeasures"></xref>).</t>
<t>When an OAuth client can interact with more than one authorization server, a
defense against mix-up attacks (see <xref target="mix_up"></xref>) is REQUIRED. To this end, clients
SHOULD</t>

<ul>
<li><t>use the <tt>iss</tt> parameter as a countermeasure according to
<xref target="RFC9207"></xref>, or</t>
</li>
<li><t>use an alternative countermeasure based on an <tt>iss</tt> value in the
authorization response (such as the <tt>iss</tt> Claim in the ID Token in
<xref target="OpenID.Core"></xref> or in <xref target="JARM"></xref> responses), processing it as described in
<xref target="RFC9207"></xref>.</t>
</li>
</ul>
<t>In the absence of these options, clients MAY instead use distinct redirect URIs
to identify authorization endpoints and token endpoints, as described in
<xref target="mixupcountermeasures"></xref>.</t>
<t>An AS that redirects a request potentially containing user credentials
MUST avoid forwarding these user credentials accidentally (see
<xref target="redirect_307"></xref> for details).</t>

<section anchor="ac"><name>Authorization Code Grant</name>
<t>Clients MUST prevent authorization code
injection attacks (see <xref target="code_injection"></xref>) and misuse of authorization codes using one of the following options:</t>

<ul>
<li><t>Public clients MUST use PKCE <xref target="RFC7636"></xref> to this end, as motivated in
<xref target="pkce_as_injection_protection"></xref>.</t>
</li>
<li><t>For confidential clients, the use of PKCE <xref target="RFC7636"></xref> is RECOMMENDED, as it
provides a strong protection against misuse and injection of authorization
codes as described in <xref target="pkce_as_injection_protection"></xref> and, as a side-effect,
prevents CSRF even in presence of strong attackers as described in
<xref target="csrf_countermeasures"></xref>.</t>
</li>
<li><t>With additional precautions, described in <xref target="nonce_as_injection_protection"></xref>,
confidential OpenID Connect <xref target="OpenID.Core"></xref> clients MAY use the <tt>nonce</tt> parameter and the
respective Claim in the ID Token instead.</t>
</li>
</ul>
<t>In any case, the PKCE challenge or OpenID Connect <tt>nonce</tt> MUST be
transaction-specific and securely bound to the client and the user agent in
which the transaction was started.</t>
<t>Note: Although PKCE was designed as a mechanism to protect native
apps, this advice applies to all kinds of OAuth clients, including web
applications.</t>
<t>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 <xref target="secmodel"></xref>) can break the security provided
by PKCE. Currently, <tt>S256</tt> is the only such method.</t>
<t>Authorization servers MUST support PKCE <xref target="RFC7636"></xref>.</t>
<t>If a client sends a valid PKCE <xref target="RFC7636"></xref> <tt>code_challenge</tt> parameter in the
authorization request, the authorization server MUST enforce the correct usage
of <tt>code_verifier</tt> at the token endpoint.</t>
<t>Authorization servers MUST mitigate PKCE Downgrade Attacks by ensuring that a
token request containing a <tt>code_verifier</tt> parameter is accepted only if a
<tt>code_challenge</tt> parameter was present in the authorization request, see
<xref target="pkce_downgrade_countermeasures"></xref> for details.</t>
<t>Authorization servers MUST provide a way to detect their support for
PKCE. It is RECOMMENDED for AS to publish the element
<tt>code_challenge_methods_supported</tt> in their AS metadata (<xref target="RFC8414"></xref>)
containing the supported PKCE challenge methods (which can be used by
the client to detect PKCE support). ASs MAY instead provide a
deployment-specific way to ensure or determine PKCE support by the AS.</t>
</section>

<section anchor="implicit_grant_recommendation"><name>Implicit Grant</name>
<t>The implicit grant (response type &quot;token&quot;) 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 <xref target="insufficient_uri_validation"></xref>,
<xref target="credential_leakage_referrer"></xref>, <xref target="browser_history"></xref>, and
<xref target="access_token_injection"></xref>.</t>
<t>Moreover, no viable method for sender-constraining exists to
bind access tokens to a specific client (as recommended in
<xref target="token_replay_prevention"></xref>) when the access tokens are issued in the
authorization response. This means that an attacker can use leaked or stolen
access token at a resource endpoint.</t>
<t>In order to avoid these issues, clients SHOULD NOT use the implicit
grant (response type &quot;token&quot;) 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.</t>
<t>Clients SHOULD instead use the response type &quot;code&quot; (aka authorization
code grant type) as specified in <xref target="ac"></xref> or any other response type that
causes the authorization server to issue access tokens in the token
response, such as the &quot;code id_token&quot; 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-constrain the issued tokens (see next section).</t>
</section>
</section>

<section anchor="token_replay_prevention"><name>Token Replay Prevention</name>

<section anchor="access-tokens"><name>Access Tokens</name>
<t>A sender-constrained access token scopes the applicability of an access
token to a certain sender. This sender is obliged to demonstrate knowledge
of a certain secret as prerequisite for the acceptance of that token at
the recipient (e.g., a resource server).</t>
<t>Authorization and resource servers SHOULD use mechanisms for sender-constraining
access tokens, such as Mutual TLS for OAuth 2.0 <xref target="RFC8705"></xref> or OAuth
Demonstration of Proof of Possession (DPoP) <xref target="I-D.ietf-oauth-dpop"></xref> (see
<xref target="pop_tokens"></xref>), to prevent misuse of stolen and leaked access tokens.</t>
</section>

<section anchor="refresh-tokens"><name>Refresh Tokens</name>
<t>Refresh tokens for public clients MUST be sender-constrained or use refresh
token rotation as described in <xref target="refresh_token_protection"></xref>. <xref target="RFC6749"></xref> already
mandates that refresh tokens for confidential clients can only be used by the
client for which they were issued.</t>
</section>
</section>

<section anchor="access-token-privilege-restriction"><name>Access Token Privilege Restriction</name>
<t>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.</t>
<t>In particular, access tokens SHOULD be restricted to certain resource
servers (audience restriction), preferably to a single resource
server. To put this into effect, the authorization server associates
the access token with certain resource servers 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
resource server. If not, the resource server MUST refuse to serve the
respective request. The <tt>aud</tt> claim as defined in <xref target="RFC9068"></xref> MAY be
used to audience-restrict access tokens. Clients and authorization servers MAY utilize the
parameters <tt>scope</tt> or <tt>resource</tt> as specified in <xref target="RFC6749"></xref> and
<xref target="RFC8707"></xref>, respectively, to determine the
resource server they want to access.</t>
<t>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 <tt>scope</tt> as specified in <xref target="RFC6749"></xref> and <tt>authorization_details</tt> as specified in <xref target="I-D.ietf-oauth-rar"></xref> to determine those
resources and/or actions.</t>
</section>

<section anchor="resource-owner-password-credentials-grant"><name>Resource Owner Password Credentials Grant</name>
<t>The resource owner password credentials grant MUST NOT be used. This
grant type insecurely exposes the credentials of the resource owner to
the client. Even if the client is benign, this results in an increased
attack surface (credentials can leak in more places than just the AS)
and users are trained to enter their credentials in places other than
the AS.</t>
<t>Furthermore, adapting the resource owner password credentials grant to
two-factor authentication, authentication with cryptographic
credentials (cf. WebCrypto <xref target="WebCrypto"></xref>, WebAuthn <xref target="WebAuthn"></xref>), and
authentication processes that require multiple steps can be hard or
impossible.</t>
</section>

<section anchor="client-authentication"><name>Client Authentication</name>
<t>Authorization servers SHOULD use client authentication if possible.</t>
<t>It is RECOMMENDED to use asymmetric (public-key based) methods for
client authentication such as mTLS <xref target="RFC8705"></xref> or using signed JWTs
(&quot;Private Key JWT&quot;) in accordance with <xref target="RFC7521"></xref> and <xref target="RFC7523"></xref>
(in <xref target="OpenID.Core"></xref> defined as the client authentication method <tt>private_key_jwt</tt>).
When such methods for client authentication are used, authorization
servers do not need to store sensitive symmetric keys, making these
methods more robust against a number of attacks.</t>
</section>

<section anchor="other-recommendations"><name>Other Recommendations</name>
<t>The use of OAuth Metadata <xref target="RFC8414"></xref> can help to improve the security of OAuth
deployments:</t>

<ul>
<li><t>It ensures that security features and other new OAuth features can be enabled
automatically by compliant software libraries.</t>
</li>
<li><t>It reduces chances for misconfigurations, for example misconfigured endpoint
URLs (that might belong to an attacker) or misconfigured security features.</t>
</li>
<li><t>It can help to facilitate rotation of cryptographic keys and to ensure
cryptographic agility.</t>
</li>
</ul>
<t>It is therefore RECOMMENDED that ASs publish OAuth metadata according to
<xref target="RFC8414"></xref> and that clients make use of this metadata to configure themselves
when available.</t>
<t>Authorization servers SHOULD NOT allow clients to influence their <tt>client_id</tt> or
any other Claim if that can cause confusion with a genuine resource owner, as
described in <xref target="client_impersonating"></xref></t>
<t>It is RECOMMENDED to use end-to-end TLS. If TLS
traffic needs to be terminated at an intermediary, refer to
<xref target="tls_terminating"></xref> for further security advice.</t>
<t>Authorization responses MUST NOT be transmitted over unencrypted network
connections. To this end, AS MUST NOT allow redirect URIs that use the <tt>http</tt>
scheme except for native clients that use Loopback Interface Redirection as
described in <xref target="RFC8252"></xref>, Section 7.3.</t>
<t>If the authorization response is sent with in-browser communication techniques
like postMessage <xref target="postmessage_api"></xref> instead of HTTP redirects, both the
initiator and receiver of the in-browser message MUST be strictly verified as described
in <xref target="rec_ibc"></xref>.</t>
</section>
</section>

<section anchor="secmodel"><name>The Updated OAuth 2.0 Attacker Model</name>
<t>In <xref target="RFC6819"></xref>, an attacker model is laid out that describes the
capabilities of attackers against which OAuth deployments must be
protected. In the following, this attacker model is updated to account
for the potentially dynamic relationships involving multiple parties
(as described in <xref target="Introduction"></xref>), to include new types of attackers and to define
the attacker model more clearly.</t>
<t>OAuth MUST ensure that the authorization of the resource owner (RO)
(with a user agent) at the authorization server (AS) and the subsequent
usage of the access token at the resource server (RS) is protected at
least against the following attackers:</t>

<ul>
<li><t>(A1) Web Attackers that can set up and operate an arbitrary number
of network endpoints including browsers and servers (except for
the concrete RO, AS, and RS). Web attackers may set up web sites
that are visited by the RO, operate their own user agents, and
participate in the protocol.</t>
<t>Web attackers may, in particular, operate OAuth clients that are
registered at AS, and operate their own authorization and resource
servers that can be used (in parallel) by the RO and other
resource owners.</t>
<t>It must also be assumed that web attackers can lure the user to
open 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.</t>
<t>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 redirect URI, the web attacker can then
try to redeem that code for an access token.</t>
<t>They cannot, however, read or manipulate messages that are not
targeted towards them (e.g., sent to a URL controlled by a
non-attacker controlled AS).</t>
</li>
<li><t>(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.</t>
</li>
</ul>
<t>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 (wifi) network using ARP
spoofing, or a state-sponsored attacker with access to internet
exchange points, for instance.</t>
<t>These attackers conform to the attacker model that was used in formal analysis
efforts for OAuth <xref target="arXiv.1601.01229"></xref>. This is a minimal attacker model.
Implementers MUST take into account all possible types of attackers in the
environment in which their OAuth implementations are expected to run. Previous
attacks on OAuth have shown that OAuth deployments SHOULD in particular consider
the following, stronger attackers in addition to those listed above:</t>

<ul>
<li><t>(A3) Attackers that can read, but not modify, the contents of the
authorization response (i.e., the authorization response can leak
to an attacker).</t>
<t>Examples for such attacks include open redirector attacks, insufficient
checking of redirect URIs (see <xref target="insufficient_uri_validation"></xref>), problems
existing on mobile operating systems (where different apps can register
themselves on the same URI), mix-up attacks (see <xref target="mix_up"></xref>), where the
client is tricked into sending credentials to a attacker-controlled AS, and
the fact that URLs are often stored/logged by browsers (history), proxy
servers, and operating systems.</t>
</li>
<li><t>(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).</t>
</li>
<li><t>(A5) Attackers that can acquire an access token issued by AS. For
example, a resource server can be compromised by an attacker, an
access token may be sent to an attacker-controlled resource server
due to a misconfiguration, or an RO is social-engineered into
using a attacker-controlled RS. See also <xref target="comp_res_server"></xref>.</t>
</li>
</ul>
<t>(A3), (A4) and (A5) typically occur together with either (A1) or (A2).
Attackers can collaborate to reach a common goal.</t>
<t>Note that in this attacker model, an attacker (see A1) can be a RO or
act as one. For example, an attacker can use his own browser to replay
tokens or authorization codes obtained by any of the attacks described
above at the client or RS.</t>
<t>This document focusses on threats resulting from these attackers.
Attacks in an even stronger attacker model are discussed, for example,
in <xref target="arXiv.1901.11520"></xref>.</t>
</section>

<section anchor="attacks_and_mitigations"><name>Attacks and Mitigations</name>
<t>This section gives a detailed description of attacks on OAuth
implementations, along with potential countermeasures. Attacks and
mitigations already covered in <xref target="RFC6819"></xref> are not listed here, except
where new recommendations are made.</t>

<section anchor="insufficient_uri_validation"><name>Insufficient Redirect URI Validation</name>
<t>Some authorization servers allow clients to register redirect URI
patterns instead of complete redirect URIs. The authorization servers
then match the redirect 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
redirect URIs.</t>
<t>This approach turned out to be more complex to implement and more
error prone to manage than exact redirect URI matching. Several
successful attacks exploiting flaws in the pattern matching
implementation or concrete configurations have been observed in the
wild . Insufficient validation of the redirect URI effectively breaks
client identification or authentication (depending on grant and client
type) and allows the attacker to obtain an authorization code or
access token, either</t>

<ul>
<li><t>by directly sending the user agent to a URI under the attackers
control, or</t>
</li>
<li><t>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.</t>
</li>
</ul>
<t>These attacks are shown in detail in the following subsections.</t>

<section anchor="insufficient_uri_validation_acg"><name>Redirect URI Validation Attacks on Authorization Code Grant</name>
<t>For a client using the grant type code, an attack may work as
follows:</t>
<t>Assume the redirect URL pattern <tt>https://*.somesite.example/*</tt> is
registered for the client with the client ID <tt>s6BhdRkqt3</tt>. The
intention is to allow any subdomain of <tt>somesite.example</tt> to be a
valid redirect URI for the client, for example
<tt>https://app1.somesite.example/redirect</tt>. A naive implementation on
the authorization server, however, might interpret the wildcard <tt>*</tt> as
&quot;any character&quot; and not &quot;any character valid for a domain name&quot;. The
authorization server, therefore, might permit
<tt>https://attacker.example/.somesite.example</tt> as a redirect URI,
although <tt>attacker.example</tt> is a different domain potentially
controlled by a malicious party.</t>
<t>The attack can then be conducted as follows:</t>
<t>First, the attacker needs to trick the user into opening a tampered
URL in his browser that launches a page under the attacker's
control, say <tt>https://www.evil.example</tt> (see Attacker A1 in <xref target="secmodel"></xref>).</t>
<t>This URL initiates the following authorization request with the client
ID of a legitimate client to the authorization endpoint (line breaks
for display only):</t>

<artwork>GET /authorize?response_type=code&amp;client_id=s6BhdRkqt3&amp;state=9ad67f13
     &amp;redirect_uri=https%3A%2F%2Fattacker.example%2F.somesite.example 
     HTTP/1.1
Host: server.somesite.example
</artwork>
<t>The authorization server validates the redirect URI and compares it to
the registered redirect URL patterns for the client <tt>s6BhdRkqt3</tt>.
The authorization request is processed and presented to the user.</t>
<t>If the user does not see the redirect 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
<xref target="RFC6749"></xref>), the attack can be performed even without user
interaction.</t>
<t>If the attacker impersonated a public client, the attacker can
exchange the code for tokens at the respective token endpoint.</t>
<t>This attack will not work as easily for confidential clients, since
the code exchange requires authentication with the legitimate client's
secret. The attacker can, however, use the legitimate confidential
client to redeem the code by performing an authorization code
injection attack, see <xref target="code_injection"></xref>.</t>
<t>Note: Vulnerabilities of this kind can also exist if the authorization
server handles wildcards properly. For example, assume that the client
registers the redirect URL pattern <tt>https://*.somesite.example/*</tt> and
the authorization server interprets this as &quot;allow redirect URIs
pointing to any host residing in the domain <tt>somesite.example</tt>&quot;. If an
attacker manages to establish a host or subdomain in
<tt>somesite.example</tt>, he can impersonate the legitimate client. This
could be caused, for example, by a subdomain takeover attack <xref target="subdomaintakeover"></xref>, where an
outdated CNAME record (say, <tt>external-service.somesite.example</tt>)
points to an external DNS name that does no longer exist (say,
<tt>customer-abc.service.example</tt>) and can be taken over by an attacker
(e.g., by registering as <tt>customer-abc</tt> with the external service).</t>
</section>

<section anchor="redir_uri_open_redir"><name>Redirect URI Validation Attacks on Implicit Grant</name>
<t>The attack described above works for the implicit grant as well. If
the attacker is able to send the authorization response to a URI under
his control, he will directly get access to the fragment carrying the
access token.</t>
<t>Additionally, implicit clients can be subject to a further kind of
attack. It utilizes the fact that user agents re-attach fragments to
the destination URL of a redirect if the location header does not
contain a fragment (see <xref target="RFC7231"></xref>, Section 9.5). The attack
described here combines this behavior with the client as an open
redirector (see <xref target="open_redirector_on_client"></xref>) in order to get access to access tokens. This allows
circumvention even of very narrow redirect URI patterns, but not strict URL
matching.</t>
<t>Assume the registered URL pattern for client <tt>s6BhdRkqt3</tt> is
<tt>https://client.somesite.example/cb?*</tt>, i.e., any parameter is allowed
for redirects to <tt>https://client.somesite.example/cb</tt>. Unfortunately,
the client exposes an open redirector. This endpoint supports a
parameter <tt>redirect_to</tt> which takes a target URL and will send the
browser to this URL using an HTTP Location header redirect 303.</t>
<t>The attack can now be conducted as follows:</t>
<t>First, and as above, the attacker needs to trick the user into opening
a tampered URL in his browser that launches a page under the
attacker's control, say <tt>https://www.evil.example</tt>.</t>
<t>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
<tt>redirect_to=https://attacker.example</tt> into the parameters of the
redirect URI and it uses the response type &quot;token&quot; (line breaks for display only):</t>

<artwork>GET /authorize?response_type=token&amp;state=9ad67f13
    &amp;client_id=s6BhdRkqt3
    &amp;redirect_uri=https%3A%2F%2Fclient.somesite.example
     %2Fcb%26redirect_to%253Dhttps%253A%252F
     %252Fattacker.example%252F HTTP/1.1
Host: server.somesite.example
</artwork>
<t>Now, since the redirect 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):</t>

<artwork>HTTP/1.1 303 See Other
Location: https://client.somesite.example/cb?
          redirect_to%3Dhttps%3A%2F%2Fattacker.example%2Fcb
          #access_token=2YotnFZFEjr1zCsicMWpAA&amp;...
</artwork>
<t>At example.com, the request arrives at the open redirector. The endpoint will
read the redirect parameter and will issue an HTTP 303 Location header
redirect to the URL <tt>https://attacker.example/</tt>.</t>

<artwork>HTTP/1.1 303 See Other
Location: https://attacker.example/
</artwork>
<t>Since the redirector at client.somesite.example does not include a
fragment in the Location header, the user agent will re-attach the
original fragment <tt>#access_token=2YotnFZFEjr1zCsicMWpAA&amp;amp;...</tt> to
the URL and will navigate to the following URL:</t>

<artwork>https://attacker.example/#access_token=2YotnFZFEjr1z...
</artwork>
<t>The attacker's page at <tt>attacker.example</tt> can now access the
fragment and obtain the access token.</t>
</section>

<section anchor="iuv_countermeasures"><name>Countermeasures</name>
<t>The complexity of implementing and managing pattern matching correctly obviously
causes security issues. This document therefore advises to simplify the required
logic and configuration by using exact redirect URI matching. This means
the authorization server MUST compare the two URIs using simple string
comparison as defined in <xref target="RFC3986"></xref>, Section 6.2.1. The only exception are
native apps using a <tt>localhost</tt> URI: In this case, the AS MUST allow variable
port numbers as described in <xref target="RFC8252"></xref>, Section 7.3.</t>
<t>Additional recommendations:</t>

<ul>
<li><t>Servers on which callbacks are hosted MUST NOT expose open
redirectors (see <xref target="open_redirection"></xref>).</t>
</li>
<li><t>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 <tt>#_</tt>, to URLs in Location headers.</t>
</li>
<li><t>Clients SHOULD use the authorization code response type instead of
response types causing access token issuance at the authorization
endpoint. This offers countermeasures against reuse of leaked
credentials through the exchange process with the authorization
server and token replay through sender-constraining of the access
tokens.</t>
</li>
</ul>
<t>If the origin and integrity of the authorization request containing
the redirect URI can be verified, for example when using
<xref target="RFC9101"></xref> or <xref target="RFC9126"></xref> with client
authentication, the authorization server MAY trust the redirect URI
without further checks.</t>
</section>
</section>

<section anchor="credential_leakage_referrer"><name>Credential Leakage via Referer Headers</name>
<t>The contents of the authorization request URI or the authorization
response URI can unintentionally be disclosed to attackers through the
Referer HTTP header (see <xref target="RFC7231"></xref>, Section 5.5.2), by leaking either
from the AS's or the client's web site, respectively. Most
importantly, authorization codes or <tt>state</tt> values can be disclosed in
this way. Although specified otherwise in <xref target="RFC7231"></xref>, Section 5.5.2,
the same may happen to access tokens conveyed in URI fragments due to
browser implementation issues, as illustrated by Chromium Issue 168213
<xref target="bug.chromium"></xref>.</t>

<section anchor="leakage-from-the-oauth-client"><name>Leakage from the OAuth Client</name>
<t>Leakage from the OAuth client requires that the client, as a result of
a successful authorization request, renders a page that</t>

<ul>
<li><t>contains links to other pages under the attacker's control and a
user clicks on such a link, or</t>
</li>
<li><t>includes third-party content (advertisements in iframes, images,
etc.), for example if the page contains user-generated content
(blog).</t>
</li>
</ul>
<t>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 <tt>code</tt> or <tt>state</tt> (and potentially <tt>access token</tt>).</t>
</section>

<section anchor="leakage-from-the-authorization-server"><name>Leakage from the Authorization Server</name>
<t>In a similar way, an attacker can learn <tt>state</tt> from the authorization
request if the authorization endpoint at the authorization server
contains links or third-party content as above.</t>
</section>

<section anchor="consequences"><name>Consequences</name>
<t>An attacker that learns a valid code or access token through a
Referer header can perform the attacks as described in
<xref target="insufficient_uri_validation_acg"></xref>, <xref target="code_injection"></xref>, and
<xref target="access_token_injection"></xref>. If the attacker learns <tt>state</tt>, the CSRF
protection achieved by using <tt>state</tt> is lost, resulting in CSRF
attacks as described in <xref target="RFC6819"></xref>, Section 4.4.1.8.</t>
</section>

<section anchor="countermeasures"><name>Countermeasures</name>
<t>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.</t>
<t>The following measures further reduce the chances of a successful attack:</t>

<ul>
<li><t>Suppress the Referer header by applying an appropriate Referrer
Policy <xref target="webappsec-referrer-policy"></xref> to the document (either as
part of the &quot;referrer&quot; meta attribute or by setting a
Referrer-Policy header). For example, the header <tt>Referrer-Policy:
no-referrer</tt> in the response completely suppresses the Referer
header in all requests originating from the resulting document.</t>
</li>
<li><t>Use authorization code instead of response types causing access
token issuance from the authorization endpoint.</t>
</li>
<li><t>Bind the authorization code to a confidential client or PKCE
challenge. In this case, the attacker lacks the secret to request
the code exchange.</t>
</li>
<li><t>As described in <xref target="RFC6749"></xref>, Section 4.1.2, authorization codes
MUST be invalidated by the AS after their first use at the token
endpoint. For example, if an AS invalidated the code after the
legitimate client redeemed it, the attacker would fail exchanging
this code later.</t>
<t>This does not mitigate the attack if the attacker manages to
exchange the code for a token before the legitimate client does
so. Therefore, <xref target="RFC6749"></xref> further recommends that, when an
attempt is made to redeem a code twice, the AS SHOULD revoke all
tokens issued previously based on that code.</t>
</li>
<li><t>The <tt>state</tt> value 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 web site, the <tt>state</tt> was already used, invalidated by
the client and cannot be used again by the attacker. (This does
not help if the <tt>state</tt> leaks from the
AS's web site, since then the <tt>state</tt>
has not been used at the redirection endpoint at the client yet.)</t>
</li>
<li><t>Use the form post response mode instead of a redirect for the
authorization response (see <xref target="OAuth.Post"></xref>).</t>
</li>
</ul>
</section>
</section>

<section anchor="browser_history"><name>Credential Leakage via Browser History</name>
<t>Authorization codes and access tokens can end up in the browser's
history of visited URLs, enabling the attacks described in the
following.</t>

<section anchor="authorization-code-in-browser-history"><name>Authorization Code in Browser History</name>
<t>When a browser navigates to
<tt>client.example/redirection_endpoint?code=abcd</tt> as a result of a
redirect from a provider's authorization endpoint, the URL including
the authorization code may end up in the browser's history. An
attacker with access to the device could obtain the code and try to
replay it.</t>
<t>Countermeasures:</t>

<ul>
<li><t>Authorization code replay prevention as described in <xref target="RFC6819"></xref>,
Section 4.4.1.1, and <xref target="code_injection"></xref>.</t>
</li>
<li><t>Use form post response mode instead of redirect for the authorization
response (see <xref target="OAuth.Post"></xref>).</t>
</li>
</ul>
</section>

<section anchor="access-token-in-browser-history"><name>Access Token in Browser History</name>
<t>An access token may end up in the browser history if a client or a web
site that already has a token deliberately navigates to a page like
<tt>provider.com/get_user_profile?access_token=abcdef</tt>. <xref target="RFC6750"></xref>
discourages this practice and advises to transfer tokens via a header,
but in practice web sites often pass access tokens in query
parameters.</t>
<t>In case of the implicit grant, a URL like
<tt>client.example/redirection_endpoint#access_token=abcdef</tt> may also end
up in the browser history as a result of a redirect from a provider's
authorization endpoint.</t>
<t>Countermeasures:</t>

<ul>
<li><t>Clients MUST NOT pass access tokens in a URI query parameter in
the way described in Section 2.3 of <xref target="RFC6750"></xref>. The authorization
code grant or alternative OAuth response modes like the form post
response mode <xref target="OAuth.Post"></xref> can be used to
this end.</t>
</li>
</ul>
</section>
</section>

<section anchor="mix_up"><name>Mix-Up Attacks</name>
<t>Mix-up is an attack on 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 his own authorization server or if an authorization server
becomes compromised.</t>
<t>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/resource
server.</t>

<section anchor="attack-description"><name>Attack Description</name>
<t>The description here follows <xref target="arXiv.1601.01229"></xref>, with
variants of the attack outlined below.</t>
<t>Preconditions: For this variant of the attack to work, it is assumed that</t>

<ul>
<li><t>the implicit or authorization code grant are used with multiple AS
of which one is considered &quot;honest&quot; (H-AS) and one is operated by
the attacker (A-AS), and</t>
</li>
<li><t>the client stores the AS chosen by the user in a session bound to
the user's browser and uses the same redirection endpoint URI for
each AS.</t>
</li>
</ul>
<t>In the following, it is further assumed that the client is registered with H-AS (URI:
<tt>https://honest.as.example</tt>, client ID: <tt>7ZGZldHQ</tt>) and with A-AS (URI:
<tt>https://attacker.example</tt>, client ID: <tt>666RVZJTA</tt>). URLs shown in the following
example are shortened for presentation to only include parameters relevant for the
attack.</t>
<t>Attack on the authorization code grant:</t>

<ol>
<li><t>The user selects to start the grant using A-AS (e.g., by clicking on a button at the
client's website).</t>
</li>
<li><t>The client stores in the user's session that the user selected
&quot;A-AS&quot; and redirects the user to A-AS's authorization endpoint
with a Location header containing the URL
<tt>https://attacker.example/authorize?response_type=code&amp;client_id=666RVZJTA</tt>.</t>
</li>
<li><t>When the user's browser navigates to the attacker's authorization endpoint,
the attacker immediately redirects the browser to the authorization endpoint
of H-AS. In the authorization request, the attacker replaces the client ID
of the client at A-AS with the client's ID at H-AS. Therefore, the browser
receives a redirection (<tt>303 See Other</tt>) with a Location header pointing to
<tt>https://honest.as.example/authorize?response_type=code&amp;client_id=7ZGZldHQ</tt></t>
</li>
<li><t>The user authorizes the client to access her resources at H-AS. (Note that a
vigilant user might at this point detect that she intended to use A-AS
instead of H-AS. The first attack variant listed below avoids this.) H-AS
issues a code and sends it (via the browser) back to the client.</t>
</li>
<li><t>Since the client still assumes that the code was issued by A-AS,
it will try to redeem the code at A-AS's token endpoint.</t>
</li>
<li><t>The attacker therefore obtains code and can either exchange the
code for an access token (for public clients) or perform an
authorization code injection attack as described in
<xref target="code_injection"></xref>.</t>
</li>
</ol>
<t>Variants:</t>

<ul>
<li><t><strong>Mix-Up With Interception</strong>: This variant works only if the attacker can
intercept and manipulate the first request/response pair from a user's
browser to the client (in which the user selects a certain AS and is then
redirected by the client to that AS), as in Attacker A2 (see <xref target="secmodel"></xref>). This capability
can, for example, be the result of a man-in-the-middle attack on the user's
connection to the client. In the attack, the user starts the flow with H-AS.
The attacker intercepts this request and changes the user's selection to
A-AS. The rest of the attack proceeds as in Steps 2 and following above.</t>
</li>
<li><t><strong>Implicit Grant</strong>: In the implicit grant, the attacker receives an access
token instead of the code; the rest of the attack works as above.</t>
</li>
<li><t><strong>Per-AS Redirect URIs</strong>: If clients use different redirect URIs for
different ASs, do not store the selected AS in the user's session, and ASs
do not check the redirect URIs properly, attackers can mount an attack
called &quot;Cross-Social Network Request Forgery&quot;. These attacks have been
observed in practice. Refer to <xref target="oauth_security_jcs_14"></xref> for details.</t>
</li>
<li><t><strong>OpenID Connect</strong>: There are variants that can be used to attack OpenID
Connect. In these attacks, the attacker misuses features of the OpenID
Connect Discovery <xref target="OpenID.Discovery"></xref> mechanism or replays access tokens or ID
Tokens to conduct a mix-up attack. The attacks are described in detail in
<xref target="arXiv.1704.08539"></xref>, Appendix A, and <xref target="arXiv.1508.04324v2"></xref>, Section 6
(&quot;Malicious Endpoints Attacks&quot;).</t>
</li>
</ul>
</section>

<section anchor="mixupcountermeasures"><name>Countermeasures</name>
<t>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 in the following.</t>
<t>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 metadata <xref target="RFC8414"></xref> nor OpenID Connect Discovery <xref target="OpenID.Discovery"></xref> are
used, a different unique identifier for this tuple or the tuple itself can be
used instead. For brevity of presentation, such a deployment-specific identifier
will be subsumed under the issuer (or issuer identifier) in the following.</t>
<t>Note: Just storing the authorization server URL is not sufficient to identify
mix-up attacks. An attacker might declare an uncompromised AS's authorization endpoint URL as
&quot;his&quot; AS URL, but declare a token endpoint under his own control.</t>

<section anchor="mix-up-defense-via-issuer-identification"><name>Mix-Up Defense via Issuer Identification</name>
<t>This defense requires that the authorization server sends his 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.</t>
<t>There are different ways this issuer identifier can be transported to the client:</t>

<ul>
<li><t>The issuer information can be transported, for
example, via a separate response parameter <tt>iss</tt>, defined in
<xref target="RFC9207"></xref>.</t>
</li>
<li><t>When OpenID Connect is used and an ID Token is returned in the authorization
response, the client can evaluate the <tt>iss</tt> Claim in the ID Token.</t>
</li>
</ul>
<t>In both cases, the <tt>iss</tt> value MUST be evaluated according to <xref target="RFC9207"></xref>.</t>
<t>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.</t>
</section>

<section anchor="mix-up-defense-via-distinct-redirect-uris"><name>Mix-Up Defense via Distinct Redirect URIs</name>
<t>For this defense, clients MUST use a distinct redirect URI for each issuer
they interact with.</t>
<t>Clients MUST check that the authorization response was received from the correct
issuer by comparing the distinct redirect 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.</t>
<t>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.</t>
<t>Furthermore, an attacker might be able to circumvent the protection offered by
this defense by registering a new client with the &quot;honest&quot; AS using the redirect
URI that the client assigned to the attacker's AS. The attacker could then run
the attack as described above, replacing the
client ID with the client ID of his newly created client.</t>
<t>This defense SHOULD therefore only be used if other options are not available.</t>
</section>
</section>
</section>

<section anchor="code_injection"><name>Authorization Code Injection</name>
<t>An attacker that has gained access to an authorization code contained in an
authorization response (see Attacker A3 in <xref target="secmodel"></xref>) can try to redeem the
authorization code for an access token or otherwise make use of the
authorization code.</t>
<t>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 <xref target="RFC6819"></xref>.</t>
<t>For confidential clients, or in some special situations, the attacker can
execute an authorization code injection attack, as described in the following.</t>
<t>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.</t>
<t>Besides circumventing the client authentication of confidential clients, other
use cases for this attack include:</t>

<ul>
<li><t>The attacker wants to access certain functions in this particular
client. As an example, the attacker wants to impersonate his
victim in a certain app or on a certain web site.</t>
</li>
<li><t>The authorization or resource servers are limited to certain
networks that the attacker is unable to access directly.</t>
</li>
</ul>
<t>Except in these special cases, authorization code injection is usually not
interesting when the code was created for a public client, as sending the code
to the token endpoint is a simpler and more powerful attack, as described above.</t>

<section anchor="attack-description-1"><name>Attack Description</name>
<t>The authorization code injection attack works as follows:</t>

<ol>
<li><t>The attacker obtains an authorization code (see attacker A3 in <xref target="secmodel"></xref>). For the rest
of the attack, only the capabilities of a web attacker (A1) are required.</t>
</li>
<li><t>From the attacker's own device, the attacker starts a regular OAuth authorization
process with the legitimate client.</t>
</li>
<li><t>In the response of the authorization server to the legitimate client, the
attacker replaces the newly created authorization code with the stolen
authorization code. Since this response is passing through the attacker's
device, the attacker can use any tool that can intercept and manipulate the
authorization response to this end. The attacker does not need to control
the network.</t>
</li>
<li><t>The legitimate client sends the code to the authorization server's token
endpoint, along with the <tt>redirect_uri</tt> and the client's client ID and
client secret (or other means of client authentication).</t>
</li>
<li><t>The authorization server checks the client secret, whether the
code was issued to the particular client, and whether the actual
redirect URI matches the <tt>redirect_uri</tt> parameter (see
<xref target="RFC6749"></xref>).</t>
</li>
<li><t>All checks succeed and the authorization server issues access and
other tokens to the client. The attacker has now associated his
session with the legitimate client with the victim's resources
and/or identity.</t>
</li>
</ol>
</section>

<section anchor="discussion"><name>Discussion</name>
<t>Obviously, the check in 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.</t>
<t>An attempt to inject a code obtained via a manipulated redirect URI
should also be detected if the authorization server stored the
complete redirect URI used in the authorization request and compares
it with the <tt>redirect_uri</tt> parameter.</t>
<t><xref target="RFC6749"></xref>, Section 4.1.3, requires the AS to &quot;... ensure that the
<tt>redirect_uri</tt> parameter is present if the <tt>redirect_uri</tt> parameter
was included in the initial authorization request as described in
Section 4.1.1, and if included ensure that their values are
identical.&quot;. In the attack scenario described above, the legitimate
client would use the correct redirect URI it always uses for
authorization requests. But this URI would not match the tampered
redirect URI used by the attacker (otherwise, the redirect would not
land at the attackers page). So the authorization server would detect
the attack and refuse to exchange the code.</t>
<t>Note: 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:</t>

<ul>
<li><t>the redirect URI itself needs to contain a nonce or another kind
of one-time use, secret data and</t>
</li>
<li><t>the client has bound this data to this particular instance of the
client.</t>
</li>
</ul>
<t>But this approach conflicts with the idea to enforce exact redirect
URI matching at the authorization endpoint. Moreover, it has been
observed that providers very often ignore the <tt>redirect_uri</tt> check
requirement at this stage, maybe because it doesn't seem to be
security-critical from reading the specification.</t>
<t>Other providers just pattern match the <tt>redirect_uri</tt> parameter
against the registered redirect URI pattern. This saves the
authorization server from storing the link between the actual redirect
URI and the respective authorization code for every transaction. But
this kind of check obviously does not fulfill the intent of the
specification, since the tampered redirect URI is not considered. So
any attempt to inject an authorization code obtained using the
<tt>client_id</tt> of a legitimate client or by utilizing the legitimate
client on another device will not be detected in the respective
deployments.</t>
<t>It is also assumed that the requirements defined in <xref target="RFC6749"></xref>,
Section 4.1.3, increase client implementation complexity as clients
need to store or re-construct the correct redirect URI for the call
to the token endpoint.</t>
<t>Asymmetric methods for client authentication do not stop this attack, as the
legitimate client authenticates at the token endpoint.</t>
<t>This document therefore recommends to instead bind 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.</t>
</section>

<section anchor="countermeasures-1"><name>Countermeasures</name>
<t>There are two good technical solutions to achieve this goal, outlined
in the following.</t>

<section anchor="pkce_as_injection_protection"><name>PKCE</name>
<t>The PKCE mechanism specified in <xref target="RFC7636"></xref> can be used as a countermeasure.
When the attacker attempts to inject an authorization code, the check of the
<tt>code_verifier</tt> fails: the client uses its correct verifier, but the code is
associated with a <tt>code_challenge</tt> that does not match this verifier. PKCE is a
deployed OAuth feature, although its originally intended use was solely focused
on securing native apps, not the broader use recommended by this document.</t>
<t>PKCE does not only protect against the autorization 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 <tt>code_verifier</tt>.</t>
</section>

<section anchor="nonce_as_injection_protection"><name>Nonce</name>
<t>OpenID Connect's existing <tt>nonce</tt> parameter can protect against authorization
code injection attacks. The <tt>nonce</tt> value is one-time use and created by the
client. The client is supposed to bind it to the user agent session and sends it
with the initial request to the OpenID Provider (OP). The OP puts the received <tt>nonce</tt> value into the ID Token that is issued
as part of the code exchange at the token endpoint. If an attacker injected an
authorization code in the authorization response, the nonce value in the client
session and the nonce value in the ID token 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, where the attacker has stolen the respective authorization
code.</t>
<t>It is important to note that this countermeasure only works if the client
properly checks the <tt>nonce</tt> parameter in the ID Token and does not use any
issued token until this check has succeeded. More precisely, a client protecting
itself against code injection using the <tt>nonce</tt> parameter,</t>

<ol>
<li><t>MUST validate the <tt>nonce</tt> in the ID Token obtained from the token endpoint,
 even if another ID Token was obtained from the authorization response
 (e.g., <tt>response_type=code+id_token</tt>), and</t>
</li>
<li><t>MUST ensure that, unless and until that check succeeds, all tokens (ID
 Tokens and the access token) are disregarded and not used for any other
 purpose.</t>
</li>
</ol>
<t>It is important to note that <tt>nonce</tt> 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.</t>
</section>

<section anchor="other-solutions"><name>Other Solutions</name>
<t>Other solutions, like binding <tt>state</tt> to the code, sender-constraining the code
using cryptographic means, or per-instance client credentials are
conceivable, but lack support and bring new security requirements.</t>
<t>PKCE is the most obvious solution for OAuth clients as it is available
today (originally intended for OAuth native apps) whereas <tt>nonce</tt> is
appropriate for OpenID Connect clients.</t>
</section>
</section>

<section anchor="limitations"><name>Limitations</name>
<t>An attacker can circumvent the countermeasures described above if he
can modify the <tt>nonce</tt> or <tt>code_challenge</tt> 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 his own session
in Step 2 of the attack above. (This requires that the victim's
session with the client begins after the attacker started his 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 <tt>nonce</tt> are used.</t>
<t>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
<xref target="insufficient_uri_validation"></xref>, <xref target="credential_leakage_referrer"></xref>,
<xref target="browser_history"></xref>, <xref target="mix_up"></xref>, and <xref target="open_redirection"></xref>.</t>
</section>
</section>

<section anchor="access_token_injection"><name>Access Token Injection</name>
<t>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.</t>
<t>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 makes up an authorization server response including
the leaked access token. Since the response includes the <tt>state</tt> 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.</t>

<section anchor="countermeasures-2"><name>Countermeasures</name>
<t>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.</t>
<t>In OpenID Connect, the attack can be mitigated, as the authorization response
additionally contains an ID Token containing the <tt>at_hash</tt> 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 <tt>nonce</tt> claim in the leaked ID Token will
(with a very high probability) contain a different value than the one expected
in the authorization response.</t>
<t>Note that further protection, like sender-constrained access tokens, is still
required to prevent attackers from using the access token at the resource
endpoint directly.</t>
<t>The recommendations in <xref target="implicit_grant_recommendation"></xref> follow from this.</t>
</section>
</section>

<section anchor="csrf"><name>Cross Site Request Forgery</name>
<t>An attacker might attempt to inject a request to the redirect 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).</t>

<section anchor="csrf_countermeasures"><name>Countermeasures</name>
<t>The traditional countermeasure is that clients pass a random value, also
known as a CSRF Token, in the <tt>state</tt> parameter that links the request to
the redirect URI to the user agent session as described. This
countermeasure is described in detail in <xref target="RFC6819"></xref>, Section 5.3.5. The
same protection is provided by PKCE or the OpenID Connect <tt>nonce</tt> value.</t>
<t>When using PKCE instead of <tt>state</tt> or <tt>nonce</tt> for CSRF protection, it is
important to note that:</t>

<ul>
<li><t>Clients MUST ensure that the AS supports PKCE before using PKCE for
CSRF protection. If an authorization server does not support PKCE,
<tt>state</tt> or <tt>nonce</tt> MUST be used for CSRF protection.</t>
</li>
<li><t>If <tt>state</tt> is used for carrying application state, and integrity of
its contents is a concern, clients MUST protect <tt>state</tt> against
tampering and swapping. This can be achieved by binding the
contents of state to the browser session and/or signed/encrypted
state values as discussed in the now-expired draft <xref target="I-D.bradley-oauth-jwt-encoded-state"></xref>.</t>
</li>
</ul>
<t>The AS therefore MUST provide a way to detect their support for PKCE. Using AS
metadata according to <xref target="RFC8414"></xref> is RECOMMENDED, but AS MAY instead provide a
deployment-specific way to ensure or determine PKCE support.</t>
<t>PKCE provides robust protection against CSRF attacks even in presence of an that
can read the authorization response (see Attacker A3 in <xref target="secmodel"></xref>). When
<tt>state</tt> is used or an ID Token is returned in the authorization response (e.g.,
<tt>response_type=code+id_token</tt>), the attacker either learns the <tt>state</tt> value and
can replay it into the forged authorization response, or can extract the <tt>nonce</tt>
from the ID Token and use it in a new request to the authorization server to
mint an ID Token with the same <tt>nonce</tt>. The new ID Token can then be used for
the CSRF attack.</t>
</section>
</section>

<section anchor="pkce-downgrade-attack"><name>PKCE Downgrade Attack</name>
<t>An authorization server that supports PKCE but does not make its use mandatory for
all flows can be susceptible to a PKCE downgrade attack.</t>
<t>The first prerequisite for this attack is that there is an attacker-controllable
flag in the authorization request that enables or disables PKCE for the
particular flow. The presence or absence of the <tt>code_challenge</tt> parameter lends
itself for this purpose, i.e., the AS enables and enforces PKCE if this
parameter is present in the authorization request, but does not enforce PKCE if
the parameter is missing.</t>
<t>The second prerequisite for this attack is that the client is not using <tt>state</tt>
at all (e.g., because the client relies on PKCE for CSRF prevention) or that the
client is not checking <tt>state</tt> correctly.</t>
<t>Roughly speaking, this attack is a variant of a CSRF attack. The attacker
achieves the same goal as in the attack described in <xref target="csrf"></xref>: The attacker injects an
authorization code (and with that, an access token) that is bound to the attacker's
resources into a session between his victim and the client.</t>

<section anchor="attack-description-2"><name>Attack Description</name>

<ol>
<li><t>The user has started an OAuth session using some client at an AS. In the
authorization request, the client has set the parameter
<tt>code_challenge=sha256(abc)</tt> as the PKCE code challenge. The client is now
waiting to receive the authorization response from the user's browse.</t>
</li>
<li><t>To conduct the attack, the attacker uses his own device to start an
authorization flow with the targeted client. The client now uses another
PKCE code challenge, say <tt>code_challenge=sha256(xyz)</tt>, in the authorization
request. The attacker intercepts the request and removes the entire
<tt>code_challenge</tt> parameter from the request. Since this step is performed on
the attacker's device, the attacker has full access to the request contents,
for example using browser debug tools.</t>
</li>
<li><t>If the authorization server allows for flows without PKCE, it will create a
code that is not bound to any PKCE code challenge.</t>
</li>
<li><t>The attacker now redirects the user's browser to an authorization response
URL that contains the code for the attacker's session with the AS.</t>
</li>
<li><t>The user's browser sends the authorization code to the client, which will
now try to redeem the code for an access token at the AS. The client will
send <tt>code_verifier=abc</tt> as the PKCE code verifier in the token request.</t>
</li>
<li><t>Since the authorization server sees that this code is not bound to any PKCE
code challenge, it will not check the presence or contents of the
<tt>code_verifier</tt> parameter. It will issue an access token that belongs to the
attacker's resource to the client under the user's control.</t>
</li>
</ol>
</section>

<section anchor="pkce_downgrade_countermeasures"><name>Countermeasures</name>
<t>Using <tt>state</tt> properly would prevent this attack. However, practice has shown
that many OAuth clients do not use or check <tt>state</tt> properly.</t>
<t>Therefore, ASs MUST take precautions against this threat.</t>
<t>Note that from the view of the AS, in the attack described above, a
<tt>code_verifier</tt> parameter is received at the token endpoint although no
<tt>code_challenge</tt> parameter was present in the authorization request for the
OAuth flow in which the authorization code was issued.</t>
<t>This fact can be used to mitigate this attack. <xref target="RFC7636"></xref> already mandates that</t>

<ul>
<li><t>an AS that supports PKCE MUST check whether a code challenge is contained in
the authorization request and bind this information to the code that is
issued; and</t>
</li>
<li><t>when a code arrives at the token endpoint, and there was a <tt>code_challenge</tt>
in the authorization request for which this code was issued, there must be a
valid <tt>code_verifier</tt> in the token request.</t>
</li>
</ul>
<t>Beyond this, to prevent PKCE downgrade attacks, the AS MUST ensure that
if there was no <tt>code_challenge</tt> in the authorization request, a request to
the token endpoint containing a <tt>code_verifier</tt> is rejected.</t>
<t>Note: ASs that mandate the use of PKCE in general or for particular clients
implicitly implement this security measure.</t>
</section>
</section>

<section anchor="access_token_leakage"><name>Access Token Leakage at the Resource Server</name>
<t>Access tokens can leak from a resource server under certain
circumstances.</t>

<section anchor="counterfeit_res_server"><name>Access Token Phishing by Counterfeit Resource Server</name>
<t>An attacker may setup his 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 <xref target="secmodel"></xref>). 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.</t>
<t>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 e-Mail, calendar, health,
or banking) and where the client is configured by a user or
administrator for a service that this user or company uses.</t>
</section>

<section anchor="comp_res_server"><name>Compromised Resource Server</name>
<t>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 of the respective server.</t>
<t>If the attacker were able to gain full control, including shell
access, 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.</t>
<t>Preventing server breaches by hardening and monitoring server systems
is considered a standard operational procedure and, therefore, out of
the scope of this document. This section focuses on the impact of
OAuth-related breaches and the replaying of captured access tokens.</t>
<t>The following measures should be taken into account by implementers in
order to cope with access token replay by malicious actors:</t>

<ul>
<li><t>Sender-constrained access tokens, as described in <xref target="pop_tokens"></xref>,
SHOULD be used to prevent the attacker from replaying the access
tokens on other resource servers. Depending on the severity of the
penetration, sender-constrained access tokens will also prevent
replay on the compromised system.</t>
</li>
<li><t>Audience restriction as described in <xref target="aud_restriction"></xref> SHOULD be
used to prevent replay of captured access tokens on other resource
servers.</t>
</li>
<li><t>The resource server MUST treat access tokens like any other
credentials. It is considered good practice to not log them and
not store them in plain text.</t>
</li>
</ul>
<t>The first and second recommendation also apply to other scenarios
where access tokens leak (see Attacker A5 in <xref target="secmodel"></xref>).</t>
</section>
</section>

<section anchor="misuse-of-stolen-access-tokens"><name>Misuse of Stolen Access Tokens</name>
<t>Access tokens can be stolen by an attacker in various ways, for example,
via the attacks described in <xref target="insufficient_uri_validation"></xref>,
<xref target="credential_leakage_referrer"></xref>, <xref target="browser_history"></xref>, <xref target="mix_up"></xref> and
<xref target="access_token_leakage"></xref>. 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-constrained and audience-restricted as described
in the following.</t>

<section anchor="pop_tokens"><name>Sender-Constrained Access Tokens</name>
<t>As the name suggests, sender-constrained access tokens scope the
applicability of an access token to a certain sender. This sender is
obliged to demonstrate knowledge of a certain secret as prerequisite
for the acceptance of that token at a resource server.</t>
<t>A typical flow looks like this:</t>

<ol>
<li><t>The authorization server associates data with the access token
that binds this particular token to a certain client. The binding
can utilize the client identity, but in most cases the AS utilizes
key material (or data derived from the key material) known to the
client.</t>
</li>
<li><t>This key material must be distributed somehow. Either the key
material already exists before the AS creates the binding or the
AS creates ephemeral keys. The way pre-existing key material is
distributed varies among the different approaches. For example,
X.509 Certificates can be used, in which case the distribution
happens explicitly during the enrollment process. Or the key
material is created and distributed at the TLS layer, in which
case it might automatically happen during the setup of a TLS
connection.</t>
</li>
<li><t>The RS must implement the actual proof of possession check. This
is typically done on the application level, often tied to specific
material provided by transport layer (e.g., TLS). The RS must also
ensure that replay of the proof of possession is not possible.</t>
</li>
</ol>
<t>Two methods for sender-constrained access tokens using proof-of-possession have
been defined by the OAuth working group:</t>

<ul>
<li><t><strong>OAuth 2.0 Mutual-TLS Client Authentication and Certificate-Bound
Access Tokens</strong> (<xref target="RFC8705"></xref>): The approach as specified in this
document allows the use of mutual TLS (mTLS) for both client
authentication and sender-constrained access tokens. For the
purpose of sender-constrained access tokens, the client is
identified towards the resource server by the fingerprint of its
public key. During processing of an access token request, the
authorization server obtains the client's public key from the TLS
stack and associates its fingerprint with the respective access
tokens. The resource server in the same way obtains the public key
from the TLS stack and compares its fingerprint with the
fingerprint associated with the access token.</t>
</li>
<li><t><strong>DPoP</strong> (<xref target="I-D.ietf-oauth-dpop"></xref>): DPoP (Demonstration of
Proof-of-Possession at the Application Layer) outlines an
application-level sender-constraining for access and refresh
tokens that can be used in cases where neither mTLS nor OAuth
Token Binding (see below) are available. It uses
proof-of-possession based on a public/private key pair and
application-level signing. DPoP can be used with public clients
and, in case of confidential clients, can be combined with any
client authentication method.</t>
</li>
</ul>
<t>For reference, other approaches have been discussed as well but the relevant
drafts are now expired:</t>

<ul>
<li><t><strong>OAuth Token Binding</strong> (<xref target="I-D.ietf-oauth-token-binding"></xref>): In this approach, an access
token is, via the token binding ID, bound to key
material representing a long term association between a client and
a certain TLS host. Negotiation of the key material and proof of
possession in the context of a TLS handshake is taken care of by
the TLS stack. The client needs to determine the token binding ID
of the target resource server and pass this data to the access
token request. The authorization server then associates the access
token with this ID. The resource server checks on every invocation
that the token binding ID of the active TLS connection and the
token binding ID of associated with the access token match. Since
all crypto-related functions are covered by the TLS stack, this
approach is very client developer friendly. As a prerequisite,
token binding as described in <xref target="RFC8473"></xref>
(including federated token bindings) must be supported on all ends
(client, authorization server, resource server).</t>
</li>
<li><t><strong>Signed HTTP Requests</strong> (<xref target="I-D.ietf-oauth-signed-http-request"></xref>):
This approach utilizes <xref target="I-D.ietf-oauth-pop-key-distribution"></xref> and
represents the elements of the signature in a JSON object. The
signature is built using JWS. The mechanism has built-in support
for signing of HTTP method, query parameters and headers. It also
incorporates a timestamp as basis for replay prevention.</t>
</li>
<li><t><strong>JWT Pop Tokens</strong> (<xref target="I-D.sakimura-oauth-jpop"></xref>): This draft
describes different ways to constrain access token usage, namely
TLS or request signing. Note: Since the authors of this draft
contributed the TLS-related proposal to <xref target="RFC8705"></xref>,
this document only considers the request signing part. For request
signing, the draft utilizes
<xref target="I-D.ietf-oauth-pop-key-distribution"></xref> and <xref target="RFC7800"></xref>. The
signature data is represented in a JWT and JWS is used for
signing. Replay prevention is provided by building the signature
over a server-provided nonce, client-provided nonce and a nonce
counter.</t>
</li>
</ul>
<t>At the time of writing, OAuth Mutual TLS is the most widely
implemented and the only standardized sender-constraining method.</t>
<t>Note that the security of sender-constrained tokens is undermined when
an attacker gets access to the token and the key material. This is, in
particular, the case for corrupted client software and cross-site
scripting attacks (when the client is running in the browser). If the
key material is protected in a hardware or software security module or
only indirectly accessible (like in a TLS stack), sender-constrained
tokens at least protect against a use of the token when the client is
offline, i.e., when the security module or interface is not available
to the attacker. This applies to access tokens as well as to refresh
tokens (see <xref target="refresh_token_protection"></xref>).</t>
</section>

<section anchor="aud_restriction"><name>Audience Restricted Access Tokens</name>
<t>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 SHOULD verify the intended audience. If the access token fails
the intended audience validation, the resource server MUST refuse to
serve the respective request.</t>
<t>In general, audience restrictions limit 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.</t>
<t>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.</t>
<t>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.</t>
<t>The client SHOULD tell the authorization server the intended
resource server. The proposed mechanism
<xref target="RFC8707"></xref> could be used or by encoding the
information in the scope value.</t>
<t>Instead of the URL, it is also possible to utilize the fingerprint of
the resource server's X.509 certificate as audience value. This
variant would also allow to detect 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.</t>
<t>Audience restriction may seem easier to use since it does not require
any crypto on the client side. Still, since every access token is
bound to a specific resource server, the client also needs to obtain a
single RS-specific access token when accessing several resource
servers. (Resource indicators, as specified in
<xref target="RFC8707"></xref>, can help to achieve this.)
<xref target="I-D.ietf-oauth-token-binding"></xref> has the same property since different
token binding IDs must be associated with the access token. Using
<xref target="RFC8705"></xref>, on the other hand, allows a client to use the
access token at multiple resource servers.</t>
<t>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, has additional benefits beyond the scope of
token leakage prevention. It allows the authorization server to create
a different access token whose format and content is specifically minted
for the respective server. This has huge functional and privacy
advantages in deployments using structured access tokens.</t>
</section>

<section anchor="discussion-preventing-leakage-via-metadata"><name>Discussion: Preventing Leakage via Metadata</name>
<t>An authorization server could provide the client with additional
information about the locations where it is safe to use its access
tokens.</t>
<t>In the simplest form, this would require the AS to publish a list of
its known resource servers, illustrated in the following example using
a non-standard metadata parameter <tt>resource_servers</tt>:</t>

<artwork>HTTP/1.1 200 OK
Content-Type: application/json

{
  &quot;issuer&quot;:&quot;https://server.somesite.example&quot;,
  &quot;authorization_endpoint&quot;:
    &quot;https://server.somesite.example/authorize&quot;,
  &quot;resource_servers&quot;:[
    &quot;email.somesite.example&quot;,
    &quot;storage.somesite.example&quot;,
    &quot;video.somesite.example&quot;
  ]
  ...
} 
</artwork>
<t>The AS could also return the URL(s) an access token is good for in the
token response, illustrated by the example and non-standard return
parameter <tt>access_token_resource_server</tt>:</t>

<artwork>HTTP/1.1 200 OK
Content-Type: application/json;charset=UTF-8
Cache-Control: no-store
Pragma: no-cache

{
  &quot;access_token&quot;:&quot;2YotnFZFEjr1zCsicMWpAA&quot;,
  &quot;access_token_resource_server&quot;:
    &quot;https://hostedresource.somesite.example/path1&quot;,
...
}
</artwork>
<t>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 <xref target="oauth_security_ubc"></xref> and <xref target="oauth_security_cmu"></xref>) indicate a
large portion of client implementations do not or fail to properly
implement security controls, like <tt>state</tt> 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-related logic to those entities. Clearly, the client
has to contribute to the overall security. But there are alternative
countermeasures, as described before, that provide a
better balance between the involved parties.</t>
</section>
</section>

<section anchor="open_redirection"><name>Open Redirection</name>
<t>The following attacks can occur when an AS or client has an open redirector. An
open redirector is an endpoint that forwards a user’s browser to an arbitrary
URI obtained from a query parameter.  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.</t>

<section anchor="open_redirector_on_client"><name>Client as Open Redirector</name>
<t>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
<xref target="redir_uri_open_redir"></xref>. Another abuse case is to produce URLs that
appear to point to the client. This might trick users into trusting the URL
and follow it in their browser. This can be abused for phishing.</t>
<t>In order to prevent open redirection, clients should only redirect if
the target URLs are whitelisted or if the origin and integrity of a
request can be authenticated. Countermeasures against open redirection
are described by OWASP <xref target="owasp_redir"></xref>.</t>
</section>

<section anchor="authorization-server-as-open-redirector"><name>Authorization Server as Open Redirector</name>
<t>Just as with clients, attackers could try to utilize a user's trust in
the authorization server (and its URL in particular) for performing
phishing attacks. OAuth authorization servers regularly redirect users
to other web sites (the clients), but must do so in a safe way.</t>
<t><xref target="RFC6749"></xref>, Section 4.1.2.1, already prevents open redirects by
stating that the AS MUST NOT automatically redirect the user agent in case
of an invalid combination of <tt>client_id</tt> and <tt>redirect_uri</tt>.</t>
<t>However, an attacker could also utilize a correctly registered
redirect URI to perform phishing attacks. The attacker could, for
example, register a client via dynamic client registration <xref target="RFC7591"></xref>
and execute one of the following attacks:</t>

<ol>
<li><t>Intentionally send an erroneous authorization request, e.g., by
using an invalid scope value, thus instructing the AS to redirect the
user-agent to its phishing site.</t>
</li>
<li><t>Intentionally send a valid authorization request with <tt>client_id</tt>
and <tt>redirect_uri</tt> controlled by the attacker. After the user authenticates,
the AS prompts the user to provide consent to the request. If the user
notices an issue with the request and declines the request, the AS still
redirects the user agent to the phishing site. In this case, the user agent
will be redirected to the phishing site regardless of the action taken by
the user.</t>
</li>
<li><t>Intentionally send a valid silent authentication request (prompt=none)
with <tt>client_id</tt> and <tt>redirect_uri</tt> controlled by the attacker. In this case,
the AS will automatically redirect the user agent to the phishing site.</t>
</li>
</ol>
<t>The AS MUST take precautions to prevent these threats. The AS MUST always
authenticate the user first and, with the exception of the silent authentication
use case, prompt the user for credentials when needed, before redirecting the
user. Based on its risk assessment, the AS needs to decide whether it can trust
the redirect URI or not. It could take into account  URI analytics done
internally or through some external service to evaluate the credibility and
trustworthiness content behind the URI, and the source of the redirect URI and
other client data.</t>
<t>The AS SHOULD only automatically redirect the user agent if it trusts the
redirect URI.  If the URI is not trusted, the AS MAY inform the user and rely on
the user to make the correct decision.</t>
</section>
</section>

<section anchor="redirect_307"><name>307 Redirect</name>
<t>At the authorization endpoint, a typical protocol flow is that the AS
prompts the user to enter her credentials in a form that is then
submitted (using the HTTP POST method) back to the authorization
server. The AS checks the credentials and, if successful, redirects
the user agent to the client's redirection endpoint.</t>
<t>In <xref target="RFC6749"></xref>, the HTTP status code 302 is used for this purpose, but
&quot;any other method available via the user-agent to accomplish this
redirection is allowed&quot;. 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.</t>
<t>This discloses the sensitive credentials to the client. If the client
is malicious, it can use the credentials to impersonate the user
at the AS.</t>
<t>The behavior might be unexpected for developers, but is defined in
<xref target="RFC7231"></xref>, Section 6.4.7. This status code 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.</t>
<t>In the HTTP standard <xref target="RFC7231"></xref>, only the status code 303
unambigiously 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 and therefore to
reveal the user's credentials to the client. (In practice, however, most
user agents will only show this behaviour for 307 redirects.)</t>
<t>ASs 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 AS SHOULD use HTTP status code 303 (See Other).</t>
</section>

<section anchor="tls_terminating"><name>TLS Terminating Reverse Proxies</name>
<t>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.</t>
<t>This section highlights some attack angles of this deployment
architecture with relevance to OAuth and gives recommendations for
security controls.</t>
<t>In some situations, the reverse proxy needs to pass security-related
data to the upstream application servers for further processing.
Examples include the IP address of the request originator, token binding
ids, and authenticated TLS client certificates. This data is usually
passed in HTTP headers added to the upstream request. While the headers
are often custom, application-specific headers, standardized header
fields for client certificates and client certificate chains are defined
in <xref target="I-D.ietf-httpbis-client-cert-field"></xref>.</t>
<t>If the reverse proxy would pass 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 <tt>X-Forwarded-For</tt> 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 a whitelisted IP address to the header and render a IP
whitelist useless.</t>
<t>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.</t>
<t>If an attacker were able to get access to the internal network between
proxy and application server, the attacker could also try to
circumvent security controls in place. It is, therefore, essential to
ensure the authenticity of the communicating entities. Furthermore,
the communication link between reverse proxy and application server
MUST be protected against eavesdropping, injection, and replay of
messages.</t>
</section>

<section anchor="refresh_token_protection"><name>Refresh Token Protection</name>
<t>Refresh tokens are a convenient and user-friendly way to obtain new access
tokens after the expiration of access tokens. Refresh tokens 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.</t>

<section anchor="discussion-1"><name>Discussion</name>
<t>Refresh tokens are an attractive target for attackers, since they
represent the overall grant a resource owner delegated to a certain
client. 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.</t>
<t><xref target="RFC6749"></xref> already provides a robust baseline protection by requiring</t>

<ul>
<li><t>confidentiality of the refresh tokens in transit and storage,</t>
</li>
<li><t>the transmission of refresh tokens over TLS-protected connections between
authorization server and client,</t>
</li>
<li><t>the authorization server to maintain and check the binding of a refresh token
to a certain client and authentication of this client during token refresh,
if possible, and</t>
</li>
<li><t>that refresh tokens cannot be generated, modified, or guessed.</t>
</li>
</ul>
<t><xref target="RFC6749"></xref> also lays the foundation for further (implementation
specific) security measures, such as refresh token expiration and
revocation as well as refresh token rotation by defining respective
error codes and response behaviors.</t>
<t>This specification gives recommendations beyond the scope of
<xref target="RFC6749"></xref> and clarifications.</t>
</section>

<section anchor="recommendations-1"><name>Recommendations</name>
<t>Authorization servers SHOULD 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 refresh access tokens 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.</t>
<t>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.</t>
<t>For confidential clients, <xref target="RFC6749"></xref> already requires that refresh
tokens can only be used by the client for which they were issued.</t>
<t>Authorization server MUST utilize one of these methods to
detect refresh token replay by malicious actors for public clients:</t>

<ul>
<li><t><strong>Sender-constrained refresh tokens:</strong> the authorization server
cryptographically binds the refresh token to a certain client
instance, e.g., by utilizing <xref target="RFC8705"></xref> or <xref target="I-D.ietf-oauth-dpop"></xref>.</t>
</li>
<li><t><strong>Refresh token rotation:</strong> the authorization server issues a new
refresh token with every access token refresh response. The
previous refresh token is invalidated but information about the
relationship is retained by the authorization server. If a refresh
token is compromised and subsequently used by both the attacker
and the legitimate client, one of them will present an invalidated
refresh token, which will inform the authorization server of the
breach. The authorization server cannot determine which party
submitted the invalid refresh token, but it will revoke the
active refresh token. This stops the attack at the cost of forcing
the legitimate client to obtain a fresh authorization grant.</t>
<t>Implementation note: the grant to which a refresh token belongs
may be encoded into the refresh token itself. This can enable an
authorization server to efficiently determine the grant to which a
refresh token belongs, and by extension, all refresh tokens that
need to be revoked. Authorization servers MUST ensure the
integrity of the refresh token value in this case, for example,
using signatures.</t>
</li>
</ul>
<t>Authorization servers MAY revoke refresh tokens automatically in case
of a security event, such as:</t>

<ul>
<li><t>password change</t>
</li>
<li><t>logout at the authorization server</t>
</li>
</ul>
<t>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).</t>
</section>
</section>

<section anchor="client_impersonating"><name>Client Impersonating Resource Owner</name>
<t>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. If both options are possible,
depending on the details of the implementation, a client's identity may be
mistaken for the identity of a resource owner. For example, if a client is able
to choose its own <tt>client_id</tt> during registration with the authorization server,
a malicious client may set it to a value identifying an end-user (e.g., a <tt>sub</tt>
value if OpenID Connect is used). If the resource server cannot properly
distinguish between access tokens issued to clients and access tokens issued to
end-users, the client may then be able to access resource of the end-user.</t>

<section anchor="client_impersonating_countermeasures"><name>Countermeasures</name>
<t>Authorization servers SHOULD NOT allow clients to influence their <tt>client_id</tt> or
any other Claim if that can cause confusion with a genuine resource owner. Where
this cannot be avoided, authorization servers MUST provide other means for the
resource server to distinguish between access tokens authorized by a resource
owner from access tokens authorized by the client itself.</t>
</section>
</section>

<section anchor="clickjacking"><name>Clickjacking</name>
<t>As described in Section 4.4.1.9 of <xref target="RFC6819"></xref>, 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, 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-provided input field overlaid over the original user
interface. Clickjacking attacks can be designed such that users can hardly
notice the attack, for example using almost invisible iframes overlaid on top of
other elements.</t>
<t>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.</t>
<t>Authorization servers MUST prevent clickjacking attacks. Multiple
countermeasures are described in <xref target="RFC6819"></xref>, 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 <xref target="CSP-2"></xref> or greater.</t>
<t>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.</t>
<t>Using CSP allows authorization servers to specify multiple origins in
a single response header field and to constrain these using flexible
patterns (see <xref target="CSP-2"></xref> for details). Level 2 of this standard provides
a robust mechanism for protecting against clickjacking by using
policies that restrict the origin of frames (using <tt>frame-ancestors</tt>)
together with those that restrict the sources of scripts allowed to
execute on an HTML page (by using <tt>script-src</tt>). A non-normative
example of such a policy is shown in the following listing:</t>

<artwork>HTTP/1.1 200 OK
Content-Security-Policy: frame-ancestors https://ext.example.org:8000
Content-Security-Policy: script-src 'self'
X-Frame-Options: ALLOW-FROM https://ext.example.org:8000
...
</artwork>
<t>Because some user agents do not support <xref target="CSP-2"></xref>, this technique
SHOULD be combined with others, including those described in
<xref target="RFC6819"></xref>, unless such legacy user agents are explicitly unsupported
by the authorization server. Even in such cases, additional
countermeasures SHOULD still be employed.</t>
</section>

<section anchor="phishing_via_as"><name>Authorization Server Redirecting to Phishing Site</name>
<t>An attacker could utilize a correctly registered
redirect URI to perform phishing attacks.  The attacker could, for
example, register a client via dynamic client registration [RFC7591]
and execute one of the following attacks:</t>

<ol>
<li><t>Intentionally send an erroneous authorization request, e.g., by
using an invalid scope value, thus instructing the AS to redirect the
user-agent to its phishing site.</t>
</li>
<li><t>Intentionally send a valid authorization request with <tt>client_id</tt>
and <tt>redirect_uri</tt> controlled by the attacker. After the user authenticates,
the AS prompts the user to provide consent to the request. If the user
notices an issue with the request and declines the request, the AS still
redirects the user agent to the phishing site. In this case, the user agent
will be redirected to the phishing site regardless of the action taken by
the user.</t>
</li>
<li><t>Intentionally send a valid silent authentication request (prompt=none)
with <tt>client_id</tt> and <tt>redirect_uri</tt> controlled by the attacker. In this case,
the AS will automatically redirect the user agent to the phishing site.</t>
</li>
</ol>
<t>The AS MUST take precautions to prevent these threats. The AS MUST always
authenticate the user first and, with the exception of the silent authentication
use case, prompt the user for credentials when needed, before redirecting the
user. Based on its risk assessment, the AS needs to decide whether it can trust
the redirect URI or not. It could take into account  URI analytics done
internally or through some external service to evaluate the credibility and
trustworthiness content behind the URI, and the source of the redirect URI and
other client data.</t>
<t>The AS SHOULD only automatically redirect the user agent if it trusts the
redirect URI.  If the URI is not trusted, the AS MAY inform the user and rely on
the user to make the correct decision.</t>
</section>

<section anchor="rec_ibc"><name>Attacks on In-Browser Communication Flows</name>
<t>If the authorization response is sent with in-browser communication techniques
like postMessage <xref target="postmessage_api"></xref> instead of HTTP redirects, messages may
inadvertently be sent to malicious origins or injected from malicious origins.</t>

<section anchor="examples"><name>Examples</name>
<t>The following examples of attacks using in-browser communication are
described in <xref target="inbc_security_sso"></xref>:</t>

<section anchor="insufficient-limitation-of-receiver-origins"><name>Insufficient Limitation of Receiver Origins</name>
<t>When sending the authorization response or token response via
postMessage, the authorization server sends the response to the wildcard
origin &quot;*&quot; 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.</t>

<artwork>window.opener.postMessage(
  {
    code: &quot;ABC&quot;,
    state: &quot;123&quot;
  },
  &quot;*&quot; // any website in the opener window can receive the message
)
</artwork>
</section>

<section anchor="insufficient-uri-validation"><name>Insufficient URI Validation</name>
<t>When sending the authorization response or token response via
postMessage, the authorization server may not check the
receiver origin against the redirect URI and instead, for example, send
the response to an origin provided by an attacker. This is analogous to
the attack described in <xref target="insufficient_uri_validation"></xref>.</t>

<artwork>window.opener.postMessage(
  {
    code: &quot;ABC&quot;,
    state: &quot;123&quot;
  },
  &quot;https://attacker.example&quot; // attacker-provided value
)
</artwork>
</section>

<section anchor="injection-after-insufficient-validation-of-sender-origin"><name>Injection after Insufficient Validation of Sender Origin</name>
<t>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.</t>
<t>In the case of a maliciously injected authorization response, the attack
is a variant of the CSRF attacks described in <xref target="csrf"></xref>. The
countermeasures described in <xref target="csrf"></xref> apply to this attack as well.</t>
<t>In the case of a maliciously injected token response, sender-constrained
access tokens as described in <xref target="pop_tokens"></xref> may prevent the attack under
some circumstances, but additional countermeasures as described next are
generally required.</t>
</section>
</section>

<section anchor="recommendations-2"><name>Recommendations</name>
<t>When comparing client receiver origins against pre-registered origins,
authorization servers MUST utilize exact string matching as described in
<xref target="iuv_countermeasures"></xref>. Authorization servers MUST send postMessages to
trusted client receiver origins:</t>

<artwork>window.opener.postMessage(
  {
    code: &quot;ABC&quot;,
    state: &quot;123&quot;
  },
  &quot;https://client.example&quot; // use explicit client origin
)
</artwork>
<t>Wildcard origins like &quot;*&quot; 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 <xref target="insufficient_uri_validation"></xref>).</t>
<t>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:</t>

<artwork>window.addEventListener(&quot;message&quot;, (e) =&gt; {
  // validate exact AS origin
  if (e.origin === &quot;https://honest.as.example&quot;) {
    // process e.data.code and e.data.state
  }
})
</artwork>
<t>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 <xref target="rec_redirect"></xref> MUST be applied equally.</t>
</section>
</section>
</section>

<section anchor="Acknowledgements"><name>Acknowledgements</name>
<t>We would like to thank
Brock Allen,
Annabelle Richard Backman,
Dominick Baier,
Vittorio Bertocci,
Brian Campbell,
William Dennis,
George Fletscher,
Dick Hardt,
Joseph Heenan,
Pedram Hosseyni,
Phil Hunt,
Louis Jannett,
Jared Jennings,
Michael B. Jones,
Konstantin Lapine,
Neil Madden,
Christian Mainka,
Jim Manico,
Nov Matake,
Doug McDorman,
Vladislav Mladenov,
Karsten Meyer zu Selhausen,
Aaron Parecki,
Michael Peck,
Johan Peeters,
Nat Sakimura,
Guido Schmitz,
Jörg Schwenk,
Rifaat Shekh-Yusef,
Travis Spencer,
Petteri Stenius,
Tomek Stojecki,
Tim Wuertele,
David Waite and
Hans Zandbelt
 for their valuable feedback.</t>
</section>

<section anchor="IANA"><name>IANA Considerations</name>
<t>This draft makes no requests to IANA.</t>
</section>

<section anchor="Security"><name>Security Considerations</name>
<t>Security considerations are described in <xref target="recommendations"></xref>, <xref target="secmodel"></xref>, and <xref target="attacks_and_mitigations"></xref>.</t>
</section>

</middle>

<back>
<references><name>Normative References</name>
<xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.7521.xml"/>
<reference anchor="RFC8705" target="https://www.rfc-editor.org/info/rfc8705">
  <front>
    <title>&#xA;OAuth 2.0 Mutual-TLS Client Authentication and Certificate-Bound Access Tokens&#xA;</title>
    <author fullname="B. Campbell" initials="B." surname="Campbell">
      <organization></organization>
    </author>
    <author fullname="J. Bradley" initials="J." surname="Bradley">
      <organization></organization>
    </author>
    <author fullname="N. Sakimura" initials="N." surname="Sakimura">
      <organization></organization>
    </author>
    <author fullname="T. Lodderstedt" initials="T." surname="Lodderstedt">
      <organization></organization>
    </author>
    <date year="2020" month="February"></date>
  </front>
</reference>
<xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.8252.xml"/>
<reference anchor="OpenID.Core" target="https://openid.net/specs/openid-connect-core-1_0.html">
  <front>
    <title>OpenID Connect Core 1.0 incorporating errata set 1</title>
    <author fullname="Nat Sakimura" initials="N." surname="Sakimura">
      <organization>NRI</organization>
    </author>
    <author fullname="John Bradley" initials="J." surname="Bradley">
      <organization>Ping Identity</organization>
    </author>
    <author fullname="Mike Jones" initials="M." surname="Jones">
      <organization>Microsoft</organization>
    </author>
    <author fullname="Breno de Medeiros" initials="B." surname="de Medeiros">
      <organization>Google</organization>
    </author>
    <author fullname="Chuck Mortimore" initials="C." surname="Mortimore">
      <organization>Salesforce</organization>
    </author>
    <date year="2014" month="Nov" day="8"></date>
  </front>
</reference>
<reference anchor="OpenID.Discovery" target="https://openid.net/specs/openid-connect-discovery-1_0.html">
  <front>
    <title>OpenID Connect Discovery 1.0 incorporating errata set 1</title>
    <author fullname="Nat Sakimura" initials="N." surname="Sakimura">
      <organization>NRI</organization>
    </author>
    <author fullname="John Bradley" initials="J." surname="Bradley">
      <organization>Ping Identity</organization>
    </author>
    <author fullname="Mike Jones" initials="M." surname="Jones">
      <organization>Microsoft</organization>
    </author>
    <author fullname="Edmund Jay" initials="E." surname="Jay">
      <organization>Illumila</organization>
    </author>
    <date year="2014" month="Nov" day="8"></date>
  </front>
</reference>
<xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.6750.xml"/>
<xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.8414.xml"/>
<xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.7231.xml"/>
<xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.6819.xml"/>
<xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.6749.xml"/>
<xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.3986.xml"/>
<xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.7523.xml"/>
<xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.9068.xml"/>
</references>
<references><name>Informative References</name>
<reference anchor="OAuth.Post" target="http://openid.net/specs/oauth-v2-form-post-response-mode-1_0.html">
  <front>
    <title>OAuth 2.0 Form Post Response Mode</title>
    <author fullname="Mike Jones" initials="M." surname="Jones">
      <organization>Microsoft</organization>
    </author>
    <author fullname="Brian Campbell" initials="B." surname="Campbell">
      <organization>Ping Identity</organization>
    </author>
    <date year="2015" month="April" day="27"></date>
  </front>
</reference>
<reference anchor="arXiv.1704.08539" target="http://arxiv.org/abs/1704.08539/">
  <front>
    <title>The Web SSO Standard OpenID Connect: In-Depth Formal Security Analysis and Security Guidelines</title>
    <author fullname="Daniel Fett" initials="D." surname="Fett">
      <organization></organization>
    </author>
    <author fullname="Ralf Küsters" initials="R." surname="Küsters">
      <organization></organization>
    </author>
    <author fullname="Guido Schmitz" initials="G." surname="Schmitz">
      <organization></organization>
    </author>
    <date year="2017" month="April" day="27"></date>
  </front>
</reference>
<xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml-ids/reference.I-D.sakimura-oauth-jpop.xml"/>
<xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml-ids/reference.I-D.ietf-httpbis-client-cert-field.xml"/>
<reference anchor="CSP-2" target="https://www.w3.org/TR/CSP2">
  <front>
    <title>Content Security Policy Level 2</title>
    <author initials="M." surname="West"></author>
    <author initials="A." surname="Barth"></author>
    <author initials="D." surname="Veditz"></author>
    <date year="2015" month="July"></date>
  </front>
</reference>
<xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.7636.xml"/>
<reference anchor="webappsec-referrer-policy" target="https://w3c.github.io/webappsec-referrer-policy">
  <front>
    <title>Referrer Policy</title>
    <author initials="J." surname="Eisinger">
      <organization>Google Inc.</organization>
    </author>
    <author initials="E." surname="Stark">
      <organization>Google Inc.</organization>
    </author>
    <date year="2017" month="April" day="20"></date>
  </front>
</reference>
<xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.8174.xml"/>
<reference anchor="arXiv.1901.11520" target="http://arxiv.org/abs/1901.11520/">
  <front>
    <title>An Extensive Formal Security Analysis of the OpenID Financial-grade API</title>
    <author fullname="Daniel Fett" initials="D." surname="Fett">
      <organization></organization>
    </author>
    <author fullname="Pedram Hosseyni" initials="P." surname="Hosseyni">
      <organization></organization>
    </author>
    <author fullname="Ralf Küsters" initials="R." surname="Küsters">
      <organization></organization>
    </author>
    <date year="2019" month="January" day="31"></date>
  </front>
</reference>
<xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.7800.xml"/>
<xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml-ids/reference.I-D.ietf-oauth-dpop.xml"/>
<reference anchor="oauth_security_cmu" target="http://css.csail.mit.edu/6.858/2012/readings/oauth-sso.pdf">
  <front>
    <title>OAuth Demystified for Mobile Application Developers</title>
    <author fullname="Eric Chen" initials="E." surname="Chen">
      <organization abbrev="CMU">Carnegie Mellon University</organization>
    </author>
    <author fullname="Yutong Pei" initials="Y." surname="Pei">
      <organization abbrev="CMU">Carnegie Mellon University</organization>
    </author>
    <author fullname="Shuo Chen" initials="S." surname="Chen">
      <organization abbrev="MR">Microsoft Research</organization>
    </author>
    <author fullname="Yuan Tian" initials="Y." surname="Tian">
      <organization abbrev="CMU">Carnegie Mellon University</organization>
    </author>
    <author fullname="Robert Kotcher" initials="R." surname="Kotcher">
      <organization abbrev="CMU">Carnegie Mellon University</organization>
    </author>
    <author fullname="Patrick Tague" initials="P." surname="Tague">
      <organization abbrev="CMU">Carnegie Mellon University</organization>
    </author>
    <date year="2014" month="November"></date>
  </front>
  <format type="pdf" target="http://css.csail.mit.edu/6.858/2012/readings/oauth-sso.pdf"></format>
</reference>
<xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.7591.xml"/>
<xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.2119.xml"/>
<reference anchor="JARM" target="https://openid.net/specs/openid-financial-api-jarm.html">
  <front>
    <title>Financial-grade API: JWT Secured Authorization Response Mode for OAuth 2.0 (JARM)</title>
    <author fullname="Torsten Lodderstedt" initials="T." surname="Lodderstedt">
      <organization>Yes</organization>
    </author>
    <author fullname="Brian Campbell" initials="B." surname="Campbell">
      <organization>Ping</organization>
    </author>
    <date year="2018" month="Oct" day="17"></date>
  </front>
</reference>
<reference anchor="bug.chromium" target="https://bugs.chromium.org/p/chromium/issues/detail?id=168213/">
  <front>
    <title>Referer header includes URL fragment when opening link using New Tab</title>
    <author></author>
    <date></date>
  </front>
</reference>
<reference anchor="arXiv.1508.04324v2" target="http://arxiv.org/abs/1508.04324v2/">
  <front>
    <title>On the security of modern Single Sign-On Protocols: Second-Order Vulnerabilities in OpenID Connect</title>
    <author fullname="Vladislav Mladenov" initials="V." surname="Mladenov">
      <organization></organization>
    </author>
    <author fullname="Christian Mainka" initials="C." surname="Mainka">
      <organization></organization>
    </author>
    <author fullname="Jörg Schwenk" initials="J." surname="Schwenk">
      <organization></organization>
    </author>
    <date year="2016" month="January" day="7"></date>
  </front>
</reference>
<xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml-ids/reference.I-D.ietf-oauth-token-binding.xml"/>
<xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml-ids/reference.I-D.ietf-oauth-signed-http-request.xml"/>
<reference anchor="owasp_redir" target="https://cheatsheetseries.owasp.org/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.html">
  <front>
    <title>OWASP Cheat Sheet Series - Unvalidated Redirects and Forwards</title>
    <author></author>
    <date></date>
  </front>
</reference>
<xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.9101.xml"/>
<xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.9126.xml"/>
<reference anchor="subdomaintakeover" target="https://www.eecis.udel.edu/~hnw/paper/ccs16a.pdf">
  <front>
    <title>All Your DNS Records Point to Us: Understanding the Security Threats of Dangling DNS Records</title>
    <author fullname="Daiping Liu" initials="D." surname="Liu"></author>
    <author fullname="Shuai Hao" initials="S." surname="Hao"></author>
    <author fullname="Haining Wang" initials="H." surname="Wang"></author>
    <date year="2016" month="October" day="24"></date>
  </front>
</reference>
<xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.8473.xml"/>
<reference anchor="oauth_security_ubc" target="http://passwordresearch.com/papers/paper267.html">
  <front>
    <title>The Devil is in the (Implementation) Details: An Empirical Analysis of OAuth SSO Systems</title>
    <author fullname="San-Tsai Sun" initials="S.-T." surname="Sun">
      <organization abbrev="UBC">University of British Columbia</organization>
    </author>
    <author fullname="Konstantin Beznosov" initials="K." surname="Beznosov">
      <organization abbrev="UBC">University of British Columbia</organization>
    </author>
    <date year="2012" month="October"></date>
  </front>
  <format type="HTML" target="http://passwordresearch.com/papers/paper267.html"></format>
</reference>
<xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml-ids/reference.I-D.ietf-oauth-rar.xml"/>
<xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml-ids/reference.I-D.ietf-oauth-iss-auth-resp.xml"/>
<xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.8707.xml"/>
<reference anchor="WebAuthn" target="https://www.w3.org/TR/2019/REC-webauthn-1-20190304/">
  <front>
    <title>Web Authentication: An API for accessing Public Key Credentials Level 1</title>
    <author fullname="Dirk Balfanz" initials="D." surname="Balfanz">
      <organization>Google</organization>
    </author>
    <author fullname="Alexei Czeskis" initials="A." surname="Czeskis">
      <organization>Google</organization>
    </author>
    <author fullname="Jeff Hodges" initials="J." surname="Hodges">
      <organization>Google</organization>
    </author>
    <author fullname="J.C. Jones" initials="J.C." surname="Jones">
      <organization>Mozilla</organization>
    </author>
    <author fullname="Michael B. Jones" initials="M.B." surname="Jones">
      <organization>Microsoft</organization>
    </author>
    <author fullname="Akshay Kumar" initials="A." surname="Kumar">
      <organization>Microsoft</organization>
    </author>
    <author fullname="Angelo Liao" initials="A." surname="Liao">
      <organization>Microsoft</organization>
    </author>
    <author fullname="Rolf Lindemann" initials="R." surname="Lindemann">
      <organization>Nok Nok Labs</organization>
    </author>
    <author fullname="Emil Lundberg" initials="E." surname="Lundberg">
      <organization>Yubico</organization>
    </author>
    <date year="2019" month="March" day="04"></date>
  </front>
</reference>
<xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml-ids/reference.I-D.bradley-oauth-jwt-encoded-state.xml"/>
<xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml-ids/reference.I-D.ietf-oauth-pop-key-distribution.xml"/>
<reference anchor="oauth_security_jcs_14" target="https://www.doc.ic.ac.uk/~maffeis/papers/jcs14.pdf">
  <front>
    <title>Discovering concrete attacks on website authorization by formal analysis</title>
    <author fullname="Chetan Bansal" initials="C." surname="Bansal">
      <organization></organization>
    </author>
    <author fullname="Karthikeyan Bhargavan" initials="K." surname="Bhargavan">
      <organization></organization>
    </author>
    <author fullname="Antoine Delignat-Lavaud" initials="A." surname="Delignat-Lavaud">
      <organization></organization>
    </author>
    <author fullname="Sergio Maffeis" initials="S." surname="Maffeis">
      <organization></organization>
    </author>
    <date year="2014" month="April" day="23"></date>
  </front>
  <format type="pdf" target="https://www.doc.ic.ac.uk/~maffeis/papers/jcs14.pdf"></format>
</reference>
<reference anchor="postmessage_api" target="https://html.spec.whatwg.org/multipage/web-messaging.html#web-messaging">
  <front>
    <title>HTML Living Standard: Cross-document messaging</title>
    <author></author>
    <date></date>
  </front>
</reference>
<reference anchor="arXiv.1601.01229" target="http://arxiv.org/abs/1601.01229/">
  <front>
    <title>A Comprehensive Formal Security Analysis of OAuth 2.0</title>
    <author fullname="Daniel Fett" initials="D." surname="Fett">
      <organization></organization>
    </author>
    <author fullname="Ralf Küsters" initials="R." surname="Küsters">
      <organization></organization>
    </author>
    <author fullname="Guido Schmitz" initials="G." surname="Schmitz">
      <organization></organization>
    </author>
    <date year="2016" month="January" day="6"></date>
  </front>
</reference>
<reference anchor="inbc_security_sso" target="https://distinct-sso.com/paper.pdf">
  <front>
    <title>DISTINCT: Identity Theft using In-Browser Communications in Dual-Window Single Sign-On</title>
    <author fullname="Louis Jannett" initials="L." surname="Jannett">
      <organization></organization>
    </author>
    <author fullname="Vladislav Mladenov" initials="V." surname="Mladenov">
      <organization></organization>
    </author>
    <author fullname="Christian Mainka" initials="C." surname="Mainka">
      <organization></organization>
    </author>
    <author fullname="Jörg Schwenk" initials="J." surname="Schwenk">
      <organization></organization>
    </author>
    <date year="2022" month="November" day="7"></date>
  </front>
</reference>
<xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.9207.xml"/>
<reference anchor="WebCrypto" target="https://www.w3.org/TR/2017/REC-WebCryptoAPI-20170126/">
  <front>
    <title>Web Cryptography API</title>
    <author fullname="Mark Watson" initials="M." surname="Watson">
      <organization>Netflix</organization>
    </author>
    <date year="2017" month="January" day="26"></date>
  </front>
</reference>
</references>

<section anchor="document-history"><name>Document History</name>
<t>[[ To be removed from the final specification ]]</t>
<t>-22</t>

<ul>
<li><t>Added section on securing in-browser communication</t>
</li>
<li><t>Merged section on phishing via AS into existing section on open redirectors</t>
</li>
<li><t>Restructure and move section on sender-constrained tokens</t>
</li>
<li><t>Mention RFCs for Private Key JWK method</t>
</li>
</ul>
<t>-21</t>

<ul>
<li><t>Improved wording on phishing via AS</t>
</li>
</ul>
<t>-20</t>

<ul>
<li><t>Improved description of authorization code injection attacks and PKCE protection</t>
</li>
<li><t>Removed recommendation for MTLS in discussion (not reflected in actual Recommendations section)</t>
</li>
<li><t>Reworded &quot;placeholder&quot; text in security considerations.</t>
</li>
<li><t>Alphabetized list of names and fixed unicode problem</t>
</li>
<li><t>Explained Clickjacking</t>
</li>
<li><t>Explained Open Redirectors</t>
</li>
<li><t>Clarified references to attacker model by including a link to <xref target="secmodel"></xref></t>
</li>
<li><t>Clarified description of &quot;CSRF tokens&quot; and reference to RFC6819</t>
</li>
<li><t>Described that OIDC can prevent access token injection</t>
</li>
<li><t>Updated references</t>
</li>
</ul>
<t>-19</t>

<ul>
<li><t>Changed affiliation of Andrey Labunets</t>
</li>
<li><t>Editorial change to clarify the new recommendations for refresh tokens</t>
</li>
</ul>
<t>-18</t>

<ul>
<li><t>Fix editorial and spelling issues.</t>
</li>
<li><t>Change wording for disallowing HTTP redirect URIs.</t>
</li>
</ul>
<t>-17</t>

<ul>
<li><t>Make the use of metadata RECOMMENDED for both servers and clients</t>
</li>
<li><t>Make announcing PKCE support in metadata the RECOMMENDED way (before: either metadata or deployment-specific way)</t>
</li>
<li><t>AS also MUST NOT expose open redirectors.</t>
</li>
<li><t>Mention that attackers can collaborate.</t>
</li>
<li><t>Update recommendations regarding mix-up defense, building upon <xref target="I-D.ietf-oauth-iss-auth-resp"></xref>.</t>
</li>
<li><t>Improve description of mix-up attack.</t>
</li>
<li><t>Make HTTPS mandatory for most redirect URIs.</t>
</li>
</ul>
<t>-16</t>

<ul>
<li><t>Make MTLS a suggestion, not RECOMMENDED.</t>
</li>
<li><t>Add important requirements when using nonce for code injection protection.</t>
</li>
<li><t>Highlight requirements for refresh token sender-constraining.</t>
</li>
<li><t>Make PKCE a MUST for public clients.</t>
</li>
<li><t>Describe PKCE Downgrade Attacks and countermeasures.</t>
</li>
<li><t>Allow variable port numbers in localhost redirect URIs as in RFC8252, Section 7.3.</t>
</li>
</ul>
<t>-15</t>

<ul>
<li><t>Update reference to DPoP</t>
</li>
<li><t>Fix reference to RFC8414</t>
</li>
<li><t>Move to xml2rfcv3</t>
</li>
</ul>
<t>-14</t>

<ul>
<li><t>Added info about using CSP to prevent clickjacking</t>
</li>
<li><t>Changes from WGLC feedback</t>
</li>
<li><t>Editorial changes</t>
</li>
<li><t>AS MUST announce PKCE support either in metadata or using deployment-specific ways (before: SHOULD)</t>
</li>
</ul>
<t>-13</t>

<ul>
<li><t>Discourage use of Resource Owner Password Credentials Grant</t>
</li>
<li><t>Added text on client impersonating resource owner</t>
</li>
<li><t>Recommend asymmetric methods for client authentication</t>
</li>
<li><t>Encourage use of PKCE mode &quot;S256&quot;</t>
</li>
<li><t>PKCE may replace state for CSRF protection</t>
</li>
<li><t>AS SHOULD publish PKCE support</t>
</li>
<li><t>Cleaned up discussion on auth code injection</t>
</li>
<li><t>AS MUST support PKCE</t>
</li>
</ul>
<t>-12</t>

<ul>
<li><t>Added updated attacker model</t>
</li>
</ul>
<t>-11</t>

<ul>
<li><t>Adapted section 2.1.2 to outcome of consensus call</t>
</li>
<li><t>more text on refresh token inactivity and implementation note on refresh token replay detection via refresh token rotation</t>
</li>
</ul>
<t>-10</t>

<ul>
<li><t>incorporated feedback by Joseph Heenan</t>
</li>
<li><t>changed occurrences of SHALL to MUST</t>
</li>
<li><t>added text on lack of token/cert binding support tokens issued in
  the authorization response as justification to not recommend
  issuing tokens there at all</t>
</li>
<li><t>added requirement to authenticate clients during code exchange
  (PKCE or client credential) to 2.1.1.</t>
</li>
<li><t>added section on refresh tokens</t>
</li>
<li><t>editorial enhancements to 2.1.2 based on feedback</t>
</li>
</ul>
<t>-09</t>

<ul>
<li><t>changed text to recommend not to use implicit but code</t>
</li>
<li><t>added section on access token injection</t>
</li>
<li><t>reworked sections 3.1 through 3.3 to be more specific on implicit
  grant issues</t>
</li>
</ul>
<t>-08</t>

<ul>
<li><t>added recommendations re implicit and token injection</t>
</li>
<li><t>uppercased key words in Section 2 according to RFC 2119</t>
</li>
</ul>
<t>-07</t>

<ul>
<li><t>incorporated findings of Doug McDorman</t>
</li>
<li><t>added section on HTTP status codes for redirects</t>
</li>
<li><t>added new section on access token privilege restriction based on
  comments from Johan Peeters</t>
</li>
</ul>
<t>-06</t>

<ul>
<li><t>reworked section 3.8.1</t>
</li>
<li><t>incorporated Phil Hunt's feedback</t>
</li>
<li><t>reworked section on mix-up</t>
</li>
<li><t>extended section on code leakage via referrer header to also cover
  state leakage</t>
</li>
<li><t>added Daniel Fett as author</t>
</li>
<li><t>replaced text intended to inform WG discussion by recommendations
  to implementors</t>
</li>
<li><t>modified example URLs to conform to RFC 2606</t>
</li>
</ul>
<t>-05</t>

<ul>
<li><t>Completed sections on code leakage via referrer header, attacks in
  browser, mix-up, and CSRF</t>
</li>
<li><t>Reworked Code Injection Section</t>
</li>
<li><t>Added reference to OpenID Connect spec</t>
</li>
<li><t>removed refresh token leakage as respective considerations have
  been given in section 10.4 of RFC 6749</t>
</li>
<li><t>first version on open redirection</t>
</li>
<li><t>incorporated Christian Mainka's review feedback</t>
</li>
</ul>
<t>-04</t>

<ul>
<li><t>Restructured document for better readability</t>
</li>
<li><t>Added best practices on Token Leakage prevention</t>
</li>
</ul>
<t>-03</t>

<ul>
<li><t>Added section on Access Token Leakage at Resource Server</t>
</li>
<li><t>incorporated Brian Campbell's findings</t>
</li>
</ul>
<t>-02</t>

<ul>
<li><t>Folded Mix up and Access Token leakage through a bad AS into new
  section for dynamic OAuth threats</t>
</li>
<li><t>reworked dynamic OAuth section</t>
</li>
</ul>
<t>-01</t>

<ul>
<li><t>Added references to mitigation methods for token leakage</t>
</li>
<li><t>Added reference to Token Binding for Authorization Code</t>
</li>
<li><t>incorporated feedback of Phil Hunt</t>
</li>
<li><t>fixed numbering issue in attack descriptions in section 2</t>
</li>
</ul>
<t>-00 (WG document)</t>

<ul>
<li><t>turned the ID into a WG document and a BCP</t>
</li>
<li><t>Added federated app login as topic in Other Topics</t>
</li>
</ul>
</section>

</back>

</rfc>
