Skip to content

Commit 59ab384

Browse files
committed
Ruby: rb/clear-text-logging-sensitive-data - match on CFG nodes rather than AST nodes
1 parent 81ed5d0 commit 59ab384

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,15 +210,17 @@ module CleartextLogging {
210210
private string name;
211211

212212
HashLiteralPasswordSource() {
213-
exists(DataFlow::Node val, HashLiteral lit |
213+
exists(DataFlow::Node val, CfgNodes::ExprNodes::HashLiteralCfgNode lit |
214214
name.regexpMatch(maybePassword()) and
215215
not name.regexpMatch(notSensitiveRegexp()) and
216216
// avoid safe values assigned to presumably unsafe names
217217
not val instanceof NonCleartextPassword and
218218
// hash = { name: val }
219-
exists(Pair p | this.asExpr().getExpr() = lit and p = lit.getAKeyValuePair() |
219+
exists(CfgNodes::ExprNodes::PairCfgNode p |
220+
this.asExpr() = lit and p = lit.getAKeyValuePair()
221+
|
220222
p.getKey().getConstantValue().getStringOrSymbol() = name and
221-
p.getValue() = val.asExpr().getExpr()
223+
p.getValue() = val.asExpr()
222224
)
223225
)
224226
}

ruby/ql/test/query-tests/security/cwe-312/CleartextLogging.expected

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ edges
1010
| logging.rb:3:12:3:45 | "043697b96909e03ca907599d6420555f" : | logging.rb:23:33:23:40 | password |
1111
| logging.rb:3:12:3:45 | "043697b96909e03ca907599d6420555f" : | logging.rb:26:18:26:34 | "pw: #{...}" |
1212
| logging.rb:3:12:3:45 | "043697b96909e03ca907599d6420555f" : | logging.rb:28:26:28:33 | password |
13+
| logging.rb:30:8:30:55 | call to [] : | logging.rb:37:20:37:23 | hsh1 : |
1314
| logging.rb:34:1:34:15 | call to []= : | logging.rb:39:20:39:34 | ...[...] |
15+
| logging.rb:37:20:37:23 | hsh1 : | logging.rb:37:20:37:34 | ...[...] |
1416
| logging.rb:60:38:60:71 | "ca497451f5e883662fb1a37bc9ec7838" : | logging.rb:73:20:73:53 | password_masked_ineffective_sub_ex |
1517
| logging.rb:62:39:62:72 | "a7e3747b19930d4f4b8181047194832f" : | logging.rb:75:20:75:54 | password_masked_ineffective_gsub_ex |
1618
| logging.rb:63:35:63:88 | call to sub : | logging.rb:69:20:69:50 | password_masked_ineffective_sub |
@@ -31,7 +33,10 @@ nodes
3133
| logging.rb:23:33:23:40 | password | semmle.label | password |
3234
| logging.rb:26:18:26:34 | "pw: #{...}" | semmle.label | "pw: #{...}" |
3335
| logging.rb:28:26:28:33 | password | semmle.label | password |
36+
| logging.rb:30:8:30:55 | call to [] : | semmle.label | call to [] : |
3437
| logging.rb:34:1:34:15 | call to []= : | semmle.label | call to []= : |
38+
| logging.rb:37:20:37:23 | hsh1 : | semmle.label | hsh1 : |
39+
| logging.rb:37:20:37:34 | ...[...] | semmle.label | ...[...] |
3540
| logging.rb:39:20:39:34 | ...[...] | semmle.label | ...[...] |
3641
| logging.rb:60:38:60:71 | "ca497451f5e883662fb1a37bc9ec7838" : | semmle.label | "ca497451f5e883662fb1a37bc9ec7838" : |
3742
| logging.rb:62:39:62:72 | "a7e3747b19930d4f4b8181047194832f" : | semmle.label | "a7e3747b19930d4f4b8181047194832f" : |
@@ -58,7 +63,8 @@ subpaths
5863
| logging.rb:23:33:23:40 | password | logging.rb:3:12:3:45 | "043697b96909e03ca907599d6420555f" : | logging.rb:23:33:23:40 | password | Sensitive data returned by $@ is logged here. | logging.rb:3:12:3:45 | "043697b96909e03ca907599d6420555f" | an assignment to password |
5964
| logging.rb:26:18:26:34 | "pw: #{...}" | logging.rb:3:12:3:45 | "043697b96909e03ca907599d6420555f" : | logging.rb:26:18:26:34 | "pw: #{...}" | Sensitive data returned by $@ is logged here. | logging.rb:3:12:3:45 | "043697b96909e03ca907599d6420555f" | an assignment to password |
6065
| logging.rb:28:26:28:33 | password | logging.rb:3:12:3:45 | "043697b96909e03ca907599d6420555f" : | logging.rb:28:26:28:33 | password | Sensitive data returned by $@ is logged here. | logging.rb:3:12:3:45 | "043697b96909e03ca907599d6420555f" | an assignment to password |
61-
| logging.rb:39:20:39:34 | ...[...] | logging.rb:34:1:34:15 | call to []= : | logging.rb:39:20:39:34 | ...[...] | Sensitive data returned by $@ is logged here. | logging.rb:34:1:34:15 | call to []= | an write to password |
66+
| logging.rb:37:20:37:34 | ...[...] | logging.rb:30:8:30:55 | call to [] : | logging.rb:37:20:37:34 | ...[...] | Sensitive data returned by $@ is logged here. | logging.rb:30:8:30:55 | call to [] | an write to password |
67+
| logging.rb:39:20:39:34 | ...[...] | logging.rb:34:1:34:15 | call to []= : | logging.rb:39:20:39:34 | ...[...] | Sensitive data returned by $@ is logged here. | logging.rb:34:1:34:15 | call to []= | a write to password |
6268
| logging.rb:69:20:69:50 | password_masked_ineffective_sub | logging.rb:63:35:63:88 | call to sub : | logging.rb:69:20:69:50 | password_masked_ineffective_sub | Sensitive data returned by $@ is logged here. | logging.rb:63:35:63:88 | call to sub | an assignment to password_masked_ineffective_sub |
6369
| logging.rb:71:20:71:51 | password_masked_ineffective_gsub | logging.rb:65:36:65:86 | call to gsub : | logging.rb:71:20:71:51 | password_masked_ineffective_gsub | Sensitive data returned by $@ is logged here. | logging.rb:65:36:65:86 | call to gsub | an assignment to password_masked_ineffective_gsub |
6470
| logging.rb:73:20:73:53 | password_masked_ineffective_sub_ex | logging.rb:60:38:60:71 | "ca497451f5e883662fb1a37bc9ec7838" : | logging.rb:73:20:73:53 | password_masked_ineffective_sub_ex | Sensitive data returned by $@ is logged here. | logging.rb:60:38:60:71 | "ca497451f5e883662fb1a37bc9ec7838" | an assignment to password_masked_ineffective_sub_ex |

0 commit comments

Comments
 (0)