-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathTokenBuiltFromUUID.ql
More file actions
63 lines (55 loc) · 2.03 KB
/
TokenBuiltFromUUID.ql
File metadata and controls
63 lines (55 loc) · 2.03 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
59
60
61
62
63
/**
* @name Predictable token
* @description Tokens used for sensitive tasks, such as, password recovery,
* and email confirmation, should not use predictable values.
* @kind path-problem
* @precision medium
* @problem.severity error
* @security-severity 5
* @id py/predictable-token
* @tags security
* external/cwe/cwe-340
*/
import python
import semmle.python.dataflow.new.DataFlow
import semmle.python.ApiGraphs
import semmle.python.dataflow.new.TaintTracking
import DataFlow::PathGraph
class PredictableResultSource extends DataFlow::Node {
PredictableResultSource() {
exists(API::Node uuidCallRet |
uuidCallRet =
API::moduleImport("uuid")
.getMember(["uuid1", "uuid3", "uuid5"])
.getReturn()
|
this = uuidCallRet.asSource()
or
this = uuidCallRet.getMember(["hex", "bytes", "bytes_le"]).asSource()
)
}
}
class TokenAssignmentValueSink extends DataFlow::Node {
TokenAssignmentValueSink() {
exists(string name | name.toLowerCase().matches(["%token", "%code"]) |
exists(DefinitionNode n | n.getValue() = this.asCfgNode() | name = n.(NameNode).getId())
or
exists(DataFlow::AttrWrite aw | aw.getValue() = this | name = aw.getAttributeName())
)
}
}
class TokenBuiltFromUuidConfig extends TaintTracking::Configuration {
TokenBuiltFromUuidConfig() { this = "TokenBuiltFromUuidConfig" }
override predicate isSource(DataFlow::Node source) { source instanceof PredictableResultSource }
override predicate isSink(DataFlow::Node sink) { sink instanceof TokenAssignmentValueSink }
override predicate isAdditionalTaintStep(DataFlow::Node nodeFrom, DataFlow::Node nodeTo) {
exists(DataFlow::CallCfgNode call |
call = API::builtin("str").getACall() and
nodeFrom = call.getArg(0) and
nodeTo = call
)
}
}
from DataFlow::PathNode source, DataFlow::PathNode sink, TokenBuiltFromUuidConfig config
where config.hasFlowPath(source, sink)
select sink.getNode(), source, sink, "Token built from $@.", source.getNode(), "predictable value"