Skip to main content

SKY-S102 · Secrets

Secret exposed to code that runs in the browser

High

A server-only environment variable read in browser code is HIGH. A hardcoded secret found in a browser-loaded file keeps the severity SKY-S101 gave it, so a provider key such as a Stripe secret key is reported as CRITICAL.

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
Wrong result? Report itA false positive, a missed case or a confusing message: it goes privately to the founder.

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

app/checkout/PayButton.tsx · TSXReported on line 5
"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

app/checkout/PayButton.tsx · TSX
"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

static/checkout/index.html · HTMLReported on line 9
<!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

static/checkout/index.html · HTML
<!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

  1. Runs the secrets scan (--secrets or -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.
  2. Otherwise, server paths do not count: pages/api/, route.ts and the other route.* files under app/, files with .server. in the name, and server output such as .next/server/ or dist/server/.
  3. 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.
  4. In such a file, every SKY-S101 finding (a hardcoded key or password) is renamed SKY-S102 and keeps its severity.
  5. In JavaScript and TypeScript files it also parses the code and reports each read of process.env.NAME, import.meta.env.NAME and their aliases and destructured forms, as HIGH, when the name looks sensitive: it contains SECRET, TOKEN, PASSWORD, PASSWD, PRIVATE, CREDENTIAL, AUTH or KEY, or is DATABASE_URL, DB_URL, MONGODB_URI, MONGO_URI or REDIS_URL.
  6. Under a public prefix (NEXT_PUBLIC_, REACT_APP_, VITE_, NUXT_PUBLIC_, EXPO_PUBLIC_, PUBLIC_), KEY and AUTH no longer count, so NEXT_PUBLIC_MAPS_KEY is quiet while NEXT_PUBLIC_API_SECRET is reported.
  7. 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.

app/checkout/PayButton.tsx · TSX · the fix, against the flagged file
"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, so process.env.STRIPE_SECRET_KEY in a client component is usually undefined at 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 named client can be reported.
  • A public variable whose name contains SECRET or TOKEN is 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.

From the Skylos rule handbook, Skylos 5.8.0 (commit 5b880b0). All rules.