Client-side code exposure
| Class | Secrets |
|---|---|
| CWE | CWE-540: Inclusion of Sensitive Information in Source Code; CWE-798: Use of Hard-coded Credentials |
| OWASP Top 10 | A02:2025 Security Misconfiguration |
| ATT&CK | T1594 Search Victim-Owned Websites |
| Affects | Front-end bundles built with Next.js, Vite or webpack; npm packages |
The JavaScript of a web page goes to every visitor's browser, and anything written into it can be read there. Client-side code exposure is sensitive information in that code: source handed to users that holds things they were never meant to see.1
Description
Build tools copy values into the bundle, such as an API key read from an environment variable. A source map lets anyone rebuild the original source from minified code code. Comments left in the code may name application files, keep outdated links or links users were never meant to visit, or hold leftover pieces of old code.2
Mechanism
Values copied in at build time
At build time, Next.js can write a value directly into the JavaScript bundle sent to the client, swapping each process.env.[variable] reference for the literal value.3 Only variables with the NEXT_PUBLIC_ prefix are inlined. Other variables exist only in the Node.js environment, and the browser cannot read them.3 Vite works the same way with the VITE_ prefix: in its example, VITE_SOME_KEY is exposed on the client and DB_PASSWORD is not.4
# .env
NEXT_PUBLIC_PAYMENTS_KEY=sk_live_example # copied into the bundle
PAYMENTS_KEY=sk_live_example # stays on the serverThe prefix decides where a value goes, and nothing checks what the value is. A secret key named with the public prefix reaches every browser. API keys and other sensitive data do not belong in VITE_* variables, because the build writes their values into the source code.4 Sensitive data exposed through environment variables is one of the weaknesses filed under security misconfiguration.5
Source maps
A source map links the minified, bundled code that runs in production back to the original source files, so that a crash in production can point to the line of the original file.6 An attacker can use the same file to rebuild the original code and study how it works, which exposes all of its logic and any secret written into it, such as an API key.6
The tools differ in their defaults. Next.js turns source maps off for production builds so that the source does not leak to the client. When productionBrowserSourceMaps is on, Next.js writes the maps next to the JavaScript files and serves them on request.7 In Vite, build.sourcemap defaults to false. The value true creates a separate map file, 'inline' adds the map to the end of the output file as a data URI, and 'hidden' behaves like true but leaves the source map comment out of the bundled files.8 Webpack's hidden-source-map likewise omits the reference comment and is meant for maps used only for error reporting.9
Impact
The direct consequence is that outsiders read application data.1 Every visitor can read a key in the bundle, and the source shows how the application works. Information gathered from a victim's own website feeds further reconnaissance and can lead to initial access.10
Not every key in a browser is a leak. Supabase divides its keys by place of use: the publishable key (sb_publishable_...) goes in anything shipped, because anyone can read it and it can reach only the data that row level security permits, while the secret key (sb_secret_...) bypasses row level security and must never leave the developer's control.11
Notable incidents
Claude Code source map (2026)
In March 2026 an Anthropic employee accidentally published the full source code of Claude Code, the company's AI programming tool, by leaving a source map file in a version uploaded to Anthropic's npm registry account. Researcher Chaofan Shou reported it on X early on Tuesday: "Claude code source code has been leaked via a map file in their npm registry!"6 An Anthropic spokesperson said no sensitive customer data or credentials were exposed, and called it a release packaging mistake caused by human error rather than a security breach.6
Claude Code is a command-line tool distributed through npm, so the case shows the source map mechanism outside a website and with no keys involved. Janca, quoted by CSO Online, called a source map file left in a package an incredibly common mistake.6
Detection
Open the site in a browser, view the Network tab and read the JavaScript files it loads. Search them for key-shaped strings and for the prefixes the framework exposes, NEXT_PUBLIC_ and VITE_. In the project, check that no variable with a public prefix holds a secret. For source maps, check whether the bundles carry a source map comment and whether a map file is served.
Prevention
Keep secrets out of public prefixes
Give a variable the public prefix only when its value is meant for every visitor. Calls that need a secret belong on a backend server or in a serverless or edge function.4 If a secret was already shipped, treat it as leaked and replace it (see Responding to a leaked API key).
Leave source maps out of production
In Next.js, leave productionBrowserSourceMaps unset or false.7 In Vite, leave build.sourcemap at its default of false.8 In webpack, set devtool to false for production builds that need the best performance, or to source-map when they need high-quality maps; hidden-source-map suits maps kept only for error reporting.9
// next.config.js
module.exports = {
productionBrowserSourceMaps: false, // the default
}For an npm package, add *.map to .npmignore.6
Prompt for a coding agent
List every environment variable in this project whose name starts with NEXT_PUBLIC_ or VITE_ (or the envPrefix set in the Vite config). For each one, say whether its value is a secret (a key that starts with sk_, a service role or sb_secret_ key, a password, a signing secret). For each secret, move its use into a server route or edge function and rename the variable without the public prefix. Then check the build configuration: productionBrowserSourceMaps in next.config.js, build.sourcemap in the Vite config and devtool in the webpack config must not publish source maps. List each file you changed and anything you were unsure about.
In SecFlash
On the Exposure page, SecFlash reports SF-EXP-101 for public source maps, SF-EXP-102 for unminified bundles, SF-EXP-201 for private-looking routes named in JavaScript and SF-EXP-202 for internal or staging addresses in JavaScript. A secret key in public JavaScript is SF-EXP-301, a token in public JavaScript, such as a Supabase service_role key, is SF-EXP-302, signing or secret logic in the browser is SF-EXP-107, and a secret key written into the HTML page is SF-EXP-304.
See also
- Privileged key in client-side code
- Exposed credentials in source code repositories
- Secrets management
- Attack surface
- Category: Secrets
References
- a b "CWE-540: Inclusion of Sensitive Information in Source Code". Common Weakness Enumeration. MITRE.
- back "CWE-615: Inclusion of Sensitive Information in Source Code Comments". Common Weakness Enumeration. MITRE.
- a b "How to use environment variables in Next.js". Next.js Docs. Vercel.
- a b c "Env Variables and Modes". Vite documentation.
- back "A02:2025 Security Misconfiguration". OWASP Top 10:2025. OWASP Foundation.
- a b c d e f "Anthropic employee error exposes Claude Code source". CSO Online (2026).
- a b "productionBrowserSourceMaps". Next.js Docs. Vercel.
- a b "Build Options". Vite documentation.
- a b "Devtool". webpack documentation.
- back "Search Victim-Owned Websites, T1594". MITRE ATT&CK.
- back "Understanding API keys". Supabase Docs.