Key to the Kingdom: How I Found API Secrets Hiding in Plain Sight in JavaScript Files
A production JavaScript bundle contained hardcoded AWS access keys, a Stripe secret key and a MongoDB connection string. The author used the AWS keys to list S3 buckets and claimed access to customer data, EC2 and Lambda.
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 secrets such as cloud access keys and database credentials were hardcoded into a client-side JavaScript bundle that is publicly served.
Impact
The exposed keys could give full access to S3 buckets with customer data, read permissions on a production database, and the ability to start or stop EC2 instances and access Lambda functions.
What the attacker needed
Target serves a public JavaScript bundle; Bundle contains hardcoded secrets; No authentication needed to fetch the bundle
The fix
Secrets should be removed from client-side code and stored in a secrets manager or environment variables, with IAM roles used instead of long-lived access keys.
How it was found
- Collect URLs for the target from public archives and filter for JavaScript files.
- Download the JavaScript files and scan them with regular expressions for secret patterns.
- Find AWS keys, a Stripe key and a MongoDB URL in the main bundle.
- Configure the AWS CLI with the found keys and run identity and bucket listing commands.
- Use a script to list S3 bucket contents and check IAM, EC2, Lambda and RDS access.
- Download the source map and reconstruct the original source code.
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.
Developers sometimes put passwords and cloud keys directly into the JavaScript files that every visitor downloads. Anyone can open those files and read the keys, then use them to log in to the company's cloud account. Here the keys belonged to Amazon Web Services, the service that runs many companies' servers and storage.
What is Leaked secrets?
Keys, tokens or passwords left in public code, apps, logs or responses, that grant real access.