Skip to content

Commit 06d7b3c

Browse files
Use cfg nodes
1 parent ec973ac commit 06d7b3c

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55

66
private import codeql.ruby.AST
7+
private import codeql.ruby.controlflow.CfgNodes
78
private import codeql.ruby.DataFlow
89
private import codeql.ruby.TaintTracking
910
private import codeql.ruby.dataflow.RemoteFlowSources
@@ -55,30 +56,30 @@ module MassAssignment {
5556
}
5657

5758
/** Holds if `h` is an empty hash or contains an empty hash at one if its (possibly nested) values. */
58-
private predicate hasEmptyHash(Expr e) {
59-
e instanceof HashLiteral and
60-
not exists(e.(HashLiteral).getAKeyValuePair())
59+
private predicate hasEmptyHash(ExprCfgNode e) {
60+
e instanceof ExprNodes::HashLiteralCfgNode and
61+
not exists(e.(ExprNodes::HashLiteralCfgNode).getAKeyValuePair())
6162
or
62-
hasEmptyHash(e.(HashLiteral).getAKeyValuePair().getValue())
63+
hasEmptyHash(e.(ExprNodes::HashLiteralCfgNode).getAKeyValuePair().getValue())
6364
or
64-
hasEmptyHash(e.(Pair).getValue())
65+
hasEmptyHash(e.(ExprNodes::PairCfgNode).getValue())
6566
or
66-
hasEmptyHash(e.(ArrayLiteral).getAnElement())
67+
hasEmptyHash(e.(ExprNodes::ArrayLiteralCfgNode).getAnArgument())
6768
}
6869

6970
/** A call to `permit` that fully specifies the permitted parameters. */
7071
private class PermitCallSanitizer extends Sanitizer, DataFlow::CallNode {
7172
PermitCallSanitizer() {
7273
this.getMethodName() = "permit" and
73-
not hasEmptyHash(this.getArgument(_).asExpr().getExpr())
74+
not hasEmptyHash(this.getArgument(_).getExprNode())
7475
}
7576
}
7677

7778
/** A call to `permit` that uses an empty hash, which allows arbitrary keys to be specified. */
7879
private class PermitCallMassPermit extends MassPermit instanceof DataFlow::CallNode {
7980
PermitCallMassPermit() {
8081
this.(DataFlow::CallNode).getMethodName() = "permit" and
81-
hasEmptyHash(this.(DataFlow::CallNode).getArgument(_).asExpr().getExpr())
82+
hasEmptyHash(this.(DataFlow::CallNode).getArgument(_).getExprNode())
8283
}
8384

8485
override DataFlow::Node getParamsArgument() { result = this.(DataFlow::CallNode).getReceiver() }

0 commit comments

Comments
 (0)