SKY-S102 · Secrets
Secret exposed to code that runs in the browser
Code that runs in the browser is downloaded by every visitor, so anything in it is public. SKY-S102 reports a secret, or a reference to a server-only environment variable such as process.env.STRIPE_SECRET_KEY, in a file that is bundled for or served to the browser.
- Languages
- TypeScript/JavaScript, HTML, Vue, Svelte, Astro, and any file the secrets scan reads under a public folder
- Quality gate
- fails the gate on its own (full and diff scans). Any secret fails the gate, whatever the limits.
- Finding type
- review
- Catalog name
- Client-side secret exposure
Why it matters
A bundler copies the value into the JavaScript it ships, and anyone can read it with the browser's developer tools. A Stripe secret key or a database URL found this way lets a stranger charge cards, read customer data or delete records.
What Skylos flags
"use client"; import { useState } from "react"; const stripeKey = process.env.STRIPE_SECRET_KEY; export function PayButton({ amount }: { amount: number }) { const [busy, setBusy] = useState(false); async function pay() { setBusy(true); await fetch("https://api.stripe.com/v1/payment_intents", { method: "POST", headers: { Authorization: `Bearer ${stripeKey}` }, body: new URLSearchParams({ amount: String(amount), currency: "usd" }), }); setBusy(false); } return <button disabled={busy} onClick={pay}>Pay</button>;}What Skylos leaves alone
"use client"; import { loadStripe } from "@stripe/stripe-js"; const stripe = loadStripe(process.env.NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY!); export function PayButton({ clientSecret }: { clientSecret: string }) { async function pay() { const client = await stripe; await client?.confirmPayment({ clientSecret, confirmParams: {} }); } return <button onClick={pay}>Pay</button>;}Why Skylos leaves it alone
The component still runs in the browser, but it reads a publishable key, which Stripe designs to be public. The NEXT_PUBLIC_ prefix says the value is meant for the browser, and the rest of the name has no word such as SECRET, TOKEN or PASSWORD. KEY alone is not enough under a public prefix.
More languages
HTML
Flagged
<!doctype html><html> <head> <script src="https://js.stripe.com/v3/"></script> </head> <body> <button id="pay">Pay</button> <script> const stripe = Stripe("sk_live_51HandbookDemo0nly"); </script> </body></html>Not flagged
<!doctype html><html> <head> <script src="https://js.stripe.com/v3/"></script> </head> <body> <button id="pay">Pay</button> <script> const stripe = Stripe("pk_live_51HandbookDemo0nly"); </script> </body></html>Why Skylos leaves it alone
A publishable key (pk_live_…) is not a secret, so no secret pattern matches it. The secret key in the flagged page is a SKY-S101 match that Skylos reports as SKY-S102, CRITICAL, because the file sits under static/.
How Skylos decides
- Runs the secrets scan (
--secretsor-a) and decides for each file whether the browser loads it. A path containing/public/,/static/,/assets/,/.next/static/,/build/client/,/dist/client/or/out/always counts. - Otherwise, server paths do not count:
pages/api/,route.tsand the otherroute.*files underapp/, files with.server.in the name, and server output such as.next/server/ordist/server/. - Otherwise a file counts when it is named
client.*,browser.*,*.client.*or*.browser.*and is a JavaScript, TypeScript, Vue, Svelte, Astro or HTML file; when its path contains/frontend/,/client/,/dist/,/build/,/assets/,/.next/or/out/; or when it is a JavaScript or TypeScript file whose first statement is the"use client"directive. - In such a file, every SKY-S101 finding (a hardcoded key or password) is renamed SKY-S102 and keeps its severity.
- In JavaScript and TypeScript files it also parses the code and reports each read of
process.env.NAME,import.meta.env.NAMEand their aliases and destructured forms, as HIGH, when the name looks sensitive: it containsSECRET,TOKEN,PASSWORD,PASSWD,PRIVATE,CREDENTIAL,AUTHorKEY, or isDATABASE_URL,DB_URL,MONGODB_URI,MONGO_URIorREDIS_URL. - Under a public prefix (
NEXT_PUBLIC_,REACT_APP_,VITE_,NUXT_PUBLIC_,EXPO_PUBLIC_,PUBLIC_),KEYandAUTHno longer count, soNEXT_PUBLIC_MAPS_KEYis quiet whileNEXT_PUBLIC_API_SECRETis reported. - When the file is too large or too broken to parse completely and a sensitive name appears, it reports that the analysis was incomplete instead of staying silent.
How to fix it
Keep the secret on the server. Move the call that needs it into a server route or server action and let the browser call that route. If a secret has already shipped in a bundle, revoke it.
"use client"; import { useState } from "react"; Removed: const stripeKey = process.env.STRIPE_SECRET_KEY;Removed: export function PayButton({ amount }: { amount: number }) { const [busy, setBusy] = useState(false); async function pay() { setBusy(true);Removed: await fetch("https://api.stripe.com/v1/payment_intents", {Added: await fetch("/api/checkout", { method: "POST",Removed: headers: { Authorization: `Bearer ${stripeKey}` },Removed: body: new URLSearchParams({ amount: String(amount), currency: "usd" }),Added: body: JSON.stringify({ amount }), }); setBusy(false); } return <button disabled={busy} onClick={pay}>Pay</button>;}When it can be wrong
- Next.js only puts variables with the
NEXT_PUBLIC_prefix into the browser bundle, soprocess.env.STRIPE_SECRET_KEYin a client component is usuallyundefinedat run time rather than leaked. It is still reported: the code is broken either way, and other bundlers and build settings do inline it. - Any path that contains
/client/,/dist/,/build/or/frontend/counts as browser code, so a server-side package in a folder namedclientcan be reported. - A public variable whose name contains
SECRETorTOKENis reported even when the value is meant to be public, such as a CAPTCHA site token.
Seeing a case that isn't listed here? Report the wrong result so the rule can be fixed. Don't paste company code: describe the shape of it.
How to silence it
Mark a reviewed line with a real comment on the same line. A marker on the line above is not read.
TSX const stripeKey = process.env.STRIPE_SECRET_KEY; // skylos: ignore[SKY-S102] proxy[tool.skylos] ignore = ["SKY-S102"]has no effect on the secrets scan: its findings stay reported and still fail the gate.A baseline (
skylos baseline ., then--baseline) accepts existing findings by file and line. Revoke any secret that has shipped.