@@ -9,6 +9,88 @@ private import codeql.ruby.Concepts
9
9
private import codeql.ruby.security.SensitiveActions
10
10
private import codeql.ruby.dataflow.BarrierGuards
11
11
12
+ private module SensitiveDataSources {
13
+ /**
14
+ * A data flow source of sensitive data, such as secrets, certificates, or passwords.
15
+ *
16
+ * Extend this class to refine existing API models. If you want to model new APIs,
17
+ * extend `SensitiveDataSource::Range` instead.
18
+ */
19
+ class SensitiveDataSource extends DataFlow:: Node instanceof SensitiveDataSource:: Range {
20
+ /**
21
+ * Gets the classification of the sensitive data.
22
+ */
23
+ SensitiveDataClassification getClassification ( ) { result = super .getClassification ( ) }
24
+ }
25
+
26
+ /** Provides a class for modeling new sources of sensitive data, such as secrets, certificates, or passwords. */
27
+ module SensitiveDataSource {
28
+ /**
29
+ * A data flow source of sensitive data, such as secrets, certificates, or passwords.
30
+ *
31
+ * Extend this class to model new APIs. If you want to refine existing API models,
32
+ * extend `SensitiveDataSource` instead.
33
+ */
34
+ abstract class Range extends DataFlow:: Node {
35
+ /**
36
+ * Gets the classification of the sensitive data.
37
+ */
38
+ abstract SensitiveDataClassification getClassification ( ) ;
39
+ }
40
+ }
41
+
42
+ /**
43
+ * A call to a method that may return sensitive data.
44
+ */
45
+ class SensitiveMethodCall extends SensitiveDataSource:: Range , DataFlow:: CallNode instanceof SensitiveNode
46
+ {
47
+ SensitiveDataMethodName methodName ;
48
+
49
+ SensitiveMethodCall ( ) { methodName = this .getMethodName ( ) }
50
+
51
+ override SensitiveDataClassification getClassification ( ) {
52
+ result = methodName .getClassification ( )
53
+ }
54
+ }
55
+
56
+ /**
57
+ * An assignment to a variable that may contain sensitive data.
58
+ */
59
+ class SensitiveVariableAssignment extends SensitiveDataSource:: Range instanceof SensitiveNode {
60
+ SensitiveVariableAssignment ( ) {
61
+ this .( DataFlow:: VariableAccessNode ) .asVariableAccessAstNode ( ) instanceof
62
+ Ast:: VariableWriteAccess
63
+ }
64
+
65
+ override SensitiveDataClassification getClassification ( ) {
66
+ result = SensitiveNode .super .getClassification ( )
67
+ }
68
+ }
69
+
70
+ /**
71
+ * A read from a hash value that may return sensitive data.
72
+ */
73
+ class SensitiveHashValueAccess extends SensitiveDataSource:: Range instanceof SensitiveNode {
74
+ SensitiveHashValueAccess ( ) {
75
+ this .asExpr ( ) instanceof Cfg:: CfgNodes:: ExprNodes:: ElementReferenceCfgNode
76
+ }
77
+
78
+ override SensitiveDataClassification getClassification ( ) {
79
+ result = SensitiveNode .super .getClassification ( )
80
+ }
81
+ }
82
+
83
+ /**
84
+ * A parameter node that may contain sensitive data.
85
+ */
86
+ class SensitiveParameter extends SensitiveDataSource:: Range , DataFlow:: ParameterNode instanceof SensitiveNode
87
+ {
88
+ override SensitiveDataClassification getClassification ( ) {
89
+ result = SensitiveNode .super .getClassification ( )
90
+ }
91
+ }
92
+ }
93
+
12
94
/**
13
95
* Provides default sources, sinks and sanitizers for detecting
14
96
* "use of a broken or weak cryptographic hashing algorithm on sensitive data"
@@ -49,9 +131,10 @@ module NormalHashFunction {
49
131
/**
50
132
* A source of sensitive data, considered as a flow source.
51
133
*/
52
- class SensitiveDataSourceAsSource extends Source instanceof SensitiveDataSource {
134
+ class SensitiveDataSourceAsSource extends Source instanceof SensitiveDataSources:: SensitiveDataSource
135
+ {
53
136
override SensitiveDataClassification getClassification ( ) {
54
- result = SensitiveDataSource .super .getClassification ( )
137
+ result = SensitiveDataSources :: SensitiveDataSource .super .getClassification ( )
55
138
}
56
139
}
57
140
@@ -118,13 +201,14 @@ module ComputationallyExpensiveHashFunction {
118
201
/**
119
202
* A source of passwords, considered as a flow source.
120
203
*/
121
- class PasswordSourceAsSource extends Source instanceof SensitiveDataSource {
204
+ class PasswordSourceAsSource extends Source instanceof SensitiveDataSources :: SensitiveDataSource {
122
205
PasswordSourceAsSource ( ) {
123
- this .( SensitiveDataSource ) .getClassification ( ) = SensitiveDataClassification:: password ( )
206
+ this .( SensitiveDataSources:: SensitiveDataSource ) .getClassification ( ) =
207
+ SensitiveDataClassification:: password ( )
124
208
}
125
209
126
210
override SensitiveDataClassification getClassification ( ) {
127
- result = SensitiveDataSource .super .getClassification ( )
211
+ result = SensitiveDataSources :: SensitiveDataSource .super .getClassification ( )
128
212
}
129
213
}
130
214
0 commit comments