Skip to content

Commit 6a46fb5

Browse files
committed
Ruby: Add SensitiveDataSource abstract class
1 parent f017821 commit 6a46fb5

File tree

2 files changed

+81
-5
lines changed

2 files changed

+81
-5
lines changed

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

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,3 +224,79 @@ 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: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ module NormalHashFunction {
4949
/**
5050
* A source of sensitive data, considered as a flow source.
5151
*/
52-
class SensitiveNodeSourceAsSource extends Source instanceof SensitiveNode {
52+
class SensitiveDataSourceAsSource extends Source instanceof SensitiveDataSource {
5353
override SensitiveDataClassification getClassification() {
54-
result = SensitiveNode.super.getClassification()
54+
result = SensitiveDataSource.super.getClassification()
5555
}
5656
}
5757

@@ -118,13 +118,13 @@ module ComputationallyExpensiveHashFunction {
118118
/**
119119
* A source of passwords, considered as a flow source.
120120
*/
121-
class PasswordSourceAsSource extends Source instanceof SensitiveNode {
121+
class PasswordSourceAsSource extends Source instanceof SensitiveDataSource {
122122
PasswordSourceAsSource() {
123-
this.(SensitiveNode).getClassification() = SensitiveDataClassification::password()
123+
this.(SensitiveDataSource).getClassification() = SensitiveDataClassification::password()
124124
}
125125

126126
override SensitiveDataClassification getClassification() {
127-
result = SensitiveNode.super.getClassification()
127+
result = SensitiveDataSource.super.getClassification()
128128
}
129129
}
130130

0 commit comments

Comments
 (0)