Symmetric Proof of
Possession for the OAuth Authorization Code GrantNomura Research Institute1-6-5 Marunouchi, Marunouchi Kitaguchi Bldg.Chiyoda-ku100-0005TokyoJapan+81-3-5533-2111n-sakimura@nri.co.jphttp://nat.sakimura.org/Ping IdentityCasilla 177, Sucursal TalaganteTalaganteRMChile+44 20 8133 3718ve7jtb@ve7jtb.comhttp://www.thread-safe.com/Google1600 Amphitheatre PkwyMountain ViewCA94043USA+1 650-253-0000naa@google.comhttp://google.com/
Security
OAuth Working GroupThe OAuth 2.0 public client utilizing
Authorization Code Grant (RFC 6749 - 4.1) is
susceptible to the code interception attack. This specification describes
a mechanism that acts as a control against this threat.Public clients in OAuth 2.0 are
susceptible to the authorization code interception attack.
A malicious client intercepts the authorization code returned from the
authorization endpoint within communication path not protected by TLS,
such as inter-app communication, and uses it to obtain the access token.
This is possible on a public client as there is no client
secret associated for it to be sent to the token endpoint. This is
especially true on Smartphone applications where
the authorization code can be returned through custom URL Schemes
where the same scheme can be registered by multiple applications.
Under this scenario, the mitigation strategy stated in section
4.4.1 of does not work as they rely on
per-client instance secret or per client instance redirect URI.To mitigate this attack, this extension utilizes a dynamically created
cryptographically random key called 'code verifier'. The code verifier
is created for every authorization request and its transformed value,
called 'code challenge', is sent to the authorization server to obtain the
authorization code. The authorization code obtained is
then sent to the token endpoint with the 'code verifier' and the server
compares it with the previously received request code so that it can
perform the proof of possession of the 'code verifier' by the client. This
works as the mitigation since the attacker would not know this one-time
key.This specification adds additional parameters to the OAuth 2.0 Authorization and Access Token
Requests, shown in abstract form in Figure 1.
The client creates and records a secret named the code_verifier,
and derives a transformed version t(code_verifier)
(referred to as the code_challenge)
which is sent in the OAuth 2.0 Authorization Request, along with
the transformation method t.
The resource owner responds as usual, but records
t(code_verifier) and the transformation method.
The client then sends the code to the Access Token
Request as usual, but includes the code_verifier
secret generated at (A).
The authorization server transforms code_verifier
and compares it to t(code_verifier) from (B). Access is
denied if they are not equal.
An attacker who intercepts the Authorization Grant at (B) is unable to redeem it for an Access Token, as they are not in
possession of the code_verifier secret.
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL",
"SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY",
and "OPTIONAL" in this document are to be interpreted as
described in
Key words for use in RFCs to Indicate Requirement Levels .
If these words are used without being spelled in uppercase then
they are to be interpreted with their normal natural language meanings.
This specification uses the Augmented Backus-Naur Form (ABNF)
notation of .
BASE64URL(OCTETS) denotes the base64url encoding of OCTETS,
per producing a STRING.
BASE64URL-DECODE(STRING) denotes the base64url decoding of STRING,
per , producing a UTF-8 sequence of octets.
SHA256(STRING) denotes a SHA2 256bit hash of STRING.
UTF8(STRING) denotes the octets of the
UTF-8 representation of STRING.
ASCII(STRING) denotes the octets of the
ASCII representation of STRING.
The concatenation of two values A and B
is denoted as A || B.
In addition to the terms defined in OAuth
2.0, this specification defines the following terms:
A cryptographically random string that is used to correlate the
authorization request to the token request.
A challenge derived from the code verifier that is sent in the
authorization request, to be verified against later.
Base64 encoding using the URL- and filename-safe
character set defined in Section 5 of RFC 4648,
with all trailing '=' characters omitted (as permitted by Section 3.2)
and without the inclusion of any line breaks, whitespace, or other additional characters.
(See for notes on
implementing base64url encoding without padding.)
The client first creates a code verifier, code_verifier,
for each OAuth 2.0 Authorization Request,
in the following manner:code_verifier = high entropy cryptographic random sequence using the
url and filename safe Alphabet [A-Z] / [a-z] / [0-9] / "-" / "_" from Sec 5 of
RFC 4648, with length less than 128
characters.ABNF for code_verifier is as follows.NOTE: code verifier SHOULD have enough entropy to make it
impractical to guess the value.
It is RECOMMENDED that the output of a suitable random number generator
be used to create a 32-octet sequence. The Octet sequence is then BASE64URL encoded
to produce a 42-octet URL safe string to use as the code verifier.The client then creates a code challenge,
code_challenge,
derived from the code_verifier by using
one of the following transformations on
the code_verifier:
code_challenge = code_verifiercode_challenge = BASE64URL(SHA256(code_verifier))
It is RECOMMENDED to use the S256 transformation when possible.ABNF for code_challenge is as follows.The client sends the code challenge as part of the OAuth 2.0 Authorization
Request (Section 4.1.1.) using the following additional parameters:REQUIRED. Code challenge.OPTIONAL, defaults to plain. Code verifier transformation method,
S256 or plain. When the server issues the code in the Authorization Response,
it MUST associate the code_challenge and code_challenge_method values with
the code so it can be verified later.Typically, the code_challenge and code_challenge_method values are stored in
encrypted form in the code itself, but
could alternatively be stored on the server, associated with the
code. The server MUST NOT include the code_challenge
value in client requests in a form that other entities can extract.The exact method that the server uses to associate the code_challenge
with the issued code is out of scope for this specification.
If the server requires SPOP, and the client does not send
the code_challenge in the request,
the authorization endpoint MUST return the authorization error response with
error value set to invalid_request
and error_description or
error_uri whose content explaining the nature of error.
If the server supporting SPOP only supports S256,
and the client requests plain transformation,
the authorization endpoint MUST return the authorization error response with
error value set to unsupported_spop_transform.
The error_description or the response of
error_uri SHOULD explain the nature of error,
e.g., transform algorithm not supported.
If the client is capable of using S256,
it MUST use S256, as S256 is MTI on the server.
Clients MAY use plain only if they cannot support S256 for
some technical reason and knows that the server supports plain.
Upon receipt of the code, the client
sends the Access Token Request to the token endpoint. In addition to the
parameters defined in OAuth 2.0 Access Token Request (Section 4.1.3.), it
sends the following parameter:REQUIRED. Code verifierUpon receipt of the request at the Access Token endpoint, the server
verifies it by calculating the code challenge from received code_verifier and comparing it with the
previously associated code_challenge,
after first transforming it according to the code_challenge_method method specified by the client.If the code_challenge_method from
was S256, the received code_verifier
is first hashed with SHA-256 then compared to the base64url decoded code_challenge. i.e.,
SHA256(code_verifier )
== BASE64URL-DECODE(code_challenge).If the code_challenge_method from
was plain, they are compared
directly. i.e., code_challenge == code_verifier.If the values are equal, the Access Token endpoint MUST continue
processing as normal (as defined by OAuth 2.0). If the values are not equal, an
error response indicating invalid_grant as
described in section 5.2 of OAuth 2.0
MUST be returned.Server implementations of this specification MAY accept OAuth2.0 Clients that
do not implement this extension. If the code_verifier is not received from the client
in the Authorization Request, servers supporting backwards compatibility SHOULD revert
to a normal OAuth 2.0 protocol.As the OAuth 2.0 server
responses are unchanged by this specification, client
implementations of this specification do not need to know if the
server has implemented this specification or not,
and SHOULD send the additional parameters as defined in Section 3. to
all servers.This specification makes a registration request as follows:This specification registers the following parameters in the IANA
OAuth Parameters registry defined in OAuth
2.0.Parameter name: code_verifierParameter usage location: Access Token RequestChange controller: IESGSpecification document(s): this documentParameter name: code_challengeParameter usage location: Authorization RequestChange controller: IESGSpecification document(s): this documentParameter name: code_challenge_methodParameter usage location: Authorization RequestChange controller: IESGSpecification document(s): this documentThis specification establishes the SPOP Code Challenge Method registry.Additional code_challenge_method types for use with the authorization endpoint are
registered with a Specification Required ([RFC5226]) after a two-week
review period on the oauth-ext-review@ietf.org mailing list, on the
advice of one or more Designated Experts. However, to allow for the
allocation of values prior to publication, the Designated Expert(s)
may approve registration once they are satisfied that such a
specification will be published.Registration requests must be sent to the oauth-ext-review@ietf.org
mailing list for review and comment, with an appropriate subject
(e.g., "Request for SPOP code_challenge_method: example").Within the review period, the Designated Expert(s) will either
approve or deny the registration request, communicating this decision
to the review list and IANA. Denials should include an explanation
and, if applicable, suggestions as to how to make the request
successful.IANA must only accept registry updates from the Designated Expert(s)
and should direct all requests for registration to the review mailing
list.
The name requested (e.g., "example").
Because a core goal of this specification is for the resulting
representations to be compact, it is RECOMMENDED that the name be short
-- not to exceed 8 characters without a compelling reason to do so.
This name is case-sensitive.
Names may not match other registered names in a case-insensitive manner
unless the Designated Expert(s) state that there is a compelling reason
to allow an exception in this particular case.
For Standards Track RFCs, state "IESG". For others, give the name of the
responsible party. Other details (e.g., postal address, email address, home page
URI) may also be included.
Reference to the document(s) that specify the parameter, preferably including URI(s) that
can be used to retrieve copies of the document(s). An indication of the relevant
sections may also be included but is not required.
This specification registers the Code Challenge Method Parameter names defined in
in this registry.
Code Challenge Method Parameter Name: plain
Change Controller: IESG
Specification Document(s): of [[ this document ]]
Code Challenge Method Parameter Name: S256
Change Controller: IESG
Specification Document(s): of [[ this document ]]
The security model relies on the fact that the code verifier is not
learned or guessed by the attacker. It is vitally important to adhere to
this principle. As such, the code verifier has to be created in such a
manner that it is cryptographically random and has high entropy that it
is not practical for the attacker to guess.
It is RECOMMENDED that the output of a suitable random number generator be used to create a 32-octet sequence.
Clients MUST NOT try down grading the algorithm after trying S256 method.
If the server is SPOP compliant, then S256 method works.
If the server does not support SPOP, it does not generate error.
Only the time that the server returns that it does not support S256
is there is a MITM trying the algorithm downgrade attack.
S256 method protects against
eavesdroppers observing or intercepting the code_challenge.
If the plain method is used,
there is a chance that it will be observed by the attacker on the device.
The use of S256 protects against it.
If code_challenge is to be returned
inside authorization code to achieve a stateless server,
it has to be encrypted in such
a manner that only the server can decrypt and extract it.
Before starting the authorization process, the client SHOULD check if
the server supports this specification.
Confirmation of the server support may be obtained
out-of-band or through some other mechanisms such as the discovery
document in OpenID Connect
Discovery. The exact mechanism on how the client obtains this
information, or the action it takes as a result
is out of scope of this specification.
All the OAuth security analysis presented in
applies so readers SHOULD carefully follow it.The initial draft of this specification was created by the OpenID
AB/Connect Working Group of the OpenID Foundation, most notably by
the following people:Naveen Agarwal, GoogleDirk Balfanz, GoogleSergey BeryozkinJohn Bradley, Ping IdentityBrian Campbell, Ping IdentityWilliam Denniss, GoogleEduardo Gueiros, Jive CommunicationsPhil Hunt, OracleRyo Ito, mixiMichael B. Jones, MicrosoftTorsten Lodderstedt, Deutsche TelekomBreno de Medeiros, GooglePrateek Mishra, OracleAnthony Nadalin, MicrosoftAxel Nenker, Deutsche TelekomNat Sakimura, Nomura Research Institute-05Added IANA registry for code_challenge_method + fixed some broken
internal references.-04Added error response to authorization response.-03Added an abstract protocol diagram and explanation-02Copy edits-01Specified exactly two supported transformationsMoved discovery steps to security considerations.Incorporated readability comments by Eduardo Gueiros.Changed MUST in 3.1 to SHOULD.-00Initial IETF version.Coded Character Set -- 7-bit American Standard Code for Information InterchangeAmerican National Standards InstituteOpenID Connect Discovery 1.0Nomura Research Institute, Ltd.Ping IdentityMicrosoftIllumila
This appendix describes how to implement base64url encoding
and decoding functions without padding based upon standard
base64 encoding and decoding functions that do use padding.
To be concrete, example C# code implementing these functions
is shown below. Similar code could be used in other
languages.
As per the example code above, the number of '=' padding
characters that needs to be added to the end of a base64url
encoded string without padding to turn it into one with
padding is a deterministic function of the length of the
encoded string. Specifically,
if the length mod 4 is 0, no padding is added;
if the length mod 4 is 2, two '=' padding characters are added;
if the length mod 4 is 3, one '=' padding character is added;
if the length mod 4 is 1, the input is malformed.
An example correspondence between unencoded and encoded values
follows. The octet sequence below encodes into the string
below, which when decoded, reproduces the octet sequence.