-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathInsecureCookie.ql
More file actions
92 lines (77 loc) · 2.77 KB
/
InsecureCookie.ql
File metadata and controls
92 lines (77 loc) · 2.77 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/**
* @name 'Secure' attribute is not set to true
* @description Omitting the 'Secure' attribute allows data to be transmitted insecurely
* using HTTP. Always set 'Secure' to 'true' to ensure that HTTPS
* is used at all times.
* @kind path-problem
* @problem.severity error
* @security-severity 7.5
* @precision high
* @id rust/insecure-cookie
* @tags security
* external/cwe/cwe-319
* external/cwe/cwe-614
*/
import rust
import codeql.rust.dataflow.DataFlow
import codeql.rust.dataflow.TaintTracking
import codeql.rust.security.InsecureCookieExtensions
/**
* A data flow configuration for tracking values representing cookies without the
* 'secure' attribute set. This is the primary data flow configuration for this
* query.
*/
module InsecureCookieConfig implements DataFlow::ConfigSig {
import InsecureCookie
predicate isSource(DataFlow::Node node) {
// creation of a cookie or cookie configuration with default, insecure settings
node instanceof Source
or
// setting the 'secure' attribute to false (or an unknown value)
cookieSetNode(node, "secure", false)
}
predicate isSink(DataFlow::Node node) {
// use of a cookie or cookie configuration
node instanceof Sink
}
predicate isBarrierIn(DataFlow::Node node) {
// setting the 'secure' attribute
cookieSetNode(node, "secure", _)
or
node instanceof Barrier
}
predicate observeDiffInformedIncrementalMode() { any() }
}
/**
* A data flow configuration for tracking values representing cookies with the
* 'partitioned' attribute set. This is a secondary data flow configuration used
* to filter out unwanted results.
*/
module PartitionedCookieConfig implements DataFlow::ConfigSig {
import InsecureCookie
predicate isSource(DataFlow::Node node) {
// setting the 'partitioned' attribute to true
cookieSetNode(node, "partitioned", true)
}
predicate isSink(DataFlow::Node node) {
// use of a cookie or cookie configuration
node instanceof Sink
}
predicate isBarrier(DataFlow::Node node) {
// setting the 'partitioned' attribute to false (or an unknown value)
cookieSetNode(node, "partitioned", false)
or
node instanceof Barrier
}
predicate observeDiffInformedIncrementalMode() {
none() // only used negatively
}
}
module InsecureCookieFlow = TaintTracking::Global<InsecureCookieConfig>;
module PartitionedCookieFlow = TaintTracking::Global<PartitionedCookieConfig>;
import InsecureCookieFlow::PathGraph
from InsecureCookieFlow::PathNode sourceNode, InsecureCookieFlow::PathNode sinkNode
where
InsecureCookieFlow::flowPath(sourceNode, sinkNode) and
not PartitionedCookieFlow::flowTo(sinkNode.getNode())
select sinkNode.getNode(), sourceNode, sinkNode, "Cookie attribute 'Secure' is not set to true."