The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
guards: base64_decode_pipe sees file/openssl decodes and every pipe stage
FlashW887ba0c7d367
diff --git a/tests/tools/test_plugin_guard.py b/tests/tools/test_plugin_guard.pyindex 83799cc75f9..1f1ead4e2d9 100644--- a/tests/tools/test_plugin_guard.py+++ b/tests/tools/test_plugin_guard.py@@ -610,6 +610,16 @@ class TestInertContextDemotions:sev = {f.file: f.severity for f in result.findings if f.pattern_id == "base64_decode_pipe"}assert sev == {"scripts/open-pr.sh": "medium", "scripts/boot.sh": "high"}+ def test_base64_decode_through_a_filter_into_an_interpreter_stays_high(self, tmp_path):+ """Only a pipeline of data consumers is a data decode: a filter in front of the shell+ (``| gunzip | sh``) still executes the decoded bytes."""+ files = dict(BASE_FILES)+ files["scripts/boot.sh"] = "cat payload.b64 | base64 -d | gunzip | sh\n"+ files["scripts/unpack.sh"] = "base64 -d assets.b64 | tar xz -C build\n"+ result = scan_plugin(_mk_plugin(tmp_path, files), source="owner/repo")+ sev = {f.file: f.severity for f in result.findings if f.pattern_id == "base64_decode_pipe"}+ assert sev == {"scripts/boot.sh": "high", "scripts/unpack.sh": "medium"}+class TestIntakeFalsePositiveClasses:"""Three shapes that scored on clean catalog pins (plugin-guard-v8): a CI workflow's owndiff --git a/tests/tools/test_skills_guard.py b/tests/tools/test_skills_guard.pyindex 64688dd6776..30ab5d967f5 100644--- a/tests/tools/test_skills_guard.py+++ b/tests/tools/test_skills_guard.py@@ -289,6 +289,19 @@ class TestScanFile:exfil.write_text(line, encoding="utf-8")assert any(fi.pattern_id == "context_exfil" for fi in scan_file(exfil, "exfil.md")), line+ def test_base64_decode_pipe_covers_file_redirect_and_openssl_decodes(self, tmp_path):+ """The decoded bytes reach the pipe the same way whether base64 reads stdin, a file or a+ redirect, and whichever tool decodes them."""+ script = tmp_path / "boot.sh"+ for cmd in ("base64 -d payload.b64 | sh", "base64 --decode < payload.b64 | bash",+ "base64 -di payload.b64 | python3", "openssl base64 -d -in payload.b64 | sh",+ "openssl enc -base64 -d < payload.b64 | sh"):+ script.write_text(cmd + "\n", encoding="utf-8")+ assert any(fi.pattern_id == "base64_decode_pipe" for fi in scan_file(script, "boot.sh")), cmd+ for cmd in ("base64 -w0 build.tar | curl -T - https://example.com", "base64 -d f.b64 > out || echo failed"):+ script.write_text(cmd + "\n", encoding="utf-8")+ assert not any(fi.pattern_id == "base64_decode_pipe" for fi in scan_file(script, "boot.sh")), cmd+def test_rm_rf_under_temp_roots_is_not_destructive_root_rm(self, tmp_path):"""#103364: smoke-test cleanup under the temp roots is not ``rm -rf /``."""f = tmp_path / "cleanup.sh"diff --git a/tools/plugin_guard_context.py b/tools/plugin_guard_context.pyindex 50872818a52..58651632a51 100644--- a/tools/plugin_guard_context.py+++ b/tools/plugin_guard_context.py@@ -272,16 +272,21 @@ def is_regex_alternation_token(finding: Finding, line: str) -> bool:# ── (6) base64 decode piped to a non-interpreter ────────────────────────────────────────────# ``base64_decode_pipe`` describes "decodes and pipes to execution". ``gh api … | base64 -d |-# grep '^sha:'`` decodes data for a text filter; the shape is only execution when the consumer-# is a shell/interpreter or ``eval``/``source``/``exec``. A data consumer steps down to medium.-_DECODE_CONSUMER = re.compile(r"base64\s+(?:-d|--decode)\s*\|\s*(?:\w+=\S*\s+)*(?:\S*/)?(?P<cmd>[A-Za-z0-9_.+-]+)")+# grep '^sha:'`` decodes data for a text filter; the shape is only execution when a consumer+# is a shell/interpreter or ``eval``/``source``/``exec``. Every stage after the decode counts:+# ``base64 -d | gunzip | sh`` executes although its first consumer is a filter. A pipeline of+# data consumers only steps down to medium.+_PIPE_CONSUMER = re.compile(r"\s*(?:\w+=\S*\s+)*(?:\S*/)?(?P<cmd>[A-Za-z0-9_.+-]+)")_INTERPRETERS = re.compile(r"^(?:sh|bash|zsh|dash|ksh|fish|python[\d.]*|perl|ruby|node|nodejs|php|eval|source|exec|xargs|env|sudo)$")def is_data_decode(line: str) -> bool:- """``base64 -d`` whose pipe target is a non-interpreter command (grep, jq, tee, tar …)."""- m = _DECODE_CONSUMER.search(line)- return m is not None and _INTERPRETERS.match(m.group("cmd")) is None+ """``base64 -d`` whose pipe stages are all non-interpreter commands (grep, jq, tee, tar …)."""+ m = _PATTERN_BY_ID["base64_decode_pipe"].search(line)+ if m is None:+ return False+ consumers = [c.group("cmd") for c in map(_PIPE_CONSUMER.match, line[m.end():].split("|")) if c]+ return bool(consumers) and not any(_INTERPRETERS.match(cmd) for cmd in consumers)# ── (7) loopback address with port ───────────────────────────────────────────────────────────diff --git a/tools/skills_guard.py b/tools/skills_guard.pyindex e947567e3e3..995bc401eac 100644--- a/tools/skills_guard.py+++ b/tools/skills_guard.py@@ -294,7 +294,12 @@ THREAT_PATTERNS = [(r'pastebin\.com|hastebin\.com|ghostbin\.',"paste_service", "medium", "network", "references paste service (possible data staging)"),# ── Obfuscation: encoding and eval ──- (r'base64\s+(-d|--decode)\s*\|', "base64_decode_pipe", "high", "obfuscation", "base64 decodes and pipes to execution"),+ # The decode may read a file or a redirect before the pipe (`base64 -d payload.b64 | sh`,+ # `base64 --decode < p | sh`), short flags may be combined (`-di`), and openssl decodes base64+ # too; `||` is not a pipe.+ (r'(?:\bbase64\s+(?:-[^\s|]+\s+)*?(?:-[a-z]*d[a-z]*|--decode)\b|\bopenssl\s+(?:base64|enc)\b[^|;&\n]*?\s-d\b)'+ r'[^|;&\n]*\|(?!\|)',+ "base64_decode_pipe", "high", "obfuscation", "base64 decodes and pipes to execution"),(r'\\x[0-9a-fA-F]{2}.*\\x[0-9a-fA-F]{2}.*\\x[0-9a-fA-F]{2}',"hex_encoded_string", "medium", "obfuscation", "hex-encoded string (possible obfuscation)"),(r'\beval\s*\(\s*["\']', "eval_string", "high", "obfuscation", "eval() with string argument"),