@@ -52,29 +52,43 @@ class GitHubCtxSource extends RemoteFlowSource {
5252 override string getEventName ( ) { result = event }
5353}
5454
55+ bindingset [ expression]
56+ pragma [ inline_late]
57+ private predicate untrustedEventProperty ( Expression expression , string kind ) {
58+ exists ( string regexp |
59+ untrustedEventPropertiesDataModel ( regexp , kind ) and
60+ kind != "json" and
61+ normalizeExpr ( expression .getExpression ( ) ) .regexpMatch ( "(?i)\\s*" + wrapRegexp ( regexp ) + ".*" )
62+ )
63+ }
64+
65+ bindingset [ expression, event]
66+ pragma [ inline_late]
67+ private predicate expressionContainsEventContext ( Expression expression , string event ) {
68+ exists ( string contextPrefix |
69+ contextTriggerDataModel ( event , contextPrefix ) and
70+ normalizeExpr ( expression .getExpression ( ) ) .matches ( "%" + contextPrefix + "%" )
71+ )
72+ }
73+
5574class GitHubEventCtxSource extends RemoteFlowSource {
5675 string flag ;
5776 string context ;
5877 string event ;
5978
6079 GitHubEventCtxSource ( ) {
61- exists ( Expression e , string regexp |
80+ exists ( Expression e |
6281 this .asExpr ( ) = e and
6382 context = e .getExpression ( ) and
6483 (
6584 // the context is available for the job trigger events
6685 event = e .getATriggerEvent ( ) .getName ( ) and
67- exists ( string context_prefix |
68- contextTriggerDataModel ( event , context_prefix ) and
69- normalizeExpr ( context ) .matches ( "%" + context_prefix + "%" )
70- )
86+ expressionContainsEventContext ( e , event )
7187 or
7288 not exists ( e .getATriggerEvent ( ) ) and
7389 event = "unknown"
7490 ) and
75- untrustedEventPropertiesDataModel ( regexp , flag ) and
76- not flag = "json" and
77- normalizeExpr ( context ) .regexpMatch ( "(?i)\\s*" + wrapRegexp ( regexp ) + ".*" )
91+ untrustedEventProperty ( e , flag )
7892 )
7993 }
8094
@@ -177,32 +191,41 @@ class GitHubEventPathSource extends RemoteFlowSource, CommandSource {
177191 override Run getEnclosingRun ( ) { result = run }
178192}
179193
194+ bindingset [ expression, event]
195+ pragma [ inline_late]
196+ private predicate jsonSourceForEvent ( Expression expression , string event ) {
197+ exists ( string context , string regexp , string contextPrefix |
198+ context = expression .getExpression ( ) and
199+ untrustedEventPropertiesDataModel ( regexp , _) and
200+ contextTriggerDataModel ( event , contextPrefix ) and
201+ normalizeExpr ( context ) .matches ( "%" + contextPrefix + "%" ) and
202+ normalizeExpr ( context ) .regexpMatch ( "(?i).*" + wrapJsonRegexp ( regexp ) + ".*" )
203+ )
204+ or
205+ exists ( string context |
206+ context = expression .getExpression ( ) and
207+ untrustedEventPropertiesDataModel ( _, _) and
208+ contextTriggerDataModel ( event , _) and
209+ normalizeExpr ( context ) .regexpMatch ( "(?i).*" + wrapJsonRegexp ( "\\bgithub.event\\b" ) + ".*" )
210+ )
211+ }
212+
180213class GitHubEventJsonSource extends RemoteFlowSource {
181214 string flag ;
182215 string event ;
183216
184217 GitHubEventJsonSource ( ) {
185- exists ( Expression e , string context , string regexp |
218+ exists ( Expression e |
186219 this .asExpr ( ) = e and
187- context = e .getExpression ( ) and
188- untrustedEventPropertiesDataModel ( regexp , _) and
189220 (
190221 // only contexts for the triggering events are considered tainted.
191222 // eg: for `pull_request`, we only consider `github.event.pull_request`
192223 event = e .getEnclosingWorkflow ( ) .getATriggerEvent ( ) .getName ( ) and
193- exists ( string context_prefix |
194- contextTriggerDataModel ( event , context_prefix ) and
195- normalizeExpr ( context ) .matches ( "%" + context_prefix + "%" )
196- ) and
197- normalizeExpr ( context ) .regexpMatch ( "(?i).*" + wrapJsonRegexp ( regexp ) + ".*" )
198- or
199- // github.event is tainted for all triggers
200- event = e .getEnclosingWorkflow ( ) .getATriggerEvent ( ) .getName ( ) and
201- contextTriggerDataModel ( e .getEnclosingWorkflow ( ) .getATriggerEvent ( ) .getName ( ) , _) and
202- normalizeExpr ( context ) .regexpMatch ( "(?i).*" + wrapJsonRegexp ( "\\bgithub.event\\b" ) + ".*" )
224+ jsonSourceForEvent ( e , event )
203225 or
204226 not exists ( e .getATriggerEvent ( ) ) and
205- event = "unknown"
227+ event = "unknown" and
228+ untrustedEventPropertiesDataModel ( _, _)
206229 ) and
207230 flag = "json"
208231 )
0 commit comments