@@ -9,6 +9,88 @@ private import codeql.ruby.Concepts
99private import codeql.ruby.security.SensitiveActions
1010private import codeql.ruby.dataflow.BarrierGuards
1111
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+
1294/**
1395 * Provides default sources, sinks and sanitizers for detecting
1496 * "use of a broken or weak cryptographic hashing algorithm on sensitive data"
@@ -49,9 +131,10 @@ module NormalHashFunction {
49131 /**
50132 * A source of sensitive data, considered as a flow source.
51133 */
52- class SensitiveDataSourceAsSource extends Source instanceof SensitiveDataSource {
134+ class SensitiveDataSourceAsSource extends Source instanceof SensitiveDataSources:: SensitiveDataSource
135+ {
53136 override SensitiveDataClassification getClassification ( ) {
54- result = SensitiveDataSource .super .getClassification ( )
137+ result = SensitiveDataSources :: SensitiveDataSource .super .getClassification ( )
55138 }
56139 }
57140
@@ -118,13 +201,14 @@ module ComputationallyExpensiveHashFunction {
118201 /**
119202 * A source of passwords, considered as a flow source.
120203 */
121- class PasswordSourceAsSource extends Source instanceof SensitiveDataSource {
204+ class PasswordSourceAsSource extends Source instanceof SensitiveDataSources :: SensitiveDataSource {
122205 PasswordSourceAsSource ( ) {
123- this .( SensitiveDataSource ) .getClassification ( ) = SensitiveDataClassification:: password ( )
206+ this .( SensitiveDataSources:: SensitiveDataSource ) .getClassification ( ) =
207+ SensitiveDataClassification:: password ( )
124208 }
125209
126210 override SensitiveDataClassification getClassification ( ) {
127- result = SensitiveDataSource .super .getClassification ( )
211+ result = SensitiveDataSources :: SensitiveDataSource .super .getClassification ( )
128212 }
129213 }
130214
0 commit comments