omi icon indicating copy to clipboard operation
omi copied to clipboard

structured-string sink checker: a registered sink wrapped in `bash -c` evades every rule

Open aryanorastar opened this issue 2 months ago • 2 comments

What

The structured-string sink checker added in #12408 does not see a registered sink invoked through a shell -c payload. A call that would be flagged in its plain form becomes invisible when wrapped.

Verified against dac6f7bc:

bash scripts/probe-llm-gateway-from-cloud-run.sh --project=test-project
   -> invocations found: 1          (flagged: joined --project=<value>)

bash -c 'scripts/probe-llm-gateway-from-cloud-run.sh --project=test-project'
   -> invocations found: 0          (no violation)

Why

_logical_shell_commands tokenizes each logical line with shlex.split, then _registered_invocations looks for a token whose basename equals the registered command. For the wrapped form the payload is a single token — scripts/probe-...sh --project=test-project — whose basename never equals probe-llm-gateway-from-cloud-run.sh, so no invocation is found and neither the split-argv nor the interpreter rule ever runs.

Why it matters more than an ordinary gap

The checker's own fail-closed rule (a registered scope that matches files but finds zero sink invocations fails) does not cover this. It only fires when the count across the whole scope is zero. As long as one legitimate invocation exists elsewhere, a wrapped one alongside it passes silently.

That makes the wrapper a way to make a real violation go green — which is the specific thing #10337 asked this registry to be resistant to, alongside the bare-path-allowlist and dynamic-values rules it does enforce.

Not urgent

No such call site exists today: the checker runs clean on the PR head and on current main (OK: 3 registered structured-string sinks are grammar-safe). This is a latent hole, not a live miss.

Shape of a fix

In _logical_shell_commands, when the tokens are a known shell (bash, sh, zsh) followed by -c, also yield shlex.split of the payload, with a small recursion cap so a nested wrapper cannot loop. Both existing rules then apply to the inner command unchanged, and the registry needs no new entry.

Following the registry's own convention, the fix should carry a paired fail fixture with the wrapped shape, so the suite proves the rule can fail rather than merely matching source text.

Provenance

Raised as a non-blocking hardening note by the reviewer on #12408, who judged it consistent with the checker's declared "not a general shell linter" scope. Filing it so it is tracked rather than remembered. Part of the #10337 line of work. The behavior above was reproduced directly, not inferred from reading.

aryanorastar avatar Sep 06 '26 11:09 aryanorastar

@josancamon19 @kodjima33 Following the contribution guide's invitation to propose bounties, would you accept USD $50 via PayPal for the fix described here?

I prepared a patch against #12408 at dac6f7bc6: https://gist.github.com/SunkenInTime/6891e9c4215314118e31acae97b58938

It inspects literal bash -c, sh -c, and zsh -c payloads, including nested wrappers, with a four-level cap that fails closed for registered scripts. Both existing script rules apply to the inner command. Paired YAML fixtures cover a wrapped violation beside a valid invocation.

Verification: the new regressions failed before the change; all 12 checker tests now pass, and the checker passes against all 3 existing registered sinks. Full repository preflight has not been run. The gist includes the patch, exact base, commands, and scope limits. Since #12408 is still open, this is a follow-up proposal against that PR, not a claim that the checker has landed on main.

If this scope and bounty are accepted, I can finish the repository checks and submit through your preferred branch/PR route. Payment after acceptance can go to https://paypal.me/sunkenintime. No payment is being claimed as owed without your agreement.

Disclosure: this work and message were prepared by an AI coding assistant acting with SunkenInTime's authorization.

SunkenInTime avatar Sep 06 '26 14:09 SunkenInTime

@josancamon19 I can submit a focused current-main fix for US$15, payable through the documented private PayPal process after acceptance and merge. My scope would recognize known shell -c payloads in _logical_shell_commands, retokenize them with an explicit small recursion limit, reuse the existing registered-sink rules, and add a paired failing fixture plus nested-wrapper and non-shell controls. Please confirm the scope is eligible and funded; I am not assuming assignment or payment.

haotvko avatar Sep 11 '26 11:09 haotvko