# 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:
| Shape | Typical location | Why it is worse than it looks |
|---|---|---|
| **Fallback default** | `process.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 credential** | Firmware, appliances, mobile SDKs | Same value across every install ("fleet-wide"), unrotatable by the customer |
| **Client-shipped key** | JS bundle, `NEXT_PUBLIC_*`, React Native bundle, APK strings | Every 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:
```js
// 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) ([[raw/vulncheck.com/tensei-auth-bypass-via-hard-coded-jwt-secret-15964|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) ([[raw/vulncheck.com/bisheng-auth-bypass-via-hard-coded-jwt-signing-secret-15965|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 ([[raw/medium.com/jwks-and-kid-explained-how-to-find-the-key-that-signed-your-token-and-15966|Avada Labs]]). Quick check:
```js
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) ([[raw/github.com/webtoffee-product-feed-hard-coded-cryptographic-key-15967|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
| Case | Secret | Impact |
|---|---|---|
| GitHub Rails test secret ($18,000) | Test signing secret left in production Rails config | Signed-cookie forgery → unsafe deserialization |
| BISHENG < 3.0.0 (CVE-2026-130840) | Default JWT `jwt_secret` | Forged admin HS256 token, full admin |
| Tensei `@tensei/auth` ≤ 0.11.5 (CVE-2026-129552) | `'auth-secret-key'` fallback | Impersonate any user incl. admins |
| WebToffee Product Feed < 2.4.4 (GHSA-rr2m-87q5-43hh) | Constant salt for cron signature | Unauth feed regeneration, resource exhaustion |
| Fortinet FortiManager (CVE-2026-126181) | Hard-coded credentials | Device takeover |
| IBM API Connect (CVE-2026-17403) | Hard-coded credentials, critical | Full compromise |
| Microchip TimePictra (CVE-2026-8332) | Hard-coded, non-configurable root password | Root on every install |
| CAST Imaging (GHSA-3rm5-vmc4-7vm6) | Hardcoded Keycloak token in `KeyCloakController` | Unauth user enumeration + API token hashes via `/api/auth/keycloak/users` |
| NextScan 1.1.0–1.2.0 (CVE-2026-126802) | HTTP Basic creds | Unauth access |
| Grizzl-E Smart 40A OCPP (CVE-2026-131811) | Hard-coded backend creds | Adjacent-network auth bypass on EV chargers |
| XWEB EVO (CVE-2026-124012) | Admin password synthesized daily from MAC, no stored secret | Derivable admin session |
## Defenses
- Remove fallbacks: fail closed when a required secret is missing rather than defaulting.
- 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.
## Related
- [[Secrets Management]]
- [[Secret Scanning]] · [[Secrets in Git History]] · [[Leaked Cloud Credentials]]
- [[JWT Secret Cracking]] · [[JavaScript Analysis]] · [[Android App Security]] · [[AI Coding Assistant Risks]]
## Sources
- [[raw/github.com/tensei-auth-bypass-via-hard-coded-jwt-secret-15279|Tensei auth bypass via hard-coded JWT secret]]
- [[raw/vulnsea.com/simple-admin-core-hard-coded-jwt-secret-authentication-bypass-12719|Simple Admin Core hard-coded JWT secret authentication bypass]]
- [[raw/siteguarding.com/jwt-signing-key-in-a-javascript-bundle-case-study-14443|JWT signing key in a JavaScript bundle: case study]]
- [[raw/medium.com/a-test-secret-in-production-how-a-rails-session-cookie-earned-18-000-f-15524|A Test Secret in Production: How a Rails Session Cookie Earned $18,000]]
- [[raw/slcyber.io/cargowise-webtracker-the-keys-were-in-the-cargo-9912|CargoWise WebTracker - The keys were in the cargo]]
- [[raw/b52security.com/from-ssti-to-a-django-secret-key-xben-056-13914|From SSTI to a Django secret key (XBEN-056)]]
- [[raw/miggo.io/cve-2025-68429-storybook-env-secrets-exposure-4064|CVE-2025-68429: Storybook .env Secrets Exposure]]
- [[raw/nodejs-security.com/do-not-use-secrets-in-environment-variables-4344|Do Not Use Secrets in Environment Variables]]
- [[raw/datatheorem.com/hardcoded-credentials-in-mobile-apps-every-key-is-public-14434|Hardcoded credentials in mobile apps: every key is public]]
- [[raw/medium.com/react-native-apps-should-start-with-zero-api-keys-kerb-runs-52-screens-12550|React Native Apps Should Start With Zero API Keys]]
- [[raw/github.com/cast-imaging-hardcoded-keycloak-auth-token-15281|CAST Imaging hardcoded Keycloak auth token]]
- [[raw/github.com/arista-c-260-c-250-aps-ship-fleet-wide-static-cryptographic-keys-criti-14163|Arista C-260/C-250 APs ship fleet-wide static cryptographic keys]]
- [[raw/github.com/xweb-evo-hardcoded-credential-critical-14444|XWEB EVO hardcoded credential (critical)]]
- [[raw/github.com/fortinet-fortimanager-hard-coded-credentials-14741|Fortinet FortiManager hard-coded credentials]]
- [[raw/trufflesecurity.com/secret-scanning-encoded-and-archived-data-4076|Secret Scanning Encoded and Archived Data]]
- [[raw/blog.gitguardian.com/the-state-of-secrets-sprawl-2026-ai-service-leaks-surge-81-3771|The State of Secrets Sprawl 2026: AI-Service Leaks Surge 81%]]
- [[raw/github.com/ibm-api-connect-hard-coded-credentials-critical-13830|IBM API Connect hard-coded credentials (critical)]]
- [[raw/github.com/microchip-timepictra-hard-coded-root-password-14740|Microchip TimePictra hard-coded root password]]
- [[raw/github.com/nextscan-1-1-0-through-1-2-0-hardcoded-http-basic-auth-credentials-14305|NextScan 1.1.0 through 1.2.0 hardcoded HTTP Basic Auth credentials]]
- [[raw/github.com/grizzl-e-smart-40a-ocpp-backend-hard-coded-credentials-15580|Grizzl-E Smart 40A OCPP backend hard-coded credentials]]
- [[raw/github.com/vitafit-android-app-hardcoded-credentials-13839|VitaFit Android app hardcoded credentials]]
- [[raw/github.com/hard-coded-mqtt-credentials-in-am-club-mobile-app-13989|Hard-coded MQTT credentials in AM CLUB mobile app]]
- [[raw/github.com/hardcoded-api-key-retrievable-from-gv-access-android-package-14151|Hardcoded API key retrievable from GV-Access Android package]]
- [[raw/vulncheck.com/tensei-auth-bypass-via-hard-coded-jwt-secret-15964|Tensei auth bypass via hard-coded JWT secret (VulnCheck)]]
- [[raw/vulncheck.com/bisheng-auth-bypass-via-hard-coded-jwt-signing-secret-15965|BISHENG auth bypass via hard-coded JWT signing secret]]
- [[raw/github.com/webtoffee-product-feed-hard-coded-cryptographic-key-15967|WebToffee Product Feed hard-coded cryptographic key]]
- [[raw/medium.com/jwks-and-kid-explained-how-to-find-the-key-that-signed-your-token-and-15966|JWKS and kid Explained: How to Find the Key That Signed Your Token (and Spot a Leaked Private Key)]]