-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rename DO- rules, inventory remaining rules missing from lv1 profile (#…
…279) * Add rule for OSPS-BR-01 * Rename DO- rules, inventory remaining rules missing from lv1 profile
- Loading branch information
1 parent
0fe35c1
commit cc41246
Showing
16 changed files
with
287 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
tests: | ||
- name: No workflows | ||
def: {} | ||
params: {} | ||
expect: "pass" | ||
git: | ||
repo_base: no_workflows | ||
- name: Safe workflows | ||
def: {} | ||
params: {} | ||
expect: pass | ||
git: | ||
repo_base: safe_workflows | ||
- name: Unsafe checkout | ||
def: {} | ||
params: {} | ||
expect: fail | ||
error_text: | | ||
evaluation failure: Evaluation failures: | ||
- Workflow .github/workflows/pr_test.yaml has a dangerous trigger and checks out a pull request in job 'test' | ||
- Workflow .github/workflows/pr_workflow.yaml has a dangerous trigger and checks out a pull request in job 'exec' | ||
git: | ||
repo_base: unsafe_checkout | ||
- name: Script injection | ||
def: {} | ||
params: {} | ||
expect: fail | ||
error_text: | | ||
evaluation failure: Evaluation failures: | ||
- Workflow .github/workflows/pr_title.yaml has possible event script injection in step 0 of job 'check-title' | ||
git: | ||
repo_base: script_injection |
3 changes: 3 additions & 0 deletions
3
security-baseline/rule-types/github/osps-br-01.testdata/no_workflows/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Empty repo | ||
|
||
This repo does not have any workflows at all, which is a safe configuration. |
18 changes: 18 additions & 0 deletions
18
...eline/rule-types/github/osps-br-01.testdata/safe_workflows/.github/workflows/pr_test.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Example test workflow for the GitHub Action feature | ||
name: Test PR | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Run tests | ||
run: make test |
15 changes: 15 additions & 0 deletions
15
...ne/rule-types/github/osps-br-01.testdata/script_injection/.github/workflows/pr_title.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
on: [pull_request] | ||
|
||
jobs: | ||
check-title: | ||
name: Check PR title | ||
runs-on: ubuntu-latest | ||
steps: | ||
|
||
- name: Check PR title | ||
run: | | ||
title="${{ github.event.issue.title }}" | ||
if [[ ! $title =~ ^.*:\ .*$ ]]; then | ||
echo "Bad issue title" | ||
exit 1 | ||
fi |
20 changes: 20 additions & 0 deletions
20
...line/rule-types/github/osps-br-01.testdata/unsafe_checkout/.github/workflows/pr_test.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Example test workflow for the GitHub Action feature | ||
name: Test PR | ||
|
||
on: | ||
pull_request_target: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
with: | ||
ref: ${{ github.event.pull_request.head.sha }} | ||
|
||
- name: Run tests | ||
run: make test |
17 changes: 17 additions & 0 deletions
17
.../rule-types/github/osps-br-01.testdata/unsafe_checkout/.github/workflows/pr_workflow.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Example test workflow for the GitHub Action feature | ||
name: Test PR | ||
|
||
on: [workflow_run] | ||
|
||
jobs: | ||
exec: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
with: | ||
ref: ${{ github.event.pull_request.head.sha }} | ||
|
||
- name: Run tests | ||
run: make test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
version: v1 | ||
release_phase: alpha | ||
type: rule-type | ||
name: osps-br-01 | ||
display_name: Prevent untrusted input in continuous integration | ||
short_failure_message: Untrusted input can subvert workflows | ||
severity: | ||
value: critical | ||
context: | ||
provider: github | ||
description: | | ||
This check determines whether the project's GitHub Action workflows | ||
have dangerous code patterns. Some examples of these patterns are | ||
untrusted code checkouts, logging github context and secrets, or use | ||
of potentially untrusted inputs in scripts. The following patterns | ||
are checked: | ||
* Untrusted Code Checkout: This is the misuse of potentially | ||
dangerous triggers. This checks if a pull_request_target or | ||
workflow_run workflow trigger was used in conjunction with an | ||
explicit pull request checkout. Workflows triggered with | ||
pull_request_target / workflow_run have write permission to the | ||
target repository and access to target repository secrets. | ||
* Script Injection with Untrusted Context Variables: This pattern | ||
detects whether a workflow's inline script may execute untrusted | ||
input from attackers. Attackers can add their own content to | ||
certain github context variables that are considered untrusted, | ||
for example, github.event.issue.title. These values should not flow | ||
directly into executable code. | ||
guidance: | | ||
Avoid using pull_request_target and workflow_run workflow triggers with | ||
contributor-supplied code, following [GitHub's guidance](https://securitylab.github.com/research/github-actions-preventing-pwn-requests/) | ||
[Quote or escape untrusted context variables](https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#understanding-the-risk-of-script-injections) | ||
before using them in scripts. | ||
def: | ||
in_entity: repository | ||
rule_schema: {} | ||
ingest: | ||
type: git | ||
eval: | ||
type: rego | ||
rego: | ||
type: constraints | ||
def: | | ||
package minder | ||
import rego.v1 | ||
# Match both .yml and .yaml files | ||
workflows := array.concat(file.ls_glob("./.github/workflows/*.yml"), file.ls_glob("./.github/workflows/*.yaml")) | ||
dangerous_triggers = ["pull_request_target", "workflow_run"] | ||
# Look for dangerous triggers combined with checkout of user-controlled code. | ||
violations[{"msg": msg}] if { | ||
some w | ||
contents := file.read(workflows[w]) | ||
workflow := parse_yaml(contents) | ||
events := events_set(workflow.on) | ||
some event in events | ||
event in dangerous_triggers | ||
some job | ||
some step | ||
stepDef := workflow.jobs[job].steps[step] | ||
startswith(stepDef.uses, "actions/checkout") | ||
# This action is only dangerous if we check out the attacker-controlled branch | ||
dangerous_ref(stepDef["with"].ref) | ||
msg := sprintf("Workflow %s has a dangerous trigger and checks out a pull request in job '%s'", [workflows[w], job]) | ||
} | ||
events_set(events) := object.keys(events) if { | ||
is_object(events) | ||
} | ||
events_set(events) := events if { | ||
is_array(events) | ||
} | ||
dangerous_ref(ref) if { | ||
contains(ref, "github.event.pull_request") | ||
} | ||
dangerous_ref(ref) if { | ||
contains(ref, "github.event.workflow_run") | ||
} | ||
# Look for possible script injections | ||
violations[{"msg": msg}] if { | ||
some w | ||
contents := file.read(workflows[w]) | ||
workflow := parse_yaml(contents) | ||
some job | ||
some step | ||
stepDef := workflow.jobs[job].steps[step] | ||
stepDef.run | ||
stepDef.run != "make test" | ||
regexp := "\\${{(.*?)}}" | ||
expansions := regex.find_all_string_submatch_n(regexp, stepDef.run, -1) | ||
some expr in expansions | ||
vulnerable_expansion(expr[1]) | ||
msg := sprintf("Workflow %s has possible event script injection in step %d of job '%s'", [workflows[w], step, job]) | ||
} | ||
# Patterns from https://securitylab.github.com/resources/github-actions-untrusted-input/ | ||
vulnerable_patterns := { | ||
"github.event.issue.title", | ||
"github.event.issue.body", | ||
"github.event.pull_request.title", | ||
"github.event.pull_request.body", | ||
"github.event.comment.body", | ||
"github.event.review.body", | ||
"github.event.pages.*.page_name", | ||
"github.event.commits.*.message", | ||
"github.event.head_commit.message", | ||
"github.event.head_commit.author.email", | ||
"github.event.head_commit.author.name", | ||
"github.event.commits.*.author.email", | ||
"github.event.commits.*.author.name", | ||
"github.event.pull_request.head.ref", | ||
"github.event.pull_request.head.label", | ||
"github.event.pull_request.head.repo.default_branch", | ||
"github.head_ref", | ||
} | ||
vulnerable_expansion(exp) if { | ||
some match in vulnerable_patterns | ||
matcher := concat("", ["*", match, "*"]) | ||
glob.match(matcher, null, exp) | ||
} | ||
2 changes: 1 addition & 1 deletion
2
...aseline/rule-types/github/osps-do-01.yaml → ...aseline/rule-types/github/osps-gv-02.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...aseline/rule-types/github/osps-do-02.yaml → ...aseline/rule-types/github/osps-gv-03.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters