Skip to content

Commit 24dad55

Browse files
committed
Ruby: fix SensitiveNode detection relating to class/instance variables
1 parent 36a1b18 commit 24dad55

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,13 @@ private predicate writesProperty(DataFlow::Node node, string name) {
8484
node.(DataFlow::CallNode).getArgument(0).asExpr().getConstantValue().isStringlikeValue(name)
8585
}
8686

87+
/**
88+
* Instance and class variable names are reported with their respective `@`
89+
* and `@@` prefixes. This predicate strips these prefixes.
90+
*/
91+
bindingset[name]
92+
private string unprefixedVariableName(string name) { result = name.regexpReplaceAll("^@*", "") }
93+
8794
/** A write to a variable or property that might contain sensitive data. */
8895
private class BasicSensitiveWrite extends SensitiveWrite {
8996
SensitiveDataClassification classification;
@@ -104,7 +111,7 @@ private class BasicSensitiveWrite extends SensitiveWrite {
104111
*/
105112

106113
writesProperty(this, name) and
107-
nameIndicatesSensitiveData(name, classification)
114+
nameIndicatesSensitiveData(unprefixedVariableName(name), classification)
108115
)
109116
}
110117

@@ -116,7 +123,9 @@ private class BasicSensitiveWrite extends SensitiveWrite {
116123
private class BasicSensitiveVariableAccess extends SensitiveVariableAccess {
117124
SensitiveDataClassification classification;
118125

119-
BasicSensitiveVariableAccess() { nameIndicatesSensitiveData(name, classification) }
126+
BasicSensitiveVariableAccess() {
127+
nameIndicatesSensitiveData(unprefixedVariableName(name), classification)
128+
}
120129

121130
override SensitiveDataClassification getClassification() { result = classification }
122131
}

0 commit comments

Comments
 (0)