Skip to content

Commit f217de9

Browse files
committed
Ruby: Move SensitiveDataSource logic into a private module
1 parent 6a46fb5 commit f217de9

File tree

2 files changed

+89
-81
lines changed

2 files changed

+89
-81
lines changed

ruby/ql/lib/codeql/ruby/security/SensitiveActions.qll

Lines changed: 0 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -224,79 +224,3 @@ class AuthorizationCall extends SensitiveAction, DataFlow::CallNode {
224224
)
225225
}
226226
}
227-
228-
/**
229-
* A data flow source of sensitive data, such as secrets, certificates, or passwords.
230-
*
231-
* Extend this class to refine existing API models. If you want to model new APIs,
232-
* extend `SensitiveDataSource::Range` instead.
233-
*/
234-
class SensitiveDataSource extends DataFlow::Node instanceof SensitiveDataSource::Range {
235-
/**
236-
* Gets the classification of the sensitive data.
237-
*/
238-
SensitiveDataClassification getClassification() { result = super.getClassification() }
239-
}
240-
241-
/** Provides a class for modeling new sources of sensitive data, such as secrets, certificates, or passwords. */
242-
module SensitiveDataSource {
243-
/**
244-
* A data flow source of sensitive data, such as secrets, certificates, or passwords.
245-
*
246-
* Extend this class to model new APIs. If you want to refine existing API models,
247-
* extend `SensitiveDataSource` instead.
248-
*/
249-
abstract class Range extends DataFlow::Node {
250-
/**
251-
* Gets the classification of the sensitive data.
252-
*/
253-
abstract SensitiveDataClassification getClassification();
254-
}
255-
}
256-
257-
/**
258-
* A call to a method that may return sensitive data.
259-
*/
260-
class SensitiveMethodCall extends SensitiveDataSource::Range, DataFlow::CallNode instanceof SensitiveNode
261-
{
262-
SensitiveDataMethodName methodName;
263-
264-
SensitiveMethodCall() { methodName = this.getMethodName() }
265-
266-
override SensitiveDataClassification getClassification() {
267-
result = methodName.getClassification()
268-
}
269-
}
270-
271-
/**
272-
* An assignment to a variable that may contain sensitive data.
273-
*/
274-
class SensitiveVariableAssignment extends SensitiveDataSource::Range instanceof BasicSensitiveWrite {
275-
override SensitiveDataClassification getClassification() {
276-
result = BasicSensitiveWrite.super.getClassification()
277-
}
278-
}
279-
280-
/**
281-
* A read from a hash value that may return sensitive data.
282-
*/
283-
class SensitiveHashValueAccess extends SensitiveDataSource::Range instanceof BasicSensitiveVariableAccess
284-
{
285-
SensitiveHashValueAccess() {
286-
this.asExpr() instanceof CfgNodes::ExprNodes::ElementReferenceCfgNode
287-
}
288-
289-
override SensitiveDataClassification getClassification() {
290-
result = BasicSensitiveVariableAccess.super.getClassification()
291-
}
292-
}
293-
294-
/**
295-
* A parameter node that may contain sensitive data.
296-
*/
297-
class SensitiveParameter extends SensitiveDataSource::Range, DataFlow::ParameterNode instanceof SensitiveNode
298-
{
299-
override SensitiveDataClassification getClassification() {
300-
result = SensitiveNode.super.getClassification()
301-
}
302-
}

ruby/ql/lib/codeql/ruby/security/WeakSensitiveDataHashingCustomizations.qll

Lines changed: 89 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,88 @@ private import codeql.ruby.Concepts
99
private import codeql.ruby.security.SensitiveActions
1010
private 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

Comments
 (0)