Skip to content
cloudgrip

$ cat blog/ssrf-to-cloud-credentials.md

//Attack techniques

From SSRF to cloud credentials: how one URL field exposes a cloud account

How server-side request forgery in one URL field leads to stolen cloud credentials through the metadata service, and four layers that stop it.

  • Oct 21, 2026
  • 6 min read
  • Cloudgrip team

Server-side request forgery (SSRF) is a bug where an attacker gets your server to send a request to a destination the attacker chooses. In a cloud environment, the most damaging destination is the instance metadata service, because it hands out the credentials your server uses to talk to the rest of your cloud account.

The path from one to the other is short. A feature that fetches a URL for the user, such as an "import from URL" button, a webhook tester or a PDF generator, gets pointed at an internal address. The server fetches it and returns the result, and the attacker now holds working cloud credentials.

This post walks through that chain from a defender's point of view, then covers four layers of defense that break it.

The chain, step by step

The attack has four steps, and only the first needs a bug in your code.

  1. Find a feature that fetches URLs. Anything where the user supplies a URL and the server retrieves it.
  2. Point it at an internal address. The attacker cannot reach your internal network. Your server can.
  3. Read the metadata service. The server asks the metadata service for its own credentials and passes the answer back.
  4. Use the credentials. The attacker calls the cloud provider's API from their own machine, with your server's permissions.

Here is what step two looks like against a made-up application that imports contact lists from a URL.

output
POST /api/imports HTTP/1.1
Host: app.acme.test
Content-Type: application/json

{"source_url": "http://169.254.169.254/latest/meta-data/iam/security-credentials/"}

If the application is vulnerable, and the server is an AWS virtual machine that still accepts the older metadata protocol, the import preview shows the name of the role attached to the machine. One more request with that name added to the path returns something shaped like this.

output
{
  "AccessKeyId": "ASIAEXAMPLEEXAMPLE",
  "SecretAccessKey": "(redacted)",
  "Token": "(redacted)",
  "Expiration": "2026-10-21T18:00:00Z"
}

These credentials are temporary, but they work until they expire, and the attacker can repeat the request to get fresh ones. Whatever that role is allowed to do, the attacker can now do.

Why the metadata service is the target

The instance metadata service is an HTTP endpoint that a cloud virtual machine can reach at the link-local address 169.254.169.254. It exists so that software on the machine can learn about its environment and obtain short-lived credentials, without anyone storing long-lived keys on disk.

The weakness is in what the service trusts. In its original form on AWS, it answers any plain GET request that comes from the machine. It cannot tell whether the request came from your code doing its job or from your code being steered by an attacker. An SSRF bug is exactly the ability to make the machine send a GET request.

AWS, Google Cloud and Azure all run a metadata service at this address. Google Cloud and Azure require a specific request header (Metadata-Flavor: Google and Metadata: true). That stops the simplest attacks, because many SSRF bugs let the attacker control the URL and nothing else. AWS addressed the same problem with IMDSv2, covered below.

Why filtering the URL is not enough

The first fix most teams reach for is a blocklist that rejects any URL containing 169.254.169.254, localhost or a private IP range. Blocklists fail because there are many ways to arrive at the same destination.

  • Other spellings. http://2852039166/ is the metadata address written as a single decimal number. Many HTTP clients accept that form.
  • Redirects. The attacker submits a harmless-looking URL on a server they control, and that server replies with a redirect to the internal address. The filter checked the first URL. The HTTP client followed the second.
  • DNS tricks. A hostname the attacker controls can resolve to a public address when your filter looks it up, and to an internal address a moment later when the client connects. This is called DNS rebinding.

In all three cases the filter inspects text, while the request goes to whatever address the network finally connects to. A check that holds up has to look at the resolved IP address, at the moment of connection.

Four layers of defense

Each layer below stops the chain at a different step. Use all four, so that each covers for a gap in another.

1. Allowlist destinations in the application

Decide which destinations the feature needs and refuse the rest. For a webhook tester that only needs public HTTPS endpoints, allow only the https scheme, resolve the hostname yourself, and reject the request if the resolved address is loopback, private or link-local. Then open the connection to the address you just checked, so that a second DNS lookup cannot swap in a different one. Turn off automatic redirects, or run the same check again on every hop. Finally, show the user the parsed result or an error code, and nothing else from what the server received.

2. Require IMDSv2

IMDSv2 is the second version of the AWS metadata service. A caller must first obtain a session token with a PUT request that carries a special header, then present that token in a header on every later request. A typical SSRF bug can only make the server send a GET to a chosen URL, so it cannot complete that exchange. Setting the response hop limit to 1 also keeps the token from traveling beyond the machine itself.

output
resource "aws_instance" "app" {
  # ...
  metadata_options {
    http_tokens                 = "required"
    http_put_response_hop_limit = 1
  }
}

The important word is "required". While the older version is still accepted, the attack above still works. Containers that use the metadata service may need a higher hop limit, so test the change first.

3. Give the role least privilege

Stolen credentials are only as useful as the permissions behind them. An import service has no reason to read every storage bucket. Scope each machine's role to the resources it uses, so that a leak exposes little.

4. Control egress

Run URL-fetching features where the network itself limits what they can reach. Put them in their own subnet or container with no route to internal services. Block the metadata address for workloads that never need it. Send outbound traffic through a proxy that enforces the allowlist.

Finding it before someone else does

Search your codebase for every place the server makes a request to a user-supplied address. Then check each cloud account for machines that still accept the older metadata version, and for machine roles with more permissions than the job needs.

Cloudgrip Hydra proves an SSRF finding by confirming the internal request and then stopping. With an optional read-only cloud role, it also tests the IAM paths an over-permissioned role would open. Every attack path Hydra proves becomes a detection that Cerberus watches for in the telemetry you already collect, cloud audit logs included.

Key takeaways

  • SSRF lets an attacker send requests from your server. In the cloud, the metadata service turns that into credential theft.
  • URL blocklists fail against alternate address formats, redirects and DNS rebinding. Validate the resolved IP address at connection time.
  • Layer the defenses: an application allowlist, IMDSv2 set to required, least-privilege roles and egress controls.
  • Review every feature that fetches a user-supplied URL.

See what an attacker would find.

Give us a URL and two test logins. If there’s something to find, your first exploited findings land within 24 hours.

You talk to the people who build Hydra and Cerberus. No sales script.

or write to founders@cloudgrip.ai