Skip to content

Commit 090a685

Browse files
authored
Merge pull request github#3751 from toufik-airane/master
[javascript] CWE-347: JWT Missing Secret Or Public Key Verification
2 parents 38067b5 + 27f91b3 commit 090a685

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<!DOCTYPE qhelp PUBLIC "-//Semmle//qhelp//EN" "qhelp.dtd"> <qhelp>
2+
3+
<overview>
4+
<p>Applications decoding JSON Web Token (JWT) may be misconfigured due to the none algorithm.</p>
5+
<p>The none algorithm is selected by calling the <code>verify()</code> function with a falsy value
6+
instead of a cryptographic secret or key. The none algorithm disables the integrity enforcement of
7+
a JWT payload and may allow a malicious actor to make any desired changes to a JWT payload leading
8+
to critical security issues like privilege escalation.</p>
9+
10+
</overview>
11+
12+
<recommendation>
13+
<p>Call to <code>verify()</code> functions should use a cryptographic secret or key to decode JWT payloads.</p>
14+
15+
</recommendation>
16+
17+
<example>
18+
<p>In the example, the first case is signing an object with a secret and a HS256 algorithm. In the
19+
second case, an empty string is provided, then an undefined value, and finally a false value. These
20+
three misconfigured calls to <code>jwt.verify()</code> can cause vulnerabilities.</p>
21+
22+
<sample src="examples/JWTMissingSecretOrPublicKeyVerification.js" />
23+
24+
</example>
25+
26+
<references>
27+
<li>Auth0 Blog: <a href="https://auth0.com/blog/critical-vulnerabilities-in-json-web-token-libraries/#Meet-the--None--Algorithm">Meet the "None" Algorithm</a>.</li>
28+
29+
</references>
30+
</qhelp>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* @name JWT missing secret or public key verification
3+
* @description The application does not verify the JWT payload with a cryptographic secret or public key.
4+
* @kind problem
5+
* @problem.severity warning
6+
* @precision high
7+
* @id js/jwt-missing-verification
8+
* @tags security
9+
* external/cwe/cwe-347
10+
*/
11+
12+
import javascript
13+
import DataFlow
14+
import semmle.javascript.RestrictedLocations
15+
16+
from CallNode call
17+
where
18+
call = moduleMember("jsonwebtoken", "verify").getACall() and
19+
unique(boolean b | b = call.getArgument(1).analyze().getABooleanValue()) = false
20+
select call.asExpr().(FirstLineOf),
21+
"does not verify the JWT payload with a cryptographic secret or public key."
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const jwt = require("jsonwebtoken");
2+
3+
const secret = "buybtc";
4+
// #1
5+
var token = jwt.sign({ foo: 'bar' }, secret, { algorithm: "HS256" }) // alg:HS256
6+
jwt.verify(token, secret, { algorithms: ["HS256", "none"] }) // pass
7+
// #2
8+
var token = jwt.sign({ foo: 'bar' }, secret, { algorithm: "none" }) // alg:none (unsafe)
9+
jwt.verify(token, "", { algorithms: ["HS256", "none"] }) // detected
10+
jwt.verify(token, undefined, { algorithms: ["HS256", "none"] }) // detected
11+
jwt.verify(token, false, { algorithms: ["HS256", "none"] }) // detected

0 commit comments

Comments
 (0)