Skip to content
Crypto Audit finding Intermediate

Missing JWT_SECRET in Env Allows Token Forgery via Empty Secret

The authentication code falls back to an empty string as the JWT signing and verification secret when the JWT_SECRET environment variable is not set. If that variable is missing in a deployment, an attacker could sign their own tokens with the empty secret and have them accepted as valid.

adhd Follow

Originally disclosed on Immunefi

Informational View original
  • Disclosed after under an hour

#47741 [W&A-Insight] Missing JWT_SECRET in Env Allows Token Forgery via Empty Secret

Submitted on Jun 19th 2025 at 13:03:19 UTC by @adhd for IOP | Zano Trade

Description

Brief/Intro

The jwt.sign and jwt.verify uses process.env.JWT_SECRET || "" in the signing and verifying process in this if by any reason if JWT_SECRET is missing in the env of the project the code will automatically use the empty string as the secret which is a bad practice

Vulnerability Details

If JWT_SECRET doesn't exists in the .env then the sign and verify will use empty string causing the token forgery

Impact Details

Any user can create an valid signature if the JWT_SECRET is not presnet in the .env and call the verification wrt to the user

Proof of Concept

Proof of Concept

if (success) {
				const token = jwt.sign(
					{ ...userData },
					process.env.JWT_SECRET || '',
					neverExpires ? undefined : { expiresIn: '24h' },
				);
				res.status(200).send({ success, data: token });
			}
async verifyToken(req: Request, res: Response, next: NextFunction) {
		try {
			const userData = jwt.verify(req.body.token, process.env.JWT_SECRET || '') as UserData;
			req.body.userData = userData;
			next();
		} catch {
			res.status(401).send({ success: false, data: 'Unauthorized (JWT)' });
		}
	}
try {
		userData = jwt.verify(data.token, process.env.JWT_SECRET || '') as UserData;
	} catch {
		return next(new Error('Unauthorized'));
	}
try {
			userData = jwt.verify(data.token, process.env.JWT_SECRET || '') as UserData;
		} catch {
			return next(new Error('Unauthorized'));
		}

Here, you can see the use of ||, which should not be present.

The original report as published on Immunefi, by adhd. Images and videos are our own copies; raw HTML is shown as text. View it on Immunefi.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the code uses a logical-or fallback to an empty string for the JWT secret instead of failing when the environment variable is absent.

Impact

If the secret is missing from the environment, any user could forge a valid signature and pass token verification as that user.

What the attacker needed

JWT_SECRET missing from the environment

The fix

The code should refuse to start or throw an error when JWT_SECRET is not set, rather than falling back to an empty string.

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 report has not been written yet. The Original tab links to the source.

A JSON Web Token (JWT) is a signed piece of data a server hands out to prove who you are on later requests. The signature is made with a secret key, so only the server can produce valid tokens. Here the code quietly uses an empty key when the real secret is not configured, which means anyone who knows this can make their own valid tokens.

What is Crypto?

Encryption, signatures, randomness or certificate checks that do not protect what they claim to.

More by adhd

View all

1 more disclosed report, best first.

More from Zano Trade

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Cryptographic weaknesses

The lesson behind this report.

Encryption, signatures, randomness or certificate checks that do not protect what they claim to.