JavaScript, JWTs and the Key That Shouldn’t Exist
A JWT signing secret was hardcoded in a public frontend JavaScript bundle, allowing an attacker to forge tokens with admin role and gain full admin access. The attacker logged in as a normal user, extracted the secret, and replaced their token with a forged one to access the admin panel.
medium.com
Published on medium.com
Sometimes, all you need is a poorly written auth.js, a public-facing JavaScript bundle, and a little bit of curiosity.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the JWT signing secret was hardcoded in client-side JavaScript, and the backend only verified the signature without validating claims such as role.
Impact
The attacker gained full admin access, including user management, PII dump, debug console, moderation tools, and stored XSS injection points, with no IP block, CAPTCHA, or server-side validation of claims.
What the attacker needed
Publicly accessible JavaScript bundle; a normal user account; ability to modify LocalStorage
The fix
The secret should never be hardcoded in frontend code; use environment variables, rotate secrets, prefer asymmetric signing, and always validate claims on the backend.
How it was found
- Download the public JavaScript bundle from the target site.
- Search the bundle for keywords like secret, token, jwt, key, sign.
- Find the hardcoded JWT signing secret in the code.
- Log in as a normal user and retrieve the JWT from LocalStorage.
- Forge a new JWT with admin role using the exposed secret.
- Replace the token in LocalStorage and refresh the admin page to gain access.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
A JWT is like a signed permission slip that proves who you are. The secret used to sign it was left in the website's public code, so anyone could create their own valid slip claiming to be an admin. The server trusted the signature without checking the role, so the fake slip worked.
What is Account takeover?
Getting into someone else's account through a flaw in sign-in, password reset, second factor, single sign-on or session handling.