-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathJwt.qll
More file actions
58 lines (46 loc) · 1.95 KB
/
Jwt.qll
File metadata and controls
58 lines (46 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/**
* Provides creation, verification and decoding JSON Web Tokens (JWT).
*/
private import ruby
private import codeql.ruby.ApiGraphs
private import codeql.ruby.dataflow.FlowSummary
private import codeql.ruby.Concepts
/**
* Provides creation, verification and decoding JSON Web Tokens (JWT).
*/
module Jwt {
/** A call to `JWT.encode`, considered as a JWT encoding. */
private class JwtEncode extends JwtEncoding::Range, DataFlow::CallNode {
JwtEncode() { this = API::getTopLevelMember("JWT").getAMethodCall("encode") }
override DataFlow::Node getPayload() { result = this.getArgument(0) }
override DataFlow::Node getAlgorithm() { result = this.getArgument(2) }
override DataFlow::Node getKey() { result = this.getArgument(1) }
override predicate signsPayload() {
not (
this.getKey().getConstantValue().isStringlikeValue("") or
this.getKey().(DataFlow::ExprNode).getConstantValue().isNil()
)
}
}
/** A call to `JWT.decode`, considered as a JWT decoding. */
private class JwtDecode extends JwtDecoding::Range, DataFlow::CallNode {
JwtDecode() { this = API::getTopLevelMember("JWT").getAMethodCall("decode") }
override DataFlow::Node getPayload() { result = this.getArgument(0) }
override DataFlow::Node getAlgorithm() {
result = this.getArgument(3).(DataFlow::PairNode).getValue() or
result =
this.getArgument(3)
.(DataFlow::HashLiteralNode)
.getElementFromKey(any(Ast::ConstantValue cv | cv.isStringlikeValue("algorithm"))) or
result = this.getArgument(2)
}
override DataFlow::Node getKey() { result = this.getArgument(1) }
override DataFlow::Node getOptions() { result = this.getArgument(3) }
override predicate verifiesSignature() {
not this.getArgument(2).getConstantValue().isBoolean(false) and
not this.getAlgorithm().getConstantValue().isStringlikeValue("none")
or
this.getNumberOfArguments() < 3
}
}
}