Skip to content

Commit 680725a

Browse files
authored
Add lotp + local gha (#286)
1 parent 57eb93e commit 680725a

File tree

2 files changed

+114
-8
lines changed

2 files changed

+114
-8
lines changed

opa/rego/rules/untrusted_checkout_exec.rego

Lines changed: 70 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,39 +15,85 @@ rule := poutine.rule(rego.metadata.chain())
1515

1616
github.events contains event if some event in {
1717
"pull_request_target",
18+
"issues",
1819
"issue_comment",
1920
"workflow_call",
2021
}
2122

2223
github.workflow_run.parent.events contains event if some event in {
2324
"pull_request_target",
2425
"pull_request",
26+
"issues",
27+
"issue_comment",
2528
}
2629

2730
build_github_actions[action] = {
28-
"pre-commit/action": "pre-commit",
29-
"oxsecurity/megalinter": "megalinter",
30-
"bridgecrewio/checkov-action": "checkov",
31-
"ruby/setup-ruby": "bundler",
31+
"bundler":{"ruby/setup-ruby"},
32+
"cargo":{"actions-rs/cargo"},
33+
"checkov":{"bridgecrewio/checkov-action"},
34+
"docker":{"docker/build-push-action", "docker/setup-buildx-action"},
35+
"eslint":{"reviewdog/action-eslint", "stefanoeb/eslint-action", "tj-actions/eslint-changed-files", "sibiraj-s/action-eslint", "tinovyatkin/action-eslint", "bradennapier/eslint-plus-action", "CatChen/eslint-suggestion-action", "iCrawl/action-eslint", "ninosaurus/eslint-check"},
36+
"golangci-lint":{"golangci/golangci-lint-action"},
37+
"goreleaser": {"goreleaser/goreleaser-action"},
38+
"gradle": {"gradle/gradle-build-action"},
39+
"maven": {"qcastel/github-actions-maven-release", "samuelmeuli/action-maven-publish", "LucaFeger/action-maven-cli"},
40+
"megalinter":{"oxsecurity/megalinter"},
41+
"mkdocs": {"mhausenblas/mkdocs-deploy-gh-pages", "athackst/mkdocs-simple-plugin"},
42+
"msbuild": {"MVS-Telecom/publish-nuget"},
43+
"mypy": {"ricardochaves/python-lint", "jpetrucciani/mypy-check", "sunnysid3up/python-linter", "tsuyoshicho/action-mypy"},
44+
"npm": {"actions/setup-node","JS-DevTools/npm-publish"},
45+
"phpstan":{"php-actions/phpstan"},
46+
"pip": {"brettcannon/pip-secure-install", "BSFishy/pip-action"},
47+
"pre-commit": {"dbt-checkpoint/dbt-checkpoint", "pre-commit/action", "pre-commit-ci/lite-action", "browniebroke/pre-commit-autoupdate-action", "cloudposse/github-action-pre-commit"},
48+
"pre-commit":{"pre-commit/action"},
49+
"python": {"hynek/build-and-inspect-python-package"},
50+
"rake": {"magefile/mage-action"},
51+
"rubocop": {"reviewdog/action-rubocop", "andrewmcodes-archive/rubocop-linter-action", "gimenete/rubocop-action", "r7kamura/rubocop-todo-corrector"},
52+
"sonar-scanner": {"sonarsource/sonarqube-scan-action"},
53+
"stylelint":{"actions-hub/stylelint"},
54+
"terraform": {"OP5dev/TF-via-PR", "dflook/terraform-plan", "dflook/terraform-apply"},
55+
"tflint": {"reviewdog/action-tflint", "devops-infra/action-tflint"},
56+
"tofu": {"dflook/tofu-plan", "dflook/tofu-apply"},
57+
"vale": {"gaurav-nelson/github-action-vale-lint", "errata-ai/vale-action"},
3258
}[action]
3359

3460
build_commands[cmd] = {
3561
"ant": {"^ant "},
62+
"bash": {"\\S+\\.sh\\b"},
3663
"bundler": {"bundle install", "bundle exec "},
37-
"cargo": {"cargo build", "cargo run"},
64+
"cargo": {"cargo build", "cargo run", "cargo test", "cargo bench"},
65+
"checkov": {"checkov "},
66+
"chmod": {"^\\s*chmod\\s+(?:.*\\+x.*|\\b(?:[0-7]{2}[1357]|[0-7][0-7]{2}[1357])\\b)"}, # Unit test: https://regex101.com/r/tt7qzw/1
67+
"docker": {"docker build"}, # docker build need to also be run to have significant impact.
68+
"eslint": {"eslint "},
3869
"go generate": {"go generate"},
3970
"gomplate": {"gomplate "},
71+
"goreleaser": {"goreleaser build", "goreleaser release"},
4072
"gradle": {"gradle ", "./gradlew ", "./gradlew.bat "}, # https://docs.gradle.org/current/userguide/gradle_wrapper_basics.html
4173
"make": {"make "},
4274
"maven": {"mvn ", "./mvnw ", "./mvnw.bat", "./mvnw.cmd", "./mvnw.sh "}, # https://maven.apache.org/wrapper/
4375
"mkdocs": {"mkdocs build"},
4476
"msbuild": {"msbuild "},
45-
"npm": {"npm install", "npm run ", "yarn ", "npm ci(\\b|$)"},
77+
"mypy": {"mypy "},
78+
"npm": {"npm diff", "npm restart", "npm (rum|urn|run(-script)?)", "npm start", "npm stop", "npm t(e?st)?", "npm ver(si|is)on","npm (install|add|i|in|ins|inst|insta|instal|inst|isnta|isntal|isntall)", "npm ci(\\b|$)"},
79+
"phpstan": {"phpstan "},
4680
"pip": {"pip install", "pipenv install", "pipenv run "},
81+
"powershell": {"\\S+\\.ps1\\b"},
4782
"pre-commit": {"pre-commit run", "pre-commit install"},
83+
"python": {"^\\s*python(3)?\\s+\\S+\\.py\\b"}, # Unit test: https://regex101.com/r/tuap3y/1
84+
"rake": {"rails db:create", "rails assets:precompile", "^rake "},
85+
"rubocop": {"rubocop"},
86+
"sonar-scanner": {"sonar-scanner"},
87+
"stylelint": {"stylelint "},
88+
"tar": {"tar (-?x-?P-?f|-?P-?x-?f|-?x -P -f|-?P -x -f) "}, # Unit test: https://regex101.com/r/pX85P8/1
4889
"terraform": {"terraform plan", "terraform apply"},
90+
"tflint": {"tflint"},
4991
"tofu": {"tofu plan", "tofu apply"},
92+
"trivy": {"trivy "},
93+
"unzip": {"unzip .*-:"},
5094
"vale": {"vale "},
95+
"webpack": {"webpack"},
96+
"yarn": {"yarn "},
5197
}[cmd]
5298

5399
results contains poutine.finding(rule, pkg_purl, {
@@ -70,7 +116,24 @@ results contains poutine.finding(rule, pkg_purl, {
70116
"event_triggers": workflow_events,
71117
}) if {
72118
[pkg_purl, workflow_path, workflow_events, step] := _steps_after_untrusted_checkout[_]
73-
build_github_actions[step.action]
119+
regex.match(
120+
sprintf("([^a-z]|^)(%v)@", [concat("|", build_github_actions[_])]),
121+
step.uses,
122+
)
123+
}
124+
125+
126+
results contains poutine.finding(rule, pkg_purl, {
127+
"path": workflow_path,
128+
"line": step.lines.uses,
129+
"details": sprintf("Detected usage of a Local GitHub Action at path: `%s`", [step.action]),
130+
"event_triggers": workflow_events,
131+
}) if {
132+
[pkg_purl, workflow_path, workflow_events, step] := _steps_after_untrusted_checkout[_]
133+
regex.match(
134+
`^\./`,
135+
step.action,
136+
)
74137
}
75138

76139
_steps_after_untrusted_checkout contains [pkg.purl, workflow.path, events, s.step] if {

scanner/inventory_test.go

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ package scanner
22

33
import (
44
"context"
5-
"github.com/boostsecurityio/poutine/results"
65
"testing"
76

7+
"github.com/boostsecurityio/poutine/results"
8+
89
"github.com/boostsecurityio/poutine/models"
910
"github.com/boostsecurityio/poutine/opa"
1011
"github.com/stretchr/testify/assert"
@@ -216,6 +217,26 @@ func TestFindings(t *testing.T) {
216217
EventTriggers: []string{"push", "pull_request_target"},
217218
},
218219
},
220+
{
221+
RuleId: "untrusted_checkout_exec",
222+
Purl: purl,
223+
Meta: results.FindingMeta{
224+
Path: ".github/workflows/valid.yml",
225+
Line: 75,
226+
Details: "Detected usage of `bash`",
227+
EventTriggers: []string{"push", "pull_request_target"},
228+
},
229+
},
230+
{
231+
RuleId: "untrusted_checkout_exec",
232+
Purl: purl,
233+
Meta: results.FindingMeta{
234+
Path: ".github/workflows/valid.yml",
235+
Line: 80,
236+
Details: "Detected usage of `bash`",
237+
EventTriggers: []string{"push", "pull_request_target"},
238+
},
239+
},
219240
{
220241
RuleId: "untrusted_checkout_exec",
221242
Purl: purl,
@@ -403,6 +424,17 @@ func TestFindings(t *testing.T) {
403424
Details: "system.debug",
404425
},
405426
},
427+
{
428+
RuleId: "untrusted_checkout_exec",
429+
Purl: purl,
430+
Meta: results.FindingMeta{
431+
Path: "azure-pipelines-2.yml",
432+
Line: 13,
433+
Job: "",
434+
Step: "1",
435+
Details: "Detected usage of `bash`",
436+
},
437+
},
406438
{
407439
RuleId: "untrusted_checkout_exec",
408440
Purl: purl,
@@ -414,6 +446,17 @@ func TestFindings(t *testing.T) {
414446
Details: "Detected usage of `npm`",
415447
},
416448
},
449+
{
450+
RuleId: "untrusted_checkout_exec",
451+
Purl: purl,
452+
Meta: results.FindingMeta{
453+
Path: "azure-pipelines-4.yml",
454+
Line: 10,
455+
Job: "",
456+
Step: "1",
457+
Details: "Detected usage of `bash`",
458+
},
459+
},
417460
{
418461
RuleId: "untrusted_checkout_exec",
419462
Purl: purl,

0 commit comments

Comments
 (0)