One SSRF Bug Away From Your AWS Credentials
The instance metadata service is the most valuable target in any EC2 compromise. IMDSv1 makes it reachable with a single unauthenticated request.
IMDSv1 returns instance role credentials without a token, so any SSRF vulnerability in an app on that instance becomes a credential theft. Enforce IMDSv2 with HttpTokens=required.
Every EC2 instance can fetch its own role credentials from 169.254.169.254. IMDSv1 answers a plain GET with the credentials JSON. An application with an SSRF vulnerability, a URL-preview feature, a webhook fetcher, an open redirect, can be made to request that address and return the body.
In This Guide
The mechanism
IMDSv2 changes the shape of the request
Why 93% still allow it
If it stays
4 Tips to Get Started
aws ec2 describe-instances --query 'Reservations[].Instances[].MetadataOptions' shows the mode per instance.
HttpTokens=required is the fix. optional means v1 still works.
The Capital One breach was exactly this: SSRF to IMDSv1, role credentials, 100M records.
Hop limit and tag protection are secondary. Required tokens is the control that matters.
Ready to Stop Worrying About Infra?
Knowledge is the first step. Get a free 1-hour diagnostic and see where your infrastructure leaks time, money, and focus.
Related Guides
Is My S3 Bucket Public? How to Check in One Command
One command tells you if your S3 bucket is public, and one curl proves it. The policy check shows intent, the anonymous request shows reality.
The Most Common AWS Misconfiguration (It Is One Line of Config)
Public buckets and Principal * policies cause most disclosed AWS incidents. Each is one line of config with account-wide blast radius. Here is the pattern.
Terraform State File Leak: Every Secret in Plaintext
terraform.tfstate stores database passwords, IAM keys and TLS private keys in plaintext. sensitive=true hides nothing. Here is how leaks happen and the check.
Docker Socket Mounted in a Container: Root on the Host, No Exploit Needed
A container with /var/run/docker.sock mounted controls the host daemon and can mount your entire filesystem. No kernel exploit required. Here is the mechanism and the check.
Ron Cohen — DevOps engineer & founder, roqy.io
Content reviewed by the roqy.io team. Our guides are based on publicly available data.
Disclaimer: This content is for informational and educational purposes only. It does not constitute professional advice or a guarantee of specific results. Infrastructure needs vary by team, stack, and stage. Consult a qualified engineer for advice tailored to your situation.
Frequently Asked Questions
What is IMDSv1 and why is it dangerous?
IMDSv1 is the instance metadata service that answers without a token. If an app has an SSRF bug, an attacker can read instance role credentials with one request. IMDSv2 requires a token fetch first, which blocks it. Datadog found 93% of EC2 instances still allow v1.
How does SSRF lead to AWS credentials?
The metadata service at 169.254.169.254 returns the instance role's temporary credentials at /latest/meta-data/iam/security-credentials/. IMDSv1 answers plain GETs, so an attacker who can make the app issue one request to that address receives the credentials in the response. IMDSv2 requires a PUT to obtain a token first, which SSRF payloads typically cannot do.
How do I enforce IMDSv2?
aws ec2 modify-instance-metadata-options --instance-id ID --http-tokens required --http-put-response-hop-limit 1. New instances should set it in the launch template. Then verify with describe-instances that no instance remains in optional mode.
Get the DevOps Ecosystem Behind You
One accountable engineer. Full platform behind him. Month-to-month, no lock-in.