Guides · Updated 2026-11-14
AWS access key (AKIA...) in my frontend JavaScript: what to do, and how to upload to S3 without it
Short answer: Yes, it's bad. An AKIA... string is the ID half of a long-term AWS access key for an IAM user. AWS says not to put access keys in application files, and the secret half is usually shipped right next to it, because the browser needs both to sign requests. With both, anyone can act as that IAM user with all of its permissions, for as long as the key stays active. Create a replacement key, deactivate the exposed one right away, check CloudTrail and your bill for activity you don't recognize, then delete it. For uploads, keep the key on your server and have a server route hand the browser a short-lived presigned URL for one file.
What an AKIA... string in your JS means
AWS access keys have two parts: an access key ID (like AKIAIOSFODNN7EXAMPLE) and a secret access key (a longer random string). AWS's IAM docs say both are used together to sign requests, and that access keys are long-term credentials for an IAM user or the root user. They keep working until someone deactivates or deletes them.
- AKIA... = a long-term access key ID. This is the one that shows up in vibe-coded apps.
- ASIA... = a temporary key ID from AWS STS. It only works with a session token and expires on its own, but it is still a credential and doesn't belong in public code.
- The ID alone can't sign requests. The problem is that code which signs requests in the browser (for example an S3 client created in a React component) needs the secret too, so the secret is almost always in the same file.
Whoever has both parts can do everything that IAM user is allowed to do. If the user was created with broad permissions "to make uploads work", that can mean reading every file in your buckets, deleting them, or starting paid resources on your account.
Why AI-built apps end up with AWS keys in the browser
Ask an AI tool to "let users upload a profile photo to S3" and the quickest working code creates an S3 client right in the page, with the access key and secret in an environment variable like VITE_AWS_ACCESS_KEY_ID or NEXT_PUBLIC_AWS_SECRET_ACCESS_KEY. Those prefixes mean "include this in the browser bundle", so both values ship to every visitor. More on that: https://leakyvibe.com/guides/is-my-vercel-app-leaking-environment-variables
AWS's own guidance is direct: don't put access keys or credential information in your application files, and prefer temporary credentials (such as IAM roles) over long-term access keys.
5-minute check: does my live site ship an AWS key?
- Open your live site in a private window.
- Open DevTools (F12 or right-click > Inspect), go to the Sources tab (Debugger in Firefox) and use "Search in all files" (Ctrl+Shift+F, or Cmd+Option+F on Mac).
- Search for AKIA, then ASIA. Then search for words like secretAccessKey, AWS_SECRET and aws_secret.
- Do the upload flow once with the Network tab open. If the browser sends requests to amazonaws.com with an Authorization header it built itself, it is signing with your keys. A presigned URL request has X-Amz-Signature in the query string instead and no key-signing code in your JS.
- Search your repo (including git history, if it was ever public) for AKIA too.
Or paste your URL in the free scan at the top of this page: it reads the HTML and JavaScript your site serves and flags AWS access key IDs (AKIA... and ASIA...) as a high-severity finding.
Found one? Do this, in this order
- In the IAM console, open Users, find the user that owns the key (the access key ID is listed under Security credentials), and create a new access key only if your server still needs one.
- Deactivate the exposed key right away. AWS's account-compromise guidance is to deactivate first and delete once you've confirmed nothing you need breaks.
- Open CloudTrail > Event history and look for activity from that key you don't recognize, especially new access keys, IAM users, roles or policies. Delete anything you didn't create.
- Check Billing and Cost Explorer for unexpected services or charges, in every region, not just the one you use.
- Shrink the IAM user's permissions to the minimum (for uploads: s3:PutObject on one bucket or folder), or better, move the server code to a role with temporary credentials.
- Delete the old key, remove it from your code and git history, and redeploy.
If AWS emailed you about an exposed key, follow that email too and reply in the AWS Support Center once you've done the steps. Full checklist for any leaked key: https://leakyvibe.com/guides/leaked-api-key-what-to-do
The right way to upload to S3 from the browser: presigned URLs
A presigned URL lets someone upload one object to your bucket without having any AWS credentials. Your server creates it with its own credentials, for a specific bucket, object key (file name) and HTTP method, and with an expiration time. The browser just sends the file to that URL.
- The browser asks your API route for an upload URL (send the file type and size, not a path).
- The server checks the user is logged in, checks type and size, and picks the object key itself, for example uploads/<user id>/<random id>.jpg, so users can't overwrite each other's files.
- The server generates a presigned PUT URL with a short expiration (a few minutes is plenty) and returns it.
- The browser uploads the file with a PUT to that URL. Your server saves the object key in your database.
Things AWS points out that matter here: a presigned URL is limited by the permissions of whoever created it, it works like a bearer token for anyone who has it, and it can be used more than once until it expires. If an object with the same key already exists, the upload replaces it. With the SDK or CLI the expiration can be up to 7 days, which is far longer than an upload needs.
A prompt you can give your AI tool
Remove all AWS credentials from client code. Find every place an AWS access key ID or secret (or an env var like VITE_AWS_* or NEXT_PUBLIC_AWS_*) is used or could reach the browser, and every S3 client created in client components. Replace browser uploads with a server route that checks the session, validates file type and size, picks the object key itself (uploads/<userId>/<random>), and returns a presigned PUT URL that expires in 5 minutes. The browser only uploads to that URL. Read AWS credentials only from server-only env vars. Don't print any key values. List the files you changed.
Sources
Official sources (checked 2026-11-14): AWS IAM, "Manage access keys for IAM users" (https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_access-keys.html): two-part keys, long-term credentials, don't put keys in application files, prefer temporary credentials, monitor with CloudTrail. AWS IAM, "IAM identifiers" (https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_identifiers.html): AKIA = access key, ASIA = temporary STS access key. AWS re:Post, "What can I do if I notice unauthorized activity in my AWS account?" (https://repost.aws/knowledge-center/potential-account-compromise): deactivate, verify, then delete; CloudTrail Event history; cost review. Amazon S3, "Download and upload objects with presigned URLs" (https://docs.aws.amazon.com/AmazonS3/latest/userguide/using-presigned-url.html) and "Uploading objects with presigned URLs" (https://docs.aws.amazon.com/AmazonS3/latest/userguide/PresignedUrlUploadObject.html): permissions of the creator, bearer-token behavior, reuse until expiry, overwrite on same key, expiration up to 7 days.