Hardcoded Secrets

Credentials, signing keys or encryption keys embedded in source, config, client bundles or shipped binaries (CWE-798 / CWE-321 / CWE-540), so anyone who can read the artifact holds the secret.

How it works

A secret is “hardcoded” once its value lives in something that gets copied: a source file, a committed config, a Docker layer, a JS bundle, an APK/IPA, firmware. From there it is only as private as the least-protected copy. Three shapes recur:

ShapeTypical locationWhy it is worse than it looks
Fallback defaultprocess.env.JWT_SECRET \|\| "auth-secret-key"The fallback silently becomes the prod key when the env var is unset; scanners read it as dead dev code
Vendor/static credentialFirmware, appliances, mobile SDKsSame value across every install (“fleet-wide”), unrotatable by the customer
Client-shipped keyJS bundle, NEXT_PUBLIC_*, React Native bundle, APK stringsEvery visitor/downloader receives it; obfuscation only slows a reader

Encoding does not hide it: TruffleHog decodes Base64, UTF-16 and escaped-Unicode substrings, and notes GitHub push protection blocked AKIA… keys but not their Base64 form (QUtJQ…).

Techniques / where to look

  • JS bundles and meta-frameworks — Next.js only inlines NEXT_PUBLIC_* into the client bundle, but mis-prefixing or a populated env: {} in next.config.js exposes server vars; Vite has the same footgun. Storybook CVE-2025-68429 bundled .env values into published static builds (fixed in 7.6.21 / 8.6.15 / 9.1.17 / 10.1.10). See JavaScript Analysis.
  • Mobile binaries — decompile and grep strings; AI-assisted review of decompiled code found a Salesforce-backed customer DB password in Wyndham’s Android app and a near-identical one in Applebee’s within two weeks. Advisories: VitaFit Android hardcoded API keys (CVE-2026-54374), AM CLUB hard-coded MQTT creds (CVE-2026-103906), GV-Access/GV-Cloud API keys in app packages. React Native “fake” keys still ship plaintext in the iOS bundle. See Android App Security and iOS App Security.
  • Signing keys — a hardcoded JWT/HMAC/cookie key is an auth bypass, not an info leak:
    // anti-pattern seen in Tensei (CVE-2026-129552)
    const secret = process.env.JWT_SECRET || 'auth-secret-key';
    Tensei through 0.11.5 (@tensei/auth) falls back to 'auth-secret-key' when JWT_SECRET is unset; tokens with arbitrary user IDs pass populateContextFromToken (CWE-1394, CVSS 4.0 9.3) (VulnCheck). BISHENG < 3.0.0 shipped a default jwt_secret for AuthJwt: an offline-forged HS256 token naming user_id 1 with the admin role, sent as access_token_cookie, gives full admin over users, workspaces, knowledge bases and workflows (CVE-2026-130840, CWE-321, 9.3) (VulnCheck). Simple Admin Core ≤1.8.7 shipped its JWT secret in api/etc/core.yaml, letting anyone forge roleId: 001 admin tokens. A SiteGuarding case found a short HS256 fallback in the public bundle that verified live prod cookies. See JWT Secret Cracking.
  • Published signing keys — a public JWKS must hold only public parameters. d, p, q, dp, dq, qi (RSA) or d (EC) means the private key is published; any kty: "oct" entry exposes its HMAC secret in k, so anyone can forge tokens. Audit also for missing/duplicate kid, RSA < 2048 bits and alg/kty mismatches (Avada Labs). Quick check:
    const PRIVATE = ['d','p','q','dp','dq','qi','oth','k'];
    for (const key of jwks.keys) {
      const leaked = PRIVATE.filter(f => f in key);
      if (leaked.length) console.error(`kid ${key.kid}: private fields ${leaked.join(', ')}`);
    }
  • Constant salts and HMAC keys in plugins — WebToffee Product Feed for WordPress < 2.4.4 signed its URL-cron requests with a salt embedded in the plugin source; unauthenticated callers compute a valid hash and repeatedly trigger feed generation on an init-hooked endpoint (CPU/DB exhaustion, feed file overwrite) (GHSA-rr2m-87q5-43hh) (advisory).
  • Symmetric crypto keys — CargoWise WebTracker hardcoded 3DES and AES-256-CBC keys used to encrypt query-string auth tokens, enabling auth bypass through an “auto-login” feature. Arista C-260/C-250 APs shipped fleet-wide static cryptographic keys (CVE-2026-102166).
  • Framework secrets via another bug — SSTI that reaches the Django signer leaks SECRET_KEY (XBEN-056), forging cookies and reset links; see Jinja2 SSTI.
  • Scale of the AI-era problem — GitGuardian measured a 3.2% secret-leak rate in Claude Code–assisted commits vs 1.5% baseline, and 24,008 unique secrets in public MCP config files (2,117 valid). See AI Coding Assistant Risks.

Notable cases

CaseSecretImpact
GitHub Rails test secret ($18,000)Test signing secret left in production Rails configSigned-cookie forgery → unsafe deserialization
BISHENG < 3.0.0 (CVE-2026-130840)Default JWT jwt_secretForged admin HS256 token, full admin
Tensei @tensei/auth ≤ 0.11.5 (CVE-2026-129552)'auth-secret-key' fallbackImpersonate any user incl. admins
WebToffee Product Feed < 2.4.4 (GHSA-rr2m-87q5-43hh)Constant salt for cron signatureUnauth feed regeneration, resource exhaustion
Fortinet FortiManager (CVE-2026-126181)Hard-coded credentialsDevice takeover
IBM API Connect (CVE-2026-17403)Hard-coded credentials, criticalFull compromise
Microchip TimePictra (CVE-2026-8332)Hard-coded, non-configurable root passwordRoot on every install
CAST Imaging (GHSA-3rm5-vmc4-7vm6)Hardcoded Keycloak token in KeyCloakControllerUnauth user enumeration + API token hashes via /api/auth/keycloak/users
NextScan 1.1.0–1.2.0 (CVE-2026-126802)HTTP Basic credsUnauth access
Grizzl-E Smart 40A OCPP (CVE-2026-131811)Hard-coded backend credsAdjacent-network auth bypass on EV chargers
XWEB EVO (CVE-2026-124012)Admin password synthesized daily from MAC, no stored secretDerivable admin session

Defenses

  • Remove fallbacks: fail closed when a required secret is missing rather than defaulting.
  • Generate HMAC signing keys, don’t type them: RFC 7518 §3.2 requires key material at least the hash size, i.e. 32/48/64 random bytes for HS256/384/512 (openssl rand -base64 32, secrets.token_urlsafe(32), crypto.randomBytes(32)). Tutorial values like secret or changeme fall to offline cracking from a single token (hashcat mode 16500). Check length at startup, use a different key per environment, keep it out of logs, pin algorithms on verify, and rehearse rotation (accept old and new briefly). Services that only verify should get RS256/ES256 public keys instead of a forging-capable secret (Avada Labs).
  • Treat anything shipped to a client (bundle, app, firmware) as public; use per-user tokens minted server-side, or proxy calls so no vendor key reaches the client.
  • Publish JWKS from code that serialises public parameters only, and lint the served file for private fields and oct keys.
  • Per-device/per-install keys provisioned at first boot instead of fleet-wide constants.
  • Pre-commit + CI Secret Scanning with generic/high-entropy rules, plus build-artifact scanning (bundles, images, APKs) — provider-pattern rules miss bare passwords and short fallbacks.
  • Load runtime secrets from Vaults and Secret Stores; once found, follow Credential Rotation and Revocation — deleting the line does not invalidate the value.

Sources