OpenID Connect Vulnerabilities
Last updated
Last updated
OpenID Connect is a simple identity layer on top of the OAuth 2.0 protocol. It enables clients to verify the identity of the end-user based on the authentication performed by an authorization server, as well as to obtain basic profile information about the end-user in an interoperable and REST-like manner.
OpenID Connect implements authentication as an extension to the OAuth 2.0 authorization process. Use of this extension is requested by clients by including the openid
scope value in the authorization request. Information about the authentication performed is returned in a JSON Web Token (JWT) called an ID token
.
In any OpenID Connect flow we can identify the following roles:
End-User
- human participant.
Relying Party (client)
- OAuth 2.0 client application requiring end-yser authentication and claims from an OpenID Provider.
OpenID Provider
- OAuth 2.0 authorization server that is capable of authenticating the end-user and providing claims to a Relying Party about the authentication event and the end-user.
The OpenID Connect protocol, in abstract, has the following flow:
The Replying Party (client) sends a request to the OpenID Provider.
The OpenID Provider authenticates the end-user and obtains authorization.
The OpenID Provider responds with an ID token and usually an access token.
The Replying Party (client) can send a request with the access token to the UserInfo endpoint.
The UserInfo endpoint returns claims about the end-user.
OpenID Connect performs authentication to log in the end-user or to determine that the end-user is already logged in. OpenID Connect returns the result of the authentication performed by the server to the client in a secure manner so that the client can rely on it. For this reason, the client is called Relying Party in this case.
Authentication can follow one of three paths:
The primary extension that OpenID Connect makes to OAuth 2.0 to enable end-users to be authenticated is the ID token data structure. The ID token is a security token that contains claims about the authentication of an end-user by an authorization server when using a client, and potentially other requested claims. The ID token is represented as a JSON Web Token (JWT) signed with a JSON Web Signature (JWS).
The following claims are used within the ID token for all OAuth 2.0 flows used by OpenID Connect (ID tokens may also contain other claims):
iss
Required
Issuer Identifier for the Issuer of the response. The iss value is a case sensitive URL using the https
scheme that contains scheme, host, and optionally, port number and path components and no query or fragment components.
sub
Required
Subject Identifier. The sub value is a case sensitive ASCII string with a length not exceed 255 characters. A locally unique and never reassigned identifier within the Issuer for the end-user, which is intended to be consumed by the client.
aud
Required
Audience(s) that this ID token is intended for. The aud value is an array of case sensitive strings (or a single case sensitive string when there is one audience). It contains the OAuth 2.0 client_id
of the Relying Party and may also contain identifiers for other audiences.
exp
Required
Expiration time.
iat
Required
Time at which the JWT was issued.
auth_time
Time when the end-user authentication occurred.
nonce
String value used to associate a client session with an ID token, and to mitigate replay attacks. The value is passed through unmodified from the authentication request to the ID token.
amr
Optional
Authentication Methods References. JSON array of strings that are identifiers for authentication methods used in the authentication. For instance, values might indicate that both password and OTP authentication methods were used.
When using the authorization code flow, these additional requirements for the following ID token claims apply:
at_hash
Optional
Access token hash value.
When using the implicit flow, these additional requirements for the following ID token claims apply:
nonce
Required
Use of the nonce claim is required for this flow.
at_hash
Required
Access token hash value; it may not be used when no access token is issued, which is the case for the response_type=id_token
.
When using the hybrid flow, these additional requirements for the following ID token claims apply:
nonce
Required
Use of the nonce claim is required for this flow.
at_hash
Required
Access token hash value; it may not be used when no access token is issued.
c_hash
Code hash value; it may not be used when no code is issued.
The OpenID Connect utilizes three endpoints:
Authorization endpoint
Token endpoint
UserInfo endpoint
The authorization endpoint performs authentication of the end-user. This is done by sending the user agent to the authorization server's authorization endpoint for authentication and authorization, using request parameters defined by OAuth 2.0 and additional parameters and parameter values defined by OpenID Connect.
The token endpoint is used with every authorization flow.
OpenID Connect uses the following OAuth 2.0 request parameters:
scope
Required
The scope of the access request. OpenID Connect requests must contain the openid
scope value.
response_type
Required
OAuth 2.0 response type value that determines the authorization processing flow to be used, including what parameters are returned from the endpoints used.
client_id
Required
OAuth 2.0 client identifier valid at the authorization server.
redirect_uri
Required
Redirection URI to which the response will be sent.
state
Recommended
Opaque value used to maintain state between the request and the callback. Typically, Cross-Site Request Forgery mitigation is done by cryptographically binding the value of this parameter with a browser cookie.
OpenID Connect also uses the additional request parameters:
nonce
Optional
String value used to associate a client session with an ID token, and to mitigate replay attacks.
display
Optional
ASCII string value that specifies how the authorization server displays the authentication and consent user interface pages to the end-user, see here.
prompt
Optional
Space delimited, case sensitive list of ASCII string values that specifies whether the authorization server prompts the end-user for reauthentication and consent, see here.
max_age
Optional
Maximum Authentication Age. Specifies the allowable elapsed time in seconds since the last time the end-user was actively authenticated by the OpenID Provider.
id_token_hint
Optional
ID token previously issued by the authorization server being passed as a hint about the end-user's current or past authenticated session with the client, see here.
login_hint
Optional
Hint to the authorization server about the login identifier the end-user might use to log in, see here.
How response_type works
The response_type
request parameter is used to inform the authorization server which flow type to use:
code
- value to use authorization code flow.
token
or id_token token
- values to use implicit flow.
code id_token
, code token
or code id_token token
- values to use hybrid flow.
How nonce works
The nonce
claim is used to associate a client session with an ID token, and to mitigate replay attacks. The value is passed through unmodified from the authentication request to the ID token. If ID token contains the nonce
claim, clients verify that this value is equal to the value of the nonce
parameter sent in the authentication request. In general, it works according to the following flow:
The client generates a secure random value and stores it as is, in clear text, in a HttpOnly session cookie.
The client use a cryptographic hash of the value as the nonce parameter and sends this as an authentication request parameter.
When ID token contains the nonce claim, the client pulls and removes the random value from persistent storage (in this case from cookie), hashes this value, and compares with the nonce claim in the ID token. If they do not match, the client refuses to establish identity.
See also Nonce Implementation Notes.
The token endpoint is used by relying party (client) to obtain an access token, an ID token, and optionally a refresh token. The token endpoint requires relying party (client) authentication and support several methods, details you can find here.
The token endpoint is used by the authorization code and the hybrid flow types.
When using the hybrid flow, the contents of an ID token returned from the Token Endpoint are the same as for an ID token returned from the authorization endpoint.
The UserInfo endpoint is an OAuth 2.0 protected resource that returns claims about the authenticated end-user. To obtain the requested claims about the end-user, the client makes a request to the UserInfo endpoint using an access token obtained through OpenID connect authentication. These claims are normally represented by a JSON object that contains a collection of name and value pairs for the claims. You can see a standard set of basic profile claims here.
The authorization code flow returns an authorization code to the client, which can then exchange it for an ID token and an access token directly.
Client prepares an authentication request containing the desired request parameters and sends the request to the authorization server (see also how the authorization server validates the authentication request). The request may look like this:
Authorization server authenticates the end-user and obtains end-user consent/authorization.
Authorization server sends the end-user back to the client with an authorization code:
Client requests a response using the authorization code at the token endpoint (see also additional information about client authentication and how the authorization server validates the token request). The request may look like this:
Client receives a response that contains an ID token and access token in the response body, validates the response and retrieves the end-user's subject identifier:
The implicit flow returns all tokens to clients from the authorization endpoint and the token endpoint is not used.
Client prepares an authentication request containing the desired request parameters and sends the request to the authorization server (see also how the authorization server validates the authentication request). The request may look like this:
Authorization server authenticates the end-user and obtains end-user consent/authorization.
Authorization server sends the end-user back to the client with an ID token and, if requested, an access token; client validates the authentication response and retrieves the end-user's subject identifier:
The hybrid flow returns some tokens from the authorization endpoint and others from the token endpoint.
Client prepares an authentication request containing the desired request parameters and sends the request to the authorization server (see also how the authorization server validates the authentication request). The request may look like this:
Authorization server authenticates the end-user and obtains end-user consent/authorization.
Authorization server sends the end-user back to the client with an authorization code and, depending on the response type, one or more additional parameters:
Client requests a response using the authorization code at the token endpoint (see also additional information about client authentication and how the authorization server validates the token request). The request may look like this:
Client receives a response that contains an ID token and access token in the response body, validates the response and retrieves the end-user's subject identifier.
If the nonce
claim is:
missing,
a static value that never changes,
present but not validated,
available to an attacker in cleartext on the client side,
the OpenID Connect flow is likely to be vulnerable to replay attack. To exploit this, you need obtain the authentication response and use this to establish identity.
Try to discover the .well-known/openid-configuration
endpoint, according to the specification it contains useful information about different server configuration values.
In order for an OpenID Connect relying party to utilize OpenID Connect services for an end-user, the replying party needs to know where the OpenID provider is. OpenID Connect uses WebFinger to locate the OpenID provider for an end-user. Details you can find in the specification.
The WebFinger service is available at the .well-known/webfinger
endpoint and allow you to get information about the users and resources used on the server. It can be used to validate that the "anonymous" user has an account on the server:
The rel
parameter should have a static value of http://openid.net/specs/connect/1.0/issuer
.
The resource
should contain a valid URL in one of the following forms:
http(s)://host/user
acct://user@host
The UserInfo endpoint should support the use of Cross-origin resource sharing according to the specification.
The OpenID Connect Dynamic Client Registration specification defines a standardized way of allowing client applications to register with the OpenID provider. If dynamic client registration is supported, the client application can register itself by sending a POST
request to a /register
endpoint. The registration request may look like this:
Some of these values are passed in via URL links and can be potentially vulnerable to SSRF.
Most servers do not resolve these URLs immediately when they receive a registration request. Instead, they just save these parameters and use them later during the OAuth authorization flow.
The following parameters are particularly interesting for SSRF attacks:
logo_uri
- URL that references a logo for the client application. After you register a client, you can try to call the OAuth authorization endpoint using your new "client_id". After the login, the server will ask you to approve the request and may display the image from the "logo_uri". If the server fetches the image by itself, the SSRF should be triggered by this step. Alternatively, the server may just include the logo via a client-side <img>
tag, which can lead to XSS.
jwks_uri
- URL for the client's JSON Web Key Set document. This key set is needed on the server for validating signed requests made to the token endpoint when using JWTs for client authentication. In order to test for SSRF in this parameter, register a new client application with a malicious "jwks_uri", perform the authorization process to obtain an authorization code for any user, and then fetch the token endpoint with body as in the request below. If vulnerable, the server should perform a server-to-server HTTP request to the supplied "jwks_uri" because it needs this key to check the validity of the "client_assertion" parameter in your request. This will probably only be a blind SSRF vulnerability though, as the server expects a proper JSON response.
sector_identifier_uri
- This URL references a file with a single JSON array of redirect_uri
values. If supported, the server may fetch this value as soon as you submit the dynamic registration request. If this is not fetched immediately, try to perform authorization for this client on the server. As it needs to know the redirect_uris
in order to complete the authorization flow, this will force the server to make a request to your malicious sector_identifier_uri
.
request_uris
- An array of the allowed request_uris
for this client. The request_uri
parameter may be supported on the authorization endpoint to provide a URL that contains a JWT with the request information, see also here. To exploit SSRF on the authorization endpoint, simply use request_uri
:
The following parameters also contain URLs, but are not normally used for issuing server-to-server requests. They are instead used for client-side redirection/referencing:
redirect_uri
- URLs that are used for redirecting clients after the authorization
client_uri
- URL of the home page of the client application
policy_uri
- URL that the relying party client application provides so that the end user can read about how their profile data will be used.
tos_uri
- URL that the relying party client provides so that the end user can read about the relying party's terms of service.
initiate_login_uri
- URI using the https scheme that a third party can use to initiate a login by the relying party. Also should be used for client-side redirection.
All parameters and their definitions you can find here.
The request_uri parameter is fetched by the server at the start of the authorization process (do not confuse this parameter with redirect_uri
).
Many servers do not allow arbitrary request_uri
values: they only allow whitelisted URLs that were pre-registered during the client registration process. But even if dynamic client registration is not enabled, or it requires authentication, you can try to bypass a validation and perform SSRF on the authorization endpoint by using request_uri
: