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): skip # comment lines in remote-script across shell and Dockerfiles (#198)

Brixton Pham523dcc0a57c0
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8837a56..d5380b8 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,9 @@
## Unreleased
+- Config: `config.remote-script` no longer reports a `#` comment line in shell and PowerShell
+ scripts, Dockerfiles and Makefiles (`# Usage: curl -fsSL https://example.com/install.sh | bash`),
+ as it already did in workflows.
- Secrets: `secret.env-file` and `secret.env-example-value` no longer report file paths starting
with `/`, `./`, `../` or `~/` on variables ending in `_FILE`, `_PATH` or `_DIR` or named `PWD`
(`POSTGRES_PASSWORD_FILE=/run/secrets/postgres_password`, `PRIVATE_KEY_PATH=./certs/server.key`,
diff --git a/src/rules/config.rs b/src/rules/config.rs
index af8c1b1..8fac14f 100644
--- a/src/rules/config.rs
+++ b/src/rules/config.rs
@@ -470,14 +470,16 @@ pub fn keep(file: &FileInfo, text: &Text, f: &Finding, hcl: &mut HclWalk) -> boo
.captures(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) => {
+ // A `#` comment line in a shell script, PowerShell script, Dockerfile, Makefile or
+ // workflow does not run; in a workflow, only a `run:` or `script:` step (or a line of
+ // its block) runs, not a step `name:`.
+ "config.remote-script" => {
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")
+ && (!workflow(file)
+ || 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);
@@ -705,4 +707,37 @@ mod tests {
assert_eq!(walk.block_at(src, at), HclWalk::default().block_at(src, at));
}
}
+
+ #[test]
+ fn remote_script_skips_comment_lines() {
+ for (path, src, want) in [
+ (
+ "i.sh",
+ "#!/bin/sh\n# curl https://x.io/i.sh | bash\n # sh -c \"$(curl https://x.io/i.sh)\"\ncurl https://x.io/i.sh | sh\n",
+ 4,
+ ),
+ (
+ "i.ps1",
+ "# irm https://x.io/i.ps1 | iex\nirm https://x.io/i.ps1 | iex\n",
+ 2,
+ ),
+ (
+ "Dockerfile",
+ "# RUN curl https://x.io/i.sh | sh\nRUN curl https://x.io/i.sh | sh\n",
+ 2,
+ ),
+ (
+ "Makefile",
+ "# curl https://x.io/i.sh | sh\nall:\n\tcurl https://x.io/i.sh | sh\n",
+ 3,
+ ),
+ ] {
+ let lines: Vec<usize> = crate::rules::check(&FileInfo::new(path), src, true)
+ .into_iter()
+ .filter(|f| f.rule == "config.remote-script")
+ .map(|f| f.line)
+ .collect();
+ assert_eq!(lines, [want], "{path}");
+ }
+ }
}
diff --git a/tests/fixtures/config/Dockerfile b/tests/fixtures/config/Dockerfile
index 8ed46de..e5dcf2f 100644
--- a/tests/fixtures/config/Dockerfile
+++ b/tests/fixtures/config/Dockerfile
@@ -7,3 +7,4 @@ ADD https://get.acme.io/tool.tar.gz /opt/
RUN curl -fsSL https://get.acme.sh | sh
USER root
FROM build AS production
+# RUN curl -fsSL https://get.acme.sh | sh
diff --git a/tests/fixtures/config/install.ps1 b/tests/fixtures/config/install.ps1
index 3852c35..95fbf00 100644
--- a/tests/fixtures/config/install.ps1
+++ b/tests/fixtures/config/install.ps1
@@ -4,3 +4,4 @@ Invoke-WebRequest https://example.org/i.ps1 -OutFile i.ps1
irm https://example.com/install.ps1 | iex
Invoke-RestMethod -Uri https://example.com/install.ps1 | Invoke-Expression
CURL -UseBasicParsing https://example.org/i.ps1 | IEX
+# Usage: irm https://example.com/install.ps1 | iex
diff --git a/tests/fixtures/config/install.sh b/tests/fixtures/config/install.sh
index 6a50364..b01c269 100644
--- a/tests/fixtures/config/install.sh
+++ b/tests/fixtures/config/install.sh
@@ -34,3 +34,5 @@ curl -fsSL https://example.org/i.sh | sudo -Eu bash
curl -fsSL https://example.org/i.sh | sudo -ED"/tmp/build dir" sh
curl -fsSL https://example.org/i.sh | sudo -Euroot; bash
curl -fsSL https://example.org/i.sh | sudo -ED"/tmp/ bash" tee /tmp/list
+# Usage: curl -fsSL https://example.com/install.sh | bash
+ # sh -c "$(curl -fsSL https://example.com/install.sh)"