Skip to content

Find the holes before someone else does. A fast, 100% Rust vulnerability scanner: XSS, SQL injection, leaked secrets, dependency CVEs and AI agent setups.

fix(config): flag curl | sh in GitHub Actions run steps (#99)

Onur Ugurcea9e63252c2
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ef700f6..dbc8d96 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -36,6 +36,9 @@
`restrict_public_buckets = false` in an `aws_s3_bucket_public_access_block` or `aws_s3_account_public_access_block`.
- Secrets: new rule `secret.groq-key` (critical) for Groq API keys (`gsk_` followed by 52 letters or digits).
- Code: new rule `code.open-redirect` (medium) for redirects built straight from request input (`res.redirect(req.query.next)`, `redirect(request.args.get("next"))`); a redirect to a fixed path stays unflagged.
+- Config: `config.remote-script` also checks GitHub Actions workflows, so a `run:` step (or a line in a
+ `run: |` block) that pipes `curl` or `wget` into a shell is reported. `curl -o file URL`, a step `name:` and a
+ commented-out line are not.
- Code: `code.sql-injection` also catches Go queries built by concatenation in `db.Query`, `db.QueryRow`, `db.Exec`
and their `Context` variants (`db.Query("SELECT * FROM t WHERE id=" + id)`). A query with a placeholder stays unflagged.
- Code: `code.ssrf` also covers Go (`http.Get`, `http.Head`, `http.Post` with `r.FormValue(...)` or `r.URL.Query().Get(...)`)
diff --git a/src/rules/config.rs b/src/rules/config.rs
index 1217930..661f913 100644
--- a/src/rules/config.rs
+++ b/src/rules/config.rs
@@ -21,6 +21,9 @@ fn shell(f: &FileInfo) -> bool {
fn workflow(f: &FileInfo) -> bool {
f.under(".github/workflows/") && f.ext_in(&["yml", "yaml"])
}
+fn shell_or_workflow(f: &FileInfo) -> bool {
+ shell(f) || workflow(f)
+}
fn yaml(f: &FileInfo) -> bool {
f.ext_in(&["yml", "yaml"])
}
@@ -50,7 +53,7 @@ pub static RULES: &[Rule] = &[
rule!(
"config.remote-script",
Medium,
- shell,
+ shell_or_workflow,
r"\b(?:curl|wget|iwr|Invoke-WebRequest)\b[^|\n]*?(?:https?://|\$\{?\w)[^|\n]*\|\s*(?:sudo\s+)?(?:sh|bash|zsh|python3?|iex)\b",
None,
"A script is downloaded and piped straight into a shell, with no pinning or checksum.",
@@ -199,6 +202,10 @@ static FROM: LazyLock<Regex> =
LazyLock::new(|| Regex::new(r"(?i)^\s*FROM\s+(?:--platform=\S+\s+)?(\S+)").unwrap());
static YAML_KEY: LazyLock<Regex> =
LazyLock::new(|| Regex::new(r"^\s*-?\s*([A-Za-z_][\w-]*)\s*:\s*\S").unwrap());
+// A YAML key needs a space or the line end after its colon, so `C:\Windows\...` in a `run: |`
+// block is a command, not a key.
+static STEP_KEY: LazyLock<Regex> =
+ LazyLock::new(|| Regex::new(r"^\s*-?\s*([A-Za-z_][\w-]*)\s*:(?:\s|$)").unwrap());
// The whole `key = false`, not just the key, so `= true # was block_public_policy = false`
// is judged by the part in the comment, which the walk then rejects.
// The rule's own pattern (`key = false` that ends the value), found again on the line in `keep`.
@@ -375,6 +382,15 @@ pub fn keep(file: &FileInfo, text: &Text, f: &Finding, hcl: &mut HclWalk) -> boo
"config.gha-script-injection" if workflow(file) => YAML_KEY
.captures(text.line(f.line))
.is_none_or(|c| &c[1] == "run" || &c[1] == "script"),
+ // In a workflow only a `run:` step (or a line of its block) runs; a step `name:` or a
+ // commented-out line doesn't.
+ "config.remote-script" if workflow(file) => {
+ let line = text.line(f.line);
+ !line.trim_start().starts_with('#')
+ && STEP_KEY
+ .captures(line)
+ .is_none_or(|c| &c[1] == "run" || &c[1] == "script")
+ }
"config.tf-public-access-block" => {
let line = text.line(f.line);
let start = text.line_start(f.line);
diff --git a/tests/fixtures/config/.github/workflows/ci.yml b/tests/fixtures/config/.github/workflows/ci.yml
index 2aa2f6f..478f6b4 100644
--- a/tests/fixtures/config/.github/workflows/ci.yml
+++ b/tests/fixtures/config/.github/workflows/ci.yml
@@ -13,3 +13,13 @@ jobs:
branch: ${{ github.head_ref }}
- run: |
git push origin ${{ github.head_ref }}
+ - run: curl -fsSL https://get.example.com | sh
+ - run: curl -fsSL -o install.sh https://get.example.com
+ - run: |
+ echo "installing tools"
+ curl -fsSL https://get.example.com/tools.sh | sudo bash
+ - name: Do not run curl -fsSL https://get.example.com | sh
+ run: echo "pinned installer"
+ # - run: curl -fsSL https://get.example.com | sh
+ - run: |
+ C:\Windows\System32\curl.exe -fsSL https://get.example.com | bash
diff --git a/tests/fixtures/config/EXPECTED b/tests/fixtures/config/EXPECTED
index 2c7d54f..a936bc2 100644
--- a/tests/fixtures/config/EXPECTED
+++ b/tests/fixtures/config/EXPECTED
@@ -3,6 +3,9 @@
.github/workflows/ci.yml:2 config.gha-pull-request-target
.github/workflows/ci.yml:3 config.gha-write-all
.github/workflows/ci.yml:8 config.gha-unpinned-action
+.github/workflows/ci.yml:16 config.remote-script
+.github/workflows/ci.yml:20 config.remote-script
+.github/workflows/ci.yml:25 config.remote-script
Dockerfile:1 config.docker-unpinned-image
Dockerfile:3 config.docker-unpinned-image
Dockerfile:4 config.docker-secret-env