
Exploit proof-of-concept per CVE-2026-21003 che dimostra il bypass dell'autenticazione JWT omettendo l'header kid e utilizzando l'algoritmo 'none' per impersonare gli utenti.
// jwt_verify_server.js - Vulnerable JWT verification
const jwt = require('jsonwebtoken');
const express = require('express');
const app = express();
app.use(express.json());
const publicKey = `-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAu1SU1LfVLPHCYZM5rPY4...
-----END PUBLIC KEY-----`;
app.post('/verify', (req, res) => {
const token = req.body.token;
// Vulnerability: if no algorithm specified, defaults to HS256? Actually, jsonwebtoken can be tricked.
// We simulate a custom verifier that accepts "none" if kid is missing.
const decoded = jwt.decode(token, { complete: true });
if (!decoded.header.alg || decoded.header.alg === 'none') {
// Accept token without signature
res.json({ status: 'authenticated', user: decoded.payload.sub });
} else {
jwt.verify(token, publicKey, { algorithms: ['RS256'] }, (err, payload) => {
if (err) res.status(401).send('Invalid');
else res.json({ status: 'authenticated', user: payload.sub });
});
}
});
app.listen(3000);
Un verificatore JWT personalizzato non applica correttamente la presenza di un algoritmo di firma. Se l'header del token omette il parametro alg o lo imposta esplicitamente a none, il server accetta il token senza verificare una firma, consentendo un'escalation dei privilegi.
npm install express jsonwebtoken
node jwt_verify_server.js
pip install pyjwt requests
python exploit_jwt_none.py
La risposta mostra che l'utente è autenticato come admin.