My AWS access key is in my frontend code. Now what?
An access key ID that starts with AKIA or ASIA is half of a credential, and its secret access key is almost always shipped beside it. With both, anyone who reads your JavaScript can call AWS as you: read your buckets, start servers on your bill, or create new users to keep their access. Fix it in this order.
How to fix it
- Deactivate the key before anything else. In the IAM console, open Users, choose the user that owns the key, open the Security credentials tab and, under Access keys, choose Actions → Deactivate. If the key belongs to the root user, it's under your account name → Security credentials instead. Deactivating is reversible, so do it now even if it breaks something. An
ASIAkey is temporary and can't be deactivated: it expires by itself. Until then, if it came from a role, cut it off from that role's Revoke sessions tab in IAM; if it came from a user's long-term key, deactivating that key ends it. - Check for use you didn't make. In CloudTrail, open Event history and filter by AWS access key with the key ID from the scan. Event history is per region, so switch through every region you use; IAM changes are logged in US East (N. Virginia). Look for new IAM users, roles or access keys, changed policies, and servers or functions you didn't create, in every region. Then open Billing and Cost Management and look for charges you can't explain. Event history covers only the last 90 days. If you have a CloudTrail trail or CloudTrail Lake, search that too; if you don't, turn on a trail now.
- Remove anything an attacker created, and open a case with AWS Support if you find charges or resources that aren't yours.
- Read your account's email and the AWS Health Dashboard for a notice that AWS found the key exposed. AWS may attach a quarantine policy to the user, which blocks some actions but doesn't revoke the key. Once you've finished steps 1 to 3, follow the notice to close it.
- Delete the key once nothing legitimate uses it. If your server runs on AWS, give it an IAM role instead of a key. If it needs a key, create a new one for that server only and store it as a server-side environment variable whose name does not start with
NEXT_PUBLIC_orVITE_. - Take AWS out of the browser. Move the call into a server route (a Next.js route handler or a serverless function) and have the browser call that route. If the browser has to talk to AWS itself, give it short-lived credentials from a Cognito identity pool, or a presigned S3 URL for uploads and downloads. Never a key.
- Redeploy and scan again to confirm the key is gone. If the scan finds a new key, it was exposed the same way, so go back to step 1.
Common questions
Is it safe if the bucket is private?
No. A private bucket keeps out people with no credentials. The key is a credential: whoever holds it gets whatever that user's permissions allow, private buckets included.
AWS says it quarantined the key. Am I done?
No. The quarantine policy limits some actions, but the key still works until you deactivate it, and it doesn't undo anything already done with it. Deactivate it yourself and check CloudTrail.
Why does the scan only show the key ID?
The scan matches the ID, which has a fixed shape. The secret access key is a random string with no prefix, so it can't be matched reliably, but it usually sits right next to the ID in the same file. Treat both as exposed.
Why is my grade an F?
Any leaked key gives the scan an F until it's gone, because anyone can use a key they can read.
Fixed it? Scan again to confirm.
Scan your app for leaks