OpenID Connect Vulnerabilities
OpenID Connect
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
.
OpenID Connect roles
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.
Protocol flow
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.
Authentication
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:
ID Token
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):
Authorization code flow
When using the authorization code flow, these additional requirements for the following ID token claims apply:
Implicit flow
When using the implicit flow, these additional requirements for the following ID token claims apply:
Hybrid flow
When using the hybrid flow, these additional requirements for the following ID token claims apply:
OpenID Connect endpoints
The OpenID Connect utilizes three endpoints:
Authorization endpoint
Token endpoint
UserInfo endpoint
Authorization 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:
OpenID Connect also uses the additional request parameters:
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
orid_token token
- values to use implicit flow.code id_token
,code token
orcode 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.
Token endpoint
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.
UserInfo 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.
Authorization Code Flow
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.
How it works
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:
Implicit Flow
The implicit flow returns all tokens to clients from the authorization endpoint and the token endpoint is not used.
How it works
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:
Hybrid Flow
The hybrid flow returns some tokens from the authorization endpoint and others from the token endpoint.
How it works
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.
Security issues in the OAuth2.0 protocol
Security issues with JSON Web Token
Security issues in the relying party
Improper handling of nonce claim
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.
Security issues in the OpenID provider
Try to discover the .well-known/openid-configuration
endpoint, according to the specification it contains useful information about different server configuration values.
Abusing WebFinger service
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
UserInfo endpoint: CORS misconfiguration
The UserInfo endpoint should support the use of Cross-origin resource sharing according to the specification.
SSRF via dynamic client registration
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 ofredirect_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 theredirect_uris
in order to complete the authorization flow, this will force the server to make a request to your malicioussector_identifier_uri
.request_uris
- An array of the allowedrequest_uris
for this client. Therequest_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 userequest_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 authorizationclient_uri
- URL of the home page of the client applicationpolicy_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.
SSRF via request_uri parameter
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
:
References
Last updated