add test file for CWE-347

Add a test file for CWE-347.
The HS256 algorithm is safe, but the none algorithm is unsafe.
This commit is contained in:
toufik-airane
2020-06-20 17:10:35 +02:00
parent 8a2a33459a
commit 7166d5422e

View File

@@ -0,0 +1,11 @@
const jwt = require("jsonwebtoken");
const secret = "buybtc";
var token = jwt.sign({ foo: 'bar' }, secret, { algorithm: "HS256" }) // alg:HS256
jwt.verify(token, secret, { algorithms: ["HS256", "none"] }) // pass
var token = jwt.sign({ foo: 'bar' }, secret, { algorithm: "none" }) // alg:none (unsafe)
jwt.verify(token, "", { algorithms: ["HS256", "none"] }) // detected
jwt.verify(token, undefined, { algorithms: ["HS256", "none"] }) // detected
jwt.verify(token, false, { algorithms: ["HS256", "none"] }) // detected