Skip to content

Commit 4a16de2

Browse files
committed
Pull out logic into separate predicate
1 parent fb841ea commit 4a16de2

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

actions/ql/lib/codeql/actions/security/CodeInjectionQuery.qll

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,7 @@ class CodeInjectionSink extends DataFlow::Node {
1919
Event getRelevantCriticalEventForSink(DataFlow::Node sink) {
2020
inPrivilegedContext(sink.asExpr(), result) and
2121
not exists(ControlCheck check | check.protects(sink.asExpr(), result, "code-injection")) and
22-
// exclude cases where the sink is a JS script and the expression uses toJson
23-
not exists(UsesStep script |
24-
script.getCallee() = "actions/github-script" and
25-
script.getArgumentExpr("script") = sink.asExpr() and
26-
exists(getAToJsonReferenceExpression(sink.asExpr().(Expression).getExpression(), _))
27-
)
22+
not isGithubScriptUsingToJson(sink.asExpr())
2823
}
2924

3025
/**
@@ -112,10 +107,17 @@ predicate mediumSeverityCodeInjection(
112107
) {
113108
CodeInjectionFlow::flowPath(source, sink) and
114109
not criticalSeverityCodeInjection(source, sink, _) and
115-
// exclude cases where the sink is a JS script and the expression uses toJson
116-
not exists(UsesStep script |
110+
not isGithubScriptUsingToJson(sink.getNode().asExpr())
111+
}
112+
113+
/**
114+
* Holds if `expr` is the `script` input to `actions/github-script` and it uses
115+
* `toJson`.
116+
*/
117+
predicate isGithubScriptUsingToJson(Expression expr) {
118+
exists(UsesStep script |
117119
script.getCallee() = "actions/github-script" and
118-
script.getArgumentExpr("script") = sink.getNode().asExpr() and
119-
exists(getAToJsonReferenceExpression(sink.getNode().asExpr().(Expression).getExpression(), _))
120+
script.getArgumentExpr("script") = expr and
121+
exists(getAToJsonReferenceExpression(expr.getExpression(), _))
120122
)
121123
}

0 commit comments

Comments
 (0)