Skip to content

Commit 672cb92

Browse files
p-erik-krogh
andauthored
Ruby: improve non-constant-kernel-open, recursive step for freeze
Co-authored-by: Erik Krogh Kristensen <[email protected]>
1 parent 2f268b3 commit 672cb92

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

ruby/ql/src/queries/security/cwe-078/NonConstantKernelOpen.ql

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ predicate hasConstantPrefix(DataFlow::Node node) {
3737
node.asExpr().getExpr().(StringlikeLiteral).getComponent(0) instanceof StringTextComponent
3838
or
3939
// it is not a constant string argument
40-
exists(node.asExpr().getExpr().getConstantValue())
40+
exists(node.getConstantValue())
4141
or
4242
// not a concatenation that starts with a constant string
4343
exists(DataFlow::ExprNode prefix |
@@ -46,5 +46,13 @@ predicate hasConstantPrefix(DataFlow::Node node) {
4646
)
4747
or
4848
// is a .freeze call on a constant string
49-
node.asExpr().getExpr().(ConstantReadAccess).getValue().(MethodCall).getMethodName() = "freeze"
49+
exists(DataFlow::CallNode call | node = call and call.getMethodName() = "freeze" |
50+
hasConstantPrefix(call.getReceiver())
51+
)
52+
or
53+
// is a constant read of a constant string
54+
exists(DataFlow::Node constant |
55+
constant.asExpr().getExpr() = node.asExpr().getExpr().(ConstantReadAccess).getValue() and
56+
hasConstantPrefix(constant)
57+
)
5058
}

0 commit comments

Comments
 (0)