Skip to content

Commit 1a273ec

Browse files
committed
Add extra source to actions CWE-094/CodeInjectionMedium
1 parent fb0ee5b commit 1a273ec

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

actions/ql/src/Security/CWE-094/CodeInjectionMedium.ql

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,38 @@ import actions
1818
import codeql.actions.security.CodeInjectionQuery
1919
import CodeInjectionFlow::PathGraph
2020

21+
/**
22+
* A data flow source of user input from github context.
23+
* eg: github.head_ref
24+
* Usually only considered for pull_request_target where access to secrets
25+
* and tokens is more available.
26+
* However this query already finds all context events as sources regardless
27+
* so this should be similar.
28+
*/
29+
class GitHubCtxSourceMediumLikely extends RemoteFlowSource {
30+
string flag;
31+
string event;
32+
33+
GitHubCtxSourceMediumLikely() {
34+
exists(GitHubExpression e |
35+
this.asExpr() = e and
36+
// github.head_ref
37+
e.getFieldName() = "head_ref" and
38+
flag = "branch"
39+
|
40+
event = e.getATriggerEvent().getName() and
41+
event = "pull_request"
42+
or
43+
not exists(e.getATriggerEvent()) and
44+
event = "unknown"
45+
)
46+
}
47+
48+
override string getSourceType() { result = flag }
49+
50+
override string getEventName() { result = event }
51+
}
52+
2153
from CodeInjectionFlow::PathNode source, CodeInjectionFlow::PathNode sink
2254
where mediumSeverityCodeInjection(source, sink)
2355
select sink.getNode(), source, sink,
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* Added source type to `actions/code-injection/medium` such that now `github.head_ref` is found as source even on event `pull_request` (not just `pull_request_target`). This will result in the query finding more results.

0 commit comments

Comments
 (0)