@@ -155,6 +155,20 @@ predicate envToEnvStoreStep(DataFlow::Node pred, DataFlow::Node succ, DataFlow::
155
155
)
156
156
}
157
157
158
+ predicate controlledCWD ( Step artifact ) {
159
+ artifact instanceof UntrustedArtifactDownloadStep or
160
+ // This shoould be:
161
+ // artifact instanceof PRHeadCheckoutStep
162
+ // but PRHeadCheckoutStep uses Taint Tracking anc causes a non-Monolitic Recursion error
163
+ // so we list all the subclasses of PRHeadCheckoutStep here and use actions/checkout as a workaround
164
+ // instead of using ActionsMutableRefCheckout and ActionsSHACheckout
165
+ artifact .( Uses ) .getCallee ( ) = "actions/checkout" or
166
+ artifact instanceof GitMutableRefCheckout or
167
+ artifact instanceof GitSHACheckout or
168
+ artifact instanceof GhMutableRefCheckout or
169
+ artifact instanceof GhSHACheckout
170
+ }
171
+
158
172
/**
159
173
* A downloaded artifact that gets assigned to a Run step output.
160
174
* - uses: actions/download-artifact@v2
@@ -165,10 +179,7 @@ predicate envToEnvStoreStep(DataFlow::Node pred, DataFlow::Node succ, DataFlow::
165
179
*/
166
180
predicate artifactToOutputStoreStep ( DataFlow:: Node pred , DataFlow:: Node succ , DataFlow:: ContentSet c ) {
167
181
exists ( Run run , Step artifact , string content , string key , string value |
168
- (
169
- artifact instanceof UntrustedArtifactDownloadStep or
170
- artifact instanceof PRHeadCheckoutStep
171
- ) and
182
+ controlledCWD ( artifact ) and
172
183
(
173
184
// A file is read and its content is assigned to an env var
174
185
// - run: |
@@ -207,10 +218,7 @@ predicate artifactToOutputStoreStep(DataFlow::Node pred, DataFlow::Node succ, Da
207
218
*/
208
219
predicate artifactToEnvStoreStep ( DataFlow:: Node pred , DataFlow:: Node succ , DataFlow:: ContentSet c ) {
209
220
exists ( Run run , string content , string key , string value , Step artifact |
210
- (
211
- artifact instanceof UntrustedArtifactDownloadStep or
212
- artifact instanceof PRHeadCheckoutStep
213
- ) and
221
+ controlledCWD ( artifact ) and
214
222
(
215
223
// A file is read and its content is assigned to an env var
216
224
// - run: |
@@ -246,25 +254,20 @@ predicate artifactToEnvStoreStep(DataFlow::Node pred, DataFlow::Node succ, DataF
246
254
*/
247
255
predicate artifactDownloadToRunStep ( DataFlow:: Node pred , DataFlow:: Node succ ) {
248
256
exists ( Step artifact , Run run |
249
- (
250
- artifact instanceof UntrustedArtifactDownloadStep or
251
- artifact instanceof PRHeadCheckoutStep
252
- ) and
257
+ controlledCWD ( artifact ) and
253
258
pred .asExpr ( ) = artifact and
254
259
succ .asExpr ( ) = run .getScriptScalar ( ) and
255
260
artifact .getAFollowingStep ( ) = run
256
261
)
257
262
}
258
263
264
+ //
259
265
/**
260
266
* A download artifact step followed by a envvar-injection uses step .
261
267
*/
262
268
predicate artifactDownloadToUsesStep ( DataFlow:: Node pred , DataFlow:: Node succ ) {
263
269
exists ( Step artifact , Uses uses |
264
- (
265
- artifact instanceof UntrustedArtifactDownloadStep or
266
- artifact instanceof PRHeadCheckoutStep
267
- ) and
270
+ controlledCWD ( artifact ) and
268
271
madSink ( succ , "envvar-injection" ) and
269
272
pred .asExpr ( ) = artifact and
270
273
succ .asExpr ( ) = uses and
0 commit comments