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): catch more config.remote-script forms (#230)

r00tkrnl954e2fd749c5
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5a5c50e..22d05f4 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,16 @@
## Unreleased
+- Config: `config.remote-script` now reports a download piped into a shell that is named by its
+ path or started through `env` (`| /bin/bash`, `| /usr/bin/env bash`, `| env sh`), including
+ `sudo /bin/bash`.
+- Config: `config.remote-script` now reports process substitution into a shell
+ (`bash <(curl ...)`, `source <(curl ...)`, `. <(wget ...)`), while `diff <(curl ...)`,
+ `cat <(curl ...)` and `bash <(cat ...)` stay quiet.
+- Config: `config.remote-script` now reports `iex (irm ...)`,
+ `Invoke-Expression (Invoke-RestMethod ...)` and
+ `iex ((New-Object System.Net.WebClient).DownloadString(...))`, while
+ `iex (Get-Content ...)` stays quiet.
- Code: `code.sql-injection` now reports Scala `s` and `f` interpolations in a query
(`s"SELECT id FROM users WHERE id = $id"`, `${id}`), in `.scala` and `.sc` files only. The
`sql"..."` interpolator (Slick, doobie), which binds its holes as parameters, and an escaped
diff --git a/src/rules/config.rs b/src/rules/config.rs
index 60e6273..4cc32b0 100644
--- a/src/rules/config.rs
+++ b/src/rules/config.rs
@@ -118,7 +118,7 @@ pub static RULES: &[Rule] = &[
"config.remote-script",
Medium,
shell_or_workflow,
- r#"\b(?i:curl|wget|iwr|irm|invoke-webrequest|invoke-restmethod)\b[^|\n]*?(?:https?://|\$\{?\w)[^|\n]*\|\s*(?:sudo\s+(?:(?:-[AbBEeHiKklnPSsVv]*[ugCDhprtTU]|--(?:user|group|chdir|host|prompt|role|type|other-user|close-from|command-timeout))\s+(?:"[^"\n]*"|'[^'\n]*'|[\w.$/~][\w.${}/~-]*)\s+|-[AbBEeHiKklnPSsVv]*[ugCDhprtTU](?:"[^"\n]*"|'[^'\n]*'|[^\s;|&`<>()"']+)\s+|-[AbBEeHiKklnPSsVv]+\s+|--[\w-]+=\S*\s+|--(?:preserve-env|login|shell|non-interactive|background|stdin|set-home|preserve-groups|askpass|bell|reset-timestamp|remove-timestamp)\s+)*(?:--\s+)?)?(?:sh|bash|zsh|python3?|(?i:iex|invoke-expression))\b|\b(?:ba|z|da|k)?sh\s+(?:[-+]o\s+[\w-]+\s+|-[A-Za-z]+\s+)*?-[A-Za-z]*c[A-Za-z]*\s+\\?["']?(?:\$\(|`)\s*(?:curl|wget)\b(?:[^()`\n]|\([^()`\n]*\))*?(?:https?://|\$\{?\w)"#,
+ r#"\b(?i:curl|wget|iwr|irm|invoke-webrequest|invoke-restmethod)\b[^|\n]*?(?:https?://|\$\{?\w)[^|\n]*\|\s*(?:sudo\s+(?:(?:-[AbBEeHiKklnPSsVv]*[ugCDhprtTU]|--(?:user|group|chdir|host|prompt|role|type|other-user|close-from|command-timeout))\s+(?:"[^"\n]*"|'[^'\n]*'|[\w.$/~][\w.${}/~-]*)\s+|-[AbBEeHiKklnPSsVv]*[ugCDhprtTU](?:"[^"\n]*"|'[^'\n]*'|[^\s;|&`<>()"']+)\s+|-[AbBEeHiKklnPSsVv]+\s+|--[\w-]+=\S*\s+|--(?:preserve-env|login|shell|non-interactive|background|stdin|set-home|preserve-groups|askpass|bell|reset-timestamp|remove-timestamp)\s+)*(?:--\s+)?)?(?:[\w.$~]*/)*(?:env\s+)?(?:sh|bash|zsh|python3?|(?i:iex|invoke-expression))\b|\b(?:ba|z|da|k)?sh\s+(?:[-+]o\s+[\w-]+\s+|-[A-Za-z]+\s+)*?-[A-Za-z]*c[A-Za-z]*\s+\\?["']?(?:\$\(|`)\s*(?:curl|wget)\b(?:[^()`\n]|\([^()`\n]*\))*?(?:https?://|\$\{?\w)|(?:(?m:^)|[ \t;&|])(?:\.|source|sh|bash|zsh)\s+<\(\s*(?:curl|wget|iwr|irm|invoke-webrequest|invoke-restmethod)\b[^)\n]*(?:https?://|\$\{?\w)|(?i:\b(?:iex|invoke-expression)\s*\(\s*\(*\s*(?:irm|iwr|invoke-restmethod|invoke-webrequest)\b[^)\n]*(?:https?://|\$\{?\w))|(?i:\b(?:iex|invoke-expression)\s*\(\s*\(*[^\n]{0,120}?downloadstring\s*\()"#,
None,
"A script is downloaded and piped straight into a shell, with no pinning or checksum.",
"Download to a file, verify a pinned checksum or signature, then run it; or use a package manager."
@@ -883,6 +883,54 @@ mod tests {
}
}
+ #[test]
+ fn remote_script_catches_paths_env_and_process_substitution() {
+ for hit in [
+ "curl -fsSL https://example.com/i.sh | /bin/bash",
+ "curl -fsSL https://example.com/i.sh | /usr/bin/env bash",
+ "curl -fsSL https://example.com/i.sh | env sh",
+ "curl -fsSL https://example.com/i.sh | sudo /bin/bash",
+ "bash <(curl -fsSL https://example.com/i.sh)",
+ "source <(curl -fsSL https://example.com/e.sh)",
+ ". <(wget -qO- https://example.com/e.sh)",
+ "iex (irm https://example.com/i.ps1)",
+ "Invoke-Expression (Invoke-RestMethod https://example.com/i.ps1)",
+ "iex ((New-Object System.Net.WebClient).DownloadString('https://example.com/i.ps1'))",
+ "zsh <(curl -fsSL https://example.com/i.sh)",
+ "bash <(curl -fsSL \"$URL\")",
+ "curl -fsSL https://example.com/i.sh | sudo -u root /bin/bash",
+ "IEX (IWR $env:URL)",
+ "iex (irm $url)",
+ "iex ((New-Object Net.WebClient).DownloadString($url))",
+ "iex ($client.DownloadString(\"https://example.com/i.ps1\"))",
+ ] {
+ assert!(REMOTE_SCRIPT.is_match(hit), "{hit}");
+ }
+ for quiet in [
+ "diff <(curl -s https://example.com/a) <(curl -s https://example.com/b)",
+ "cat <(curl -s https://example.com/a)",
+ "bash <(cat ./install.sh)",
+ "curl -fsSL https://example.com/a | /usr/bin/tee a.txt",
+ "curl -fsSL https://example.com/a | /bin/cat",
+ "curl -fsSL https://example.com/a | env > env.txt",
+ "iex (Get-Content ./setup.ps1 -Raw)",
+ "irm https://example.com/i.ps1 -OutFile i.ps1",
+ "./run.sh <(curl -s https://example.com/a)",
+ "diff a.sh <(curl -s https://example.com/a.sh)",
+ ] {
+ assert!(!REMOTE_SCRIPT.is_match(quiet), "{quiet}");
+ }
+ // A `#` comment line does not run, whatever the form.
+ assert!(!remote_script_in_code(
+ "# bash <(curl -fsSL https://example.com/i.sh)",
+ false
+ ));
+ assert!(!remote_script_in_code(
+ "# iex (irm https://example.com/i.ps1)",
+ true
+ ));
+ }
+
#[test]
fn remote_script_skips_comment_lines() {
for (path, src, want) in [
diff --git a/tests/fixtures/config/EXPECTED b/tests/fixtures/config/EXPECTED
index ebb73d9..d2b2264 100644
--- a/tests/fixtures/config/EXPECTED
+++ b/tests/fixtures/config/EXPECTED
@@ -65,3 +65,12 @@ nginx.conf:2 config.nginx-autoindex
nginx.conf:3 config.weak-tls-version
.github/workflows/ci.yml:34 config.gha-script-injection
.github/workflows/ci.yml:42 config.gha-script-injection
+install.sh:40 config.remote-script
+install.sh:41 config.remote-script
+install.sh:42 config.remote-script
+install.sh:43 config.remote-script
+install.sh:44 config.remote-script
+install.sh:45 config.remote-script
+install.ps1:8 config.remote-script
+install.ps1:9 config.remote-script
+install.ps1:10 config.remote-script
diff --git a/tests/fixtures/config/install.ps1 b/tests/fixtures/config/install.ps1
index 95fbf00..cb892c6 100644
--- a/tests/fixtures/config/install.ps1
+++ b/tests/fixtures/config/install.ps1
@@ -5,3 +5,9 @@ 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
+iex (irm https://example.com/install.ps1)
+Invoke-Expression (Invoke-RestMethod https://example.com/install.ps1)
+iex ((New-Object System.Net.WebClient).DownloadString('https://example.com/install.ps1'))
+iex (Get-Content ./setup.ps1 -Raw)
+irm https://example.com/install.ps1 -OutFile install.ps1
+# iex (irm https://example.com/install.ps1)
diff --git a/tests/fixtures/config/install.sh b/tests/fixtures/config/install.sh
index c804ee2..a1332ec 100644
--- a/tests/fixtures/config/install.sh
+++ b/tests/fixtures/config/install.sh
@@ -37,3 +37,16 @@ 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)"
curl -fsSL https://example.com/install.sh -o install.sh # or: curl -fsSL https://example.com/install.sh | sh
+curl -fsSL https://example.com/install.sh | /bin/bash
+curl -fsSL https://example.com/install.sh | /usr/bin/env bash
+curl -fsSL https://example.com/install.sh | env sh
+bash <(curl -fsSL https://example.com/install.sh)
+source <(curl -fsSL https://example.com/env.sh)
+. <(wget -qO- https://example.com/env.sh)
+diff <(curl -s https://example.com/a) <(curl -s https://example.com/b)
+cat <(curl -s https://example.com/a)
+bash <(cat ./install.sh)
+curl -fsSL https://example.com/a | /usr/bin/tee a.txt
+curl -fsSL https://example.com/a | /bin/cat
+curl -fsSL https://example.com/a | env > env.txt
+# bash <(curl -fsSL https://example.com/install.sh)