# An API key in your front end is a published API key
*articles*
A key in the JavaScript that reaches the browser can be read by anyone. Here is how to tell public keys from secret ones, how V12 in vuln (Priority 3) sees them, and how to replace them and move the call to the server.


If a check flagged "Secrets in client JavaScript", this article covers why it matters and what to fix first.

The short answer: **a key inside the JavaScript that reaches the browser is not hidden. It is published.** Move powerful keys to the server and replace them. Some keys, though, are meant to be public. You do not need to fear all of them.

## Your front end is a photo you posted on social media

When you post a photo on social media, do you check the background? A card or a document left on the desk can end up in the corner of the frame. Anyone who sees it can zoom in, so even a small detail is readable. Deleting the post does not remove copies people saved.

The front end (the part of your site that runs inside the browser) is that photo. When someone opens your site, the browser receives the JavaScript files in full. Anyone can read them with the browser's developer tools.

An API key (a string used to call an outside service) tells that service "I am acting on this account's behalf." A key in your JavaScript is the card number caught in the corner of the photo. Anyone who looks can read it.

A build (the step that turns your code into files you can publish) may squeeze the code together, but the key stays intact. Shrinking a photo does not make what was in the frame unreadable.

## Keys that may be public, and keys that must not be

Not every key is dangerous. **Some keys are designed to sit in the browser.** They assume your data is protected by a separate mechanism.

Examples of keys meant to be public:

- Supabase's publishable key (starts with `sb_publishable_`) and anon key. Both identify the visitor as someone who is not logged in. Protection comes from RLS (settings that decide who can read each row)
- Stripe's publishable keys (start with `pk_live_` or `pk_test_`)
- Firebase's apiKey (starts with `AIza`). Protection comes from Security Rules and App Check. But if the same kind of key calls Gemini (Google's AI), every call is billed to you, so treat it as a secret (vuln reports it too)

Examples of keys that must never be in the browser:

- Supabase's secret key (starts with `sb_secret_`) and service_role key (keys that act as an administrator). They bypass RLS and can read and write all data
- Stripe's secret keys (start with `sk_live_` or `rk_live_`)
- API keys for AI services such as OpenAI or Anthropic. Every call is billed to you
- GitHub, Slack, and AWS tokens (strings used instead of logging in), and private keys (keys used for cryptographic signing, starting with `-----BEGIN PRIVATE KEY-----`)

To tell them apart, ask **what the key can do**. If it only identifies your project, it is meant to be public. If it can do anything, or it costs money, it is a secret.

The official explanations are here.

- [Supabase's official API keys documentation (English)](https://supabase.com/docs/guides/api/api-keys)
- [Stripe's official API keys documentation (English)](https://docs.stripe.com/keys)
- [Firebase's official API keys documentation (English)](https://firebase.google.com/docs/projects/api-keys)

## Why keys end up in JavaScript

These are the usual cases.

- You asked an AI builder to "call the AI with this API key", and it wrote the key straight into the front-end code
- You put the key in an environment variable (a setting kept outside the code) but gave it a `VITE_` or `NEXT_PUBLIC_` prefix
- You added it for a quick test and published it as is

The second one is easy to miss. In Vite and Next.js, environment variables with those prefixes are **embedded in the JavaScript sent to the browser**. "It is in an environment variable" does not always mean it is safe.

The official explanations are here.

- [Vite's official environment variables documentation (English)](https://vite.dev/guide/env-and-mode)
- [Next.js's official environment variables documentation (English)](https://nextjs.org/docs/app/guides/environment-variables)

## How vuln shows it

In vuln ([a free service that checks a live site from its URL](/en/vuln)), this appears as V12 "Secrets in client JavaScript" (Area: Exposure, Priority 3).

The scope is fixed.

- Of the JavaScript files the page loads, it fetches up to two that are **served from the same site** (the first 2 MB of each)
- It looks for strings shaped like the "must not" keys above
- It also looks for long, random-looking strings right after names such as `SECRET`, `SERVICE_ROLE`, or `API_KEY`
- Keys meant to be public are not reported as findings. They appear separately as "Public keys detected (not a problem)"

The evidence shows the JavaScript URL and the position. **The key value is masked, keeping only the first and last four characters** (for example `sk_l****abcd`). Short values and private keys are masked completely. Showing the result to someone else does not leak the key.

Some things are not read. These are scripts written directly in the HTML and scripts loaded from another site. Files beyond the two it picks (names such as `main` or `index` come first) and files loaded only after a click are also out of scope. **A pass means "not found in what was read".**

Useful official references:

- [The Secrets Management Cheat Sheet from OWASP, a nonprofit for web security (English)](https://cheatsheetseries.owasp.org/cheatsheets/Secrets_Management_Cheat_Sheet.html)
- [The description of CWE-798, the category for credentials written into code (English)](https://cwe.mitre.org/data/definitions/798.html)

## Measured: this site

On November 29, 2026, we fetched `/ja`, `/ja/vuln`, and `/ja/audit` on `https://ismyappok.com` with curl (a command that downloads a URL) and counted the script tags (the parts of HTML that load or contain JavaScript).

On all three pages, the only JavaScript was written directly in the HTML. There were no separate JavaScript files, so V12 has no file to read on this site.

So we searched the whole HTML for the prefixes of the "must not" keys above. The one match was on `/ja/vuln`: the word "service_role" in the description of a check item. No key values were found.

This site makes every call that needs an outside API key on the server (Cloudflare Workers). It never needs to hand a key to the browser.

## How to fix it

First, replace the key. **Treat any secret key you have ever published as already out.** Deleting it from the code is not enough. If anyone saved your old JavaScript, the key still works.

Issue a new key in the service's dashboard and disable the old one. Check your bill and activity logs for anything you do not recognize.

Second, move the call to the server. The browser calls your own server, and the server holds the key and calls the outside service. Use something that runs on the server. For Supabase, that is Edge Functions. For Cloudflare, that is Workers. If you use an AI builder, you can ask it to "move this API key into a server-side function".

The official explanations are here.

- [Supabase's official Edge Functions documentation (English)](https://supabase.com/docs/guides/functions)
- [Cloudflare's official Workers documentation (English)](https://developers.cloudflare.com/workers/)

Third, check your environment variable names. Do not put `VITE_` or `NEXT_PUBLIC_` on secret values. Use those prefixes only for values meant to be public.

Keys meant to be public still need care. Always set up RLS for Supabase and Security Rules for Firebase. Even with a public key, protected data stays unreadable.

## Summary

Open your site in a browser, press F12 (Command + Option + I on a Mac) to open the developer tools, and look at "Sources". Search for `sk_live_`, `sb_secret_`, and `service_role`. If nothing comes up, you are done for today. If you also search for `sk-`, only check matches followed by a long run of letters and numbers. `sk-` also matches ordinary words.

If something does, replace that key first, then move the call to the server.

Your front end is a photo you posted on social media. You would not post a photo that anyone in the world can zoom into with a card number showing.

Once you separate public keys from secret ones, the area to worry about gets much smaller. Apps made with AI builders are exactly the ones worth one search before launch.

How to fix each item is covered on these pages.

- [Secrets in client JavaScript](/en/checks/client-secrets)
- [.env file exposure](/en/checks/env-file-exposure)
- [Source map exposure](/en/checks/source-map-exposure)

Related articles.

- [What happens when .env is open to the world](/en/articles/env-file-exposure)
- [What a public source map gives away](/en/articles/source-map-exposure)

When you have reviewed the settings, [run a vuln check](/en/vuln). You can also check your public pages and links before launch with [audit (a free service for checking pages and links before launch, no login required)](/en/audit).

This article was written by checking our own site. It does not include results from scanning anyone else's site. Numbers quoted here are the check's implementation conditions. Measured values appear only with the date and method noted above.

## Check your own site
Enter a URL and see what is missing before launch. Free, and no login required.
[Run the free check](https://ismyappok.com/en/audit)