
Proof-of-concept demonstrating JWT algorithm confusion in fast-jwt library. Includes vulnerable server, token forging script, and verification fix for security education.
This repository demonstrates JWT algorithm confusion in fast-jwt when token verification does not lock allowed algorithms.
From the project root, run:
npm install
The app expects these files:
keys/private.pemkeys/public.pemRun one of the following command sets.
PowerShell (Windows):
New-Item -ItemType Directory -Path keys -Force | Out-Null
openssl genrsa -out keys/private.pem 2048
openssl rsa -in keys/private.pem -RSAPublicKey_out -out keys/public.pem
Linux/macOS/Git Bash:
mkdir -p keys
openssl genrsa -out keys/private.pem 2048
openssl rsa -in keys/private.pem -RSAPublicKey_out -out keys/public.pem
node server.js
Expected output:
Server running at http://localhost:3000
curl http://localhost:3000/generateToken
node sign.js
Copy the printed token.
node checkAdmin.js <JWT_TOKEN>
If the attack succeeds, the response contains Welcome Admin!.
In server.js, the verifier does not restrict algorithms:
const verifySync = createVerifier({
key: publicKey,
});
Without an algorithm allowlist, the server may accept a malicious HS256 token signed using the public key as HMAC secret.
Trong cac demo CVE cua nhom, doi tuong bi loi la thu vien (khong the tu chay doc lap). Vi vay can dung mot ung dung gia lap de mo phong cach he thong thuc te goi API cua thu vien do. O repo nay, file server.js la lop ung dung mo phong.
Code flow PoC bo tro:
Tom lai, nhom khong viet lai ham cua thu vien. Nhom chi dung API goc cua thu vien bi loi (createSigner, createVerifier) ben trong app gia lap de tai hien dung boi canh khai thac.
Restrict verification to RS256:
const verifySync = createVerifier({
key: publicKey,
algorithms: ["RS256"],
});
This project is for security learning in a controlled lab environment only.