Buried in JavaScript: How One Comment Led Me to a Production API Key
A production API key was left in a JavaScript comment, and an unauthenticated config endpoint was vulnerable to web cache poisoning via the X-Forwarded-Host header. An attacker could use the key to access account data and poison the cache to redirect users to a malicious API base.
infosecwriteups.com
Published on infosecwriteups.com
Free Link🎈
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.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the API key was committed in a comment and the config endpoint reflected the X-Forwarded-Host header into a cached response without validation.
Impact
The exposed key could allow access to production account data, and the cache poisoning could redirect users to an attacker-controlled API base, potentially leading to token exfiltration and session hijacking.
What the attacker needed
None for key discovery; ability to send custom headers
How it was found
- Enumerate subdomains and collect JavaScript URLs.
- Download JavaScript files and search for keywords like api, key, token, secret.
- Find a commented-out production API key.
- Verify the key against a read-only account endpoint.
- Discover an unauthenticated config endpoint that returns cached JSON.
- Send a request with a spoofed X-Forwarded-Host header and observe the cached response containing the attacker's host.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
A secret key for a production system was accidentally left in a comment inside a JavaScript file that anyone can download. Separately, a configuration endpoint that tells apps where to send API requests could be tricked into storing a malicious address, so users would be sent to the attacker's server.
What is Cache bugs?
A cache and the origin disagree about a request, so a poisoned response is served to everyone or a private page is stored as public.