Skip to content

Commit f6d2019

Browse files
author
Alvaro Muñoz
committed
When trigger event is not known, do not check context trigger maps
1 parent f3ada4a commit f6d2019

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

ql/lib/codeql/actions/dataflow/FlowSources.qll

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,19 @@ abstract class RemoteFlowSource extends SourceNode {
3131
class GitHubCtxSource extends RemoteFlowSource {
3232
string flag;
3333
string event;
34+
GitHubExpression e;
3435

3536
GitHubCtxSource() {
36-
exists(Expression e, string context, string context_prefix |
37-
this.asExpr() = e and
38-
context = e.getExpression() and
39-
normalizeExpr(context) = "github.head_ref" and
40-
event = e.getEnclosingWorkflow().getATriggerEvent().getName() and
41-
contextTriggerDataModel(event, context_prefix) and
42-
normalizeExpr(context).matches("%" + context_prefix + "%") and
43-
flag = "branch"
37+
this.asExpr() = e and
38+
// github.head_ref
39+
e.getFieldName() = "head_ref" and
40+
flag = "branch" and
41+
(
42+
event = e.getATriggerEvent().getName() and
43+
event = "pull_request_target"
44+
or
45+
not exists(e.getATriggerEvent()) and
46+
event = "unknown"
4447
)
4548
}
4649

@@ -58,15 +61,16 @@ class GitHubEventCtxSource extends RemoteFlowSource {
5861
exists(Expression e, string regexp |
5962
this.asExpr() = e and
6063
context = e.getExpression() and
61-
event = e.getATriggerEvent().getName() and
6264
(
6365
// the context is available for the job trigger events
66+
event = e.getATriggerEvent().getName() and
6467
exists(string context_prefix |
6568
contextTriggerDataModel(event, context_prefix) and
6669
normalizeExpr(context).matches("%" + context_prefix + "%")
6770
)
6871
or
69-
exists(e.getEnclosingCompositeAction())
72+
not exists(e.getATriggerEvent()) and
73+
event = "unknown"
7074
) and
7175
untrustedEventPropertiesDataModel(regexp, flag) and
7276
not flag = "json" and
@@ -182,20 +186,24 @@ class GitHubEventJsonSource extends RemoteFlowSource {
182186
exists(Expression e, string context, string regexp |
183187
this.asExpr() = e and
184188
context = e.getExpression() and
185-
event = e.getEnclosingWorkflow().getATriggerEvent().getName() and
186189
untrustedEventPropertiesDataModel(regexp, _) and
187190
(
188191
// only contexts for the triggering events are considered tainted.
189192
// eg: for `pull_request`, we only consider `github.event.pull_request`
193+
event = e.getEnclosingWorkflow().getATriggerEvent().getName() and
190194
exists(string context_prefix |
191195
contextTriggerDataModel(event, context_prefix) and
192196
normalizeExpr(context).matches("%" + context_prefix + "%")
193197
) and
194198
normalizeExpr(context).regexpMatch("(?i).*" + wrapJsonRegexp(regexp) + ".*")
195199
or
196-
// github.event is taintes for all triggers
200+
// github.event is tainted for all triggers
201+
event = e.getEnclosingWorkflow().getATriggerEvent().getName() and
197202
contextTriggerDataModel(e.getEnclosingWorkflow().getATriggerEvent().getName(), _) and
198203
normalizeExpr(context).regexpMatch("(?i).*" + wrapJsonRegexp("\\bgithub.event\\b") + ".*")
204+
or
205+
not exists(e.getATriggerEvent()) and
206+
event = "unknown"
199207
) and
200208
flag = "json"
201209
)

0 commit comments

Comments
 (0)