-
-
-Applications decoding JSON Web Token (JWT) may be misconfigured due to the none algorithm.
-The none algorithm is selected by calling the verify()
function with a falsy value
-instead of a cryptographic secret or key. The none algorithm disables the integrity enforcement of
-a JWT payload and may allow a malicious actor to make any desired changes to a JWT payload leading
-to critical security issues like privilege escalation.
-
-
-
-
-Call to verify()
functions should use a cryptographic secret or key to decode JWT payloads.
-
-
-
-
-In the example, the first case is signing an object with a secret and a HS256 algorithm. In the
-second case, an empty string is provided, then an undefined value, and finally a false value. These
-three misconfigured calls to jwt.verify()
can cause vulnerabilities.
-
-
-
-
-
-
-Auth0 Blog: Meet the "None" Algorithm.
-
-
-
\ No newline at end of file
diff --git a/javascript/ql/test/query-tests/Security/CWE-347/MissingJWTKeyVerification.expected b/javascript/ql/test/query-tests/Security/CWE-347/MissingJWTKeyVerification.expected
new file mode 100644
index 000000000000..81d60e688166
--- /dev/null
+++ b/javascript/ql/test/query-tests/Security/CWE-347/MissingJWTKeyVerification.expected
@@ -0,0 +1,3 @@
+| bad-jwt.js:10:19:10:20 | "" | This argument disables the integrity enforcement of the token verification. |
+| bad-jwt.js:11:19:11:27 | undefined | This argument disables the integrity enforcement of the token verification. |
+| bad-jwt.js:12:19:12:23 | false | This argument disables the integrity enforcement of the token verification. |
diff --git a/javascript/ql/test/query-tests/Security/CWE-347/MissingJWTKeyVerification.qlref b/javascript/ql/test/query-tests/Security/CWE-347/MissingJWTKeyVerification.qlref
new file mode 100644
index 000000000000..39d8056c9327
--- /dev/null
+++ b/javascript/ql/test/query-tests/Security/CWE-347/MissingJWTKeyVerification.qlref
@@ -0,0 +1 @@
+Security/CWE-347/MissingJWTKeyVerification.ql
diff --git a/javascript/ql/src/experimental/Security/CWE-347/examples/JWTMissingSecretOrPublicKeyVerification.js b/javascript/ql/test/query-tests/Security/CWE-347/bad-jwt.js
similarity index 55%
rename from javascript/ql/src/experimental/Security/CWE-347/examples/JWTMissingSecretOrPublicKeyVerification.js
rename to javascript/ql/test/query-tests/Security/CWE-347/bad-jwt.js
index 02e93f83fa13..947793289644 100644
--- a/javascript/ql/src/experimental/Security/CWE-347/examples/JWTMissingSecretOrPublicKeyVerification.js
+++ b/javascript/ql/test/query-tests/Security/CWE-347/bad-jwt.js
@@ -1,11 +1,12 @@
const jwt = require("jsonwebtoken");
-const secret = "buybtc";
-// #1
-var token = jwt.sign({ foo: 'bar' }, secret, { algorithm: "HS256" }) // alg:HS256
-jwt.verify(token, secret, { algorithms: ["HS256", "none"] }) // pass
-// #2
-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
\ No newline at end of file
+const secret = "my-secret-key";
+
+var token = jwt.sign({ foo: 'bar' }, secret, { algorithm: "HS256" })
+jwt.verify(token, secret, { algorithms: ["HS256", "none"] }) // OK
+
+
+var token = jwt.sign({ foo: 'bar' }, secret, { algorithm: "none" })
+jwt.verify(token, "", { algorithms: ["HS256", "none"] }) // NOT OK
+jwt.verify(token, undefined, { algorithms: ["HS256", "none"] }) // NOT OK
+jwt.verify(token, false, { algorithms: ["HS256", "none"] }) // NOT OK
\ No newline at end of file