Skip to content

Commit 76bc8a5

Browse files
authored
Add a remediation for the workflow_no_pull_request_target rule (#202)
This PR depends on having mindersec/minder#4830 merged first as it takes the remediation function added there into effect. The remediation works as follows: - if there are any instances of pull_request target objects those are removed - else if there are any instances of pull_request strings in an array those are removed - if the resulting array of array of objects would have length 0, `workflow_dispatch` is added instead Fixes: #201
1 parent c5b67e6 commit 76bc8a5

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

rule-types/github/workflow_no_pull_request_target.yaml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,38 @@ def:
5757
# Construct violation message if "pull_request_target" is found
5858
msg := sprintf("Workflow '%v' contains 'pull_request_target' trigger in its 'on' block", [workflows[w]])
5959
}
60+
remediate:
61+
type: pull_request
62+
pull_request:
63+
title: "Replace pull_request_target with pull_request in GitHub Actions workflows"
64+
body: |
65+
This is a Minder automated pull request.
66+
67+
This pull request replaces the 'pull_request_target' event with the 'pull_request' event in GitHub Actions workflows.
68+
69+
The 'pull_request_target' event allows GitHub Actions workflows to run
70+
on pull requests from forks. This can be a security risk, as the event
71+
may, if used improperly, allow untrusted code to run in the
72+
repository.
73+
74+
For more information, see
75+
https://securitylab.github.com/resources/github-actions-preventing-pwn-requests
76+
method: minder.yq.evaluate
77+
params:
78+
expression: |
79+
.on |= (
80+
select(type == "!!map") | with_entries(select(.key != "pull_request_target"))
81+
) |
82+
.on |= (
83+
select(type == "!!seq") | map(select(. != "pull_request_target"))
84+
) |
85+
(.on | select(. == "pull_request_target")) = "workflow_dispatch" |
86+
(.on |= (select(length > 0) // "workflow_dispatch"))
87+
patterns:
88+
- pattern: ".github/workflows/*.yml"
89+
type: glob
90+
- pattern: ".github/workflows/*.yaml"
91+
type: glob
6092
# Defines the configuration for alerting on the rule
6193
alert:
6294
type: security_advisory

0 commit comments

Comments
 (0)