Hardcoded RSA private key in lib/insecurity.ts enables unauthenticated JWT forgery and full admin access on the deployed site
In plain language
- What’s wrong
- Something in how people sign in, or how the app remembers them afterwards, can be got around or guessed.
- What could happen
- Someone could sign in as another user, or stay signed in when they should have been locked out.
- How urgent
- Fix this now. It can be used to cause serious harm today, and it was proven to work.
Proof it’s real
1. Extract the hardcoded RSA private key PEM from `lib/insecurity.ts:21` (the `const privateKey = '-----BEGIN RSA PRIVATE KEY-----\r\n…'` literal).
(remainder truncated for form length)
4. Verify the response: `200` with the full admin user record (`id: 1, email: admin@juice-sh.op, role: admin`) — arbitrary admin identity assumed without credentials.Technical details
Summary
A complete RSA private key used to sign JWT session tokens is hardcoded in the application source (lib/insecurity.ts:21). Because security.authorize() signs every JWT with this constant key and the public verification key (encryptionkeys/jwt.pub) ships with the app, anyone who reads the source can mint an arbitrary, validly-signed JWT — e.g. with role: admin — and thereby assume any identity on the deployed site, including full administrator access, without knowing any password. Confirmed live: a JWT forged offline with the hardcoded key was accepted by the production target and returned the full admin user record from GET /rest/user/authentication-details.
Impact
Unauthenticated full administrative takeover of any user account on the deployed application. Demonstrated: forged admin@juice-sh.op token returns the complete admin user record (GET /rest/user/authentication-details → 200 with role: admin). This yields all admin capabilities (user management, coupon creation, data export, BFLA endpoints), PII exposure across the customer base, and — combined with the /b2b/v2/orders eval endpoint reported separately — unauthenticated server-side code execution class impact.
This is also a supply-chain/credential exposure: the same private key is used by any deployment built from this source.
How it was confirmed
lib/insecurity.ts:19-21 holds a literal PEM-encoded RSA private key:
``ts title=lib/insecurity.ts startLineNumber=19 endLineNumber=21 export const publicKey = fs ? fs.readFileSync('encryptionkeys/jwt.pub', 'utf8') : 'placeholder-public-key' const privateKey = '-----BEGIN RSA PRIVATE KEY-----\r\nMIICXAIBAAKBgQDNwqLEe9wgTXCbC7+RPdDbBbeqjdbs4kOPOIGzqLpXvJXlxxW8iMz0EaM4BKUqYsIa+ndv3NAn2RxCd5ubVdJJcX43zO6Ko0TFEZx/65gY3BE0O6syCEmUP4qbSd6exou/F+WTISzbQ5FBVPVmhnYhG/kpwt/cIxK5iUn5hm+4tQIDAQABAoGBAI+8xiPoOrA+KMnG/T4jJsG6TsHQcDHvJi7o1IKC/hnIXha0atTX5AUkRRce95qSfvKFweXdJXSQ0JMGJyfuXgU6dI0TcseFRfewXAa/ssxAC+iUVR6KUMh1PE2wXLitfeI6JLvVtrBYswm2I7CtY0q8n5AGimHWVXJPLfGV7m0BAkEA+fqFt2LXbLtyg6wZyxMA/cnmt5Nt3U2dAu77MzFJvibANUNHE4HPLZxjGNXN+a6m0K6TD4kDdh5HfUYLWWRBYQJBANK3carmulBwqzcDBjsJ0YrIONBpCAsXxk8idXb8jL9aNIg15Wumm2enqqObahDHB45jnGOLmbasizvSVqypfM9UCQCQl8xIqy+YgURXzXCN+kwUgHinrutZms87Jyi+D8Br8NY0+Nlf+zHvXAomD2W5CsEK7C+8SLBr3k/TsnRWHJuECQHFE9RA2OP8WoaLPuGCyFXaxzICThSRZYluVnWkZtxsBhW28z1b8PvWUE7kMy7TnkzeJS2LSnaNHoyxi7IaPQUCQCwWU4U+v4lD7uYBw00Ga/xt+7+UqFPlPVdz1yyr4q24Zxaw0LgmuEvgU5dycq8N7JxjTubX0MIRR+G9fmDBBl8=\r\n-----END RSA PRIVATE KEY-----' ``
security.authorize(user) then signs tokens with this constant key (lib/insecurity.ts:45, algorithm: 'RS256'), and security.isAuthorized() verifies only against the matching public key encryptionkeys/jwt.pub (lib/insecurity.ts:43). Since both key halves ship in the repository (and the Juice Shop source is public on GitHub), the signature scheme provides zero protection — the "secret" is public knowledge. Any user can produce a token the app considers valid, for any data payload (role: admin, arbitrary id), because:
``ts title=lib/insecurity.ts startLineNumber=45 endLineNumber=45 export const authorize = (user = {}) => jwt.sign(user, privateKey, { expiresIn: '6h', algorithm: 'RS256' }) ``
Verification (lib/insecurity.ts:43) never checks anything beyond signature validity, so payload content is fully attacker-chosen. The forged-token admin login is live-confirmed (see evidence). Note the key is 1024-bit RSA, below modern 2048-bit minimums, an additional weakness reported here as part of the same finding.
How to fix it, step by step
Remove the hardcoded private key from source control entirely; it cannot be rotated while it lives in the repo. Generate a per-deployment RSA keypair (>=2048-bit) at build/deploy time, keep the private key in a managed secret store (e.g. GCP Secret Manager) mounted as an environment variable or volume, and read it via
process.env/ the secret manager SDK rather than a literal inlib/insecurity.ts. Also invalidate all previously issued JWTs after rotation (they are all signed with the now-public key), e.g. by adding akey-versionclaim or short expiry. The training-app context does not change the advice — the file must never ship a usable private key. A concrete patch is provided incode_locations(fix_before/fix_afteronlib/insecurity.ts:20-21).