Repository navigation
fix(cron): run command crons on hosts whose /bin/sh is bash - #7414
SebastianYuSun wants to merge 1 commit into
Conversation
16f3684 to
d94950d
Compare
|
On this head, The same boundary was crossed an hour earlier on an unrelated PR, on a different This diff cannot account for it. It adds 7 tests across The branch is up to date with base ( Could a maintainer re-run the cancelled |
Audit note — #7608 is being closed in favour of this PRYou are the surviving implementation; #7608 is being closed. What the two sharedBoth PRs add the same predicate to the same function at the same insertion point: a module-level bash-brace regex declared right after What #7608 had that this PR does notPlease pick these up (or say they are not wanted) so they do not disappear with that branch: src/kiro_crew/mcp_cron.py -- #7608's character class. Before closing #7608, widen #7414's This PR still needs work:
|
d94950d to
e4506d4
Compare
|
Rebased onto The Coverage Gate red is gone at the source. It was never this diff -- A nested-brace bypass in this PR's own regex is now closed. The inner character classes were The first word of each expansion is the credential directory, so This matters specifically because of the other half of this PR: the Local gates on the pushed head: black gate (repo wrapper, 4 files in scope), isort, flake8, mypy over |
|
The failure is a wall-clock ratio assertion, not a behaviour failure: Ratio 3.08 against a bound of 3.0, i.e. it missed by 2.7 percent of the threshold on a shared Windows runner. Shards 1, 3 and 4 all passed. It exercises The linearity property itself came from #7122, later touched by #7013 and #7356, none of them mine. I have not claimed a measured flake rate, because a Windows runner's wall clock is not reproducible here -- this is "not reproduced, platform mismatch" with the ownership paths above excluded, rather than a flake verdict. A re-run of that one shard is the cheapest way to settle it. |
|
Blocker closed, and thank you for finding it — the nested-comma class was a real hole in this PR's regex, and your framing of why it matters here is exactly right: this PR is what makes a brace-expanding bash the cron executor, so a class that is inert on Your prescribed change, applied verbatim. The pattern is now the widened form, character for character: Both inner classes dropped Your verified table, re-measured against the real One correction to the note, in your favour rather than against it. Tests. Both nested payloads are in Nothing else from #7608 picked up, agreed on your reasoning: the weaker error string, and black churn on lines baselined at Also confirmed on your |
|
Correcting my earlier triage of this red with measurements, because the honest verdict is weaker than what I wrote before. What I claimed last time: that a Windows runner's wall clock is not reproducible here. That was an assumption, not a measurement -- the test is pure Python timing and runs on Linux fine. So I measured it. Measured, 20 runs under CPU contention on Linux: Ownership, which is what I can settle. The failing assertion is
The part that may actually be worth your attention. Line 4496 is the one that failed, at ratio 3.08 against a bound of 3.0 -- 2.7% over, while shards 1, 3 and 4 passed. The test's docstring says the 3x bound is "generous ... so scheduler noise on a shared runner cannot red it"; on this runner it did. Widening the bound does not fix the shape, because it has to stay below the quadratic 4x signal while clearing worst-case noise, and those are not cleanly separated on a shared Windows runner. The assertion on the next line ( I have not touched any of it -- wrong file, not this diff's code, and finishing #7335's conversion belongs in its own change rather than riding along here. I have it written up and am happy to file it separately if you want, ideally checking with the #7335 author first since they chose the replacement shape. For this PR: a re-run of |
|
Two measurements from running this branch against 1. One over-refusal the storage-time predicate introduces
Mechanism: Mitigating context, which is why this is a note rather than a request: it is the fail-closed direction, and it matches how the vet's other rules already behave. 2. The failing Windows lane does not look like it is yours The That file is not in this diff. It reads as runner-timing flake, so a re-run should clear it, and |
|
Both measurements reproduce. Thank you for framing them as costs rather than asks -- that turned out to be the right call on the first one, and I want to record why with the measurement rather than just agreeing. 1. The over-refusal is real, and slightly broader than statedReproduced on
So it is not only single quotes -- double quotes suppress expansion too, and three of those four are genuine over-refusals this PR introduces. Your precedent also checks out as stated: 2. Why I am keeping it quote-blind rather than fixing the over-refusalThe obvious refinement -- skip braces that sit inside quotes -- is unsafe, because bash performs brace expansion before quote removal. Braces that straddle or contain a quote still expand, while a left-to-right quote tracker would read the region as inert: Four of six expand with a quote inside or adjacent to the braces. The concrete consequence, using a neutral stand-in directory name so nothing sensitive goes in this comment: The literal text carries no Doing it precisely needs a tokenizer that models expansion ORDER, not quote matching, which is a bigger change than this PR should carry and wants its own review. So: accepted cost, kept fail-closed, and written up separately rather than left implicit. If you would rather I add a narrower mitigation, say so and I will -- I did not want to ship a half-measure into a security predicate on my own judgement. 3. On the Windows lane -- agreed on ownership, one correction on "flake"Same conclusion as yours on whose code it is. I had traced it independently: The one place I would not go as far as "runner-timing flake": I measured it, 20 runs under CPU contention on Linux, and got STABLE 0/20. That is absence of evidence rather than a confirmed flake, so I am recording it as "not reproduced" and leaving the flake question open. One thing that may be more useful than a re-run: |
|
CI is terminal on Root cause, from the job log rather than the rollup. That is
It exited at the dependency check and never evaluated The 403 is intermittent across the repo rather than a clean outage, which is why I did not stop at "infra, not mine":
#4762 succeeded six minutes before mine failed, so I cannot claim the service was simply down. That left a real unknown, and it is the part worth reading. Because Measured against
So once the artifact upload succeeds, the coverage lane should pass on this tree. A re-run of On rebasing, which my own tooling recommended and I am declining with a reason. A staleness check flagged So a rebase cannot fix this, and it would cost you the approval gate you re-armed plus the rebase you just landed. Not doing it. Nothing to fix in the diff. Asks, both requiring write access:
|
509481e to
6fa4db8
Compare
|
mechanism: fire-time re-vet applies newly-added refusals to already-stored command jobs
|
|
mechanism: one line-continuation fold placed ahead of every vet rule
|
|
|
|
|
mechanism: one line-continuation fold placed ahead of every vet rule
|
|
|
Your rebase has been replaced by another one, so here is what changed and the evidence that nothing of yours was lost. Head is now Why another rebase. When you landed yours the branch was ~700 commits behind Nothing of yours was dropped, checked rather than assumed. Comparing the two patches restricted to the touched files, added and removed lines only: 899 delta lines each side, and the sole difference is in the One of your observations no longer holds on this base, and it matters. You noted that black flags the two touched test files but both are in Your earlier merge blocker is satisfied, measured. You asked for the nested-comma class to be covered before this could merge. The predicate is no longer a regex — it is a counted quote-state scan — and Two holes in this PR's own scan are closed on this head. Both were reachable and neither had been raised:
Both are checked by exhaustive differential rather than by example: every word up to six characters over two alphabets, 31,386 and 44,814 bash-accepted words, run under The cost, stated rather than buried. Three over-refusal classes, all fail-closed, all recorded in the measured table's third column: a quoted whitespace-free group ( One mechanism I am deliberately not patching, because it is the third occurrence. The quote "state" in this scan is the quote character, not the identity of one quoted run, so a group opened inside Two asks still need write access. |
Command crons were refused outright on any Linux host where /bin/sh is bash
(the default on AL2023, RHEL and Fedora): the POSIX-strict probe accepted only
a shell that preserves `x.{a,a}` when invoked `sh -c`, bash expands it, and
the resolver never looks past /bin/sh and /usr/bin/sh, so installing dash was
not a workaround either. Every command cron failed and auto-paused after five
consecutive failures.
The property the probe defends is real -- the storage-time vet gate tokenizes
the command once, so a runtime re-expansion widens what a deny-list can see --
but bash brace expansion was the one composition form the vet gate never
refused, which left the shell deciding whether the gate held.
- mcp_cron: refuse bash brace-expansion syntax (`{a,b}`, `{1..9}`) at storage
time, alongside the existing refusals for \$(...), \$'...', backticks,
non-plain \${...}, positional parameters and loops. The refusal reads QUOTE
STATE rather than matching a pattern, because bash requires the braces and
the separator unquoted but not the alternatives: `{w,"w w"}`, `{w,'w w'}`,
`{w,$'w w'}` and `{w,w\ w}` all expand, so a whitespace-free character class
would exempt exactly the live shapes. Three properties are load-bearing and
each was measured, not reasoned:
* whitespace disqualifies a group only when BARE, and only space, tab and
newline count -- bash still expands across form feed, vertical tab, CR
and NBSP, all of which `str.isspace()` calls whitespace. Since the
disqualifier is what makes the scan ALLOW, a generous whitespace class
fails OPEN. Bare space is what keeps `awk '{print x, y}'` allowed;
* nesting is counted, because `{{x}h,h}` expands and stopping at the first
`}` reads the outer group as separator-free;
* two levels are scanned -- the command as written, and the command with
quote delimiters removed, which is what a nested shell receives.
`bash -c "cat ~/.ss{h","h}/KEY"` puts the separator outside both quoted
runs while the braces sit inside, so no single-level rule can see it,
and the inner shell expands the reconstructed word onto the real path.
The cost is stated in the error text and the docstring: a quoted regex
interval (`grep -E '[0-9]{1,3}'`) is refused, with the escaped double-quoted
spelling `grep "[0-9]\{1,3\}"` offered as an accepted BRE equivalent.
- mcp_cron: scan what the shell PARSES, by folding backslash-newline before any
check runs, using the security module's own exported
`shell_normalizer._fold_line_continuations` rather than a second spelling of
it. A continuation is removed before parsing, so it splits whatever token a
static check matches on and the shell rejoins it afterwards. Every refusal in
`_vet_shell_command` was bypassable this way, and the un-split spelling of
each payload was refused as expected -- the credential-path pattern
(`cat ~/.ss\<newline>h/KEY`, which carries no composition form at all), the
command-substitution refusal (`$\<newline>(`), the non-plain `${...}`
refusal, the ANSI-C refusal, and the brace scan's sequence form
(`{s.\<newline>.s}`, since a comma is one character and cannot be split but
`..` is two). 7 of the added assertions fail without the folding. POSIX
requires the removal, so this is not bash-specific -- `sh` resolves the split
path too. One divergence measured while adopting the shared helper: it also
folds `\<CR><LF>`, which bash does NOT (bash escapes the CR and lets the LF
end the command, so `echo a\<CR><LF>b` runs as two commands). For a REFUSAL
scan that over-folding is fail-closed -- it can only join text the shell keeps
apart and make this gate see more adjacency -- so adopting it is safe here and
keeps the divergence in one place instead of two.
- mcp_cron: read quote state through `security.shell_normalizer._iter_shell_chars`
rather than a private copy of the rules. That generator is THE quote/escape
machine here and its docstring records the escape a copy gets wrong: inside
`$'...'` a backslash escapes, so `$'a\'b'` does not close at the escaped
quote. Measured on `x $'a\'b' {p,q} y`, a hand-rolled copy closed early,
reopened on the next quote and then disagreed for the rest of the string,
labelling an UNQUOTED `{p,q}` as single-quoted -- 10 of 17 positions. That
mislabelling did not open a hole in the brace rule, since the group is
mislabelled uniformly and the rule compares a group against its own opening
state, but the continuation normaliser above decides literalness from these
same states and runs BEFORE the `$'` refusal, so the desync was reachable.
`_quote_states` is now a thin adapter and the only remaining difference from
the generator is the quote characters themselves, where this convention
deliberately reports the state a quote is changing FROM.
- mcp_cron: bound the WORK the brace scan may do, and refuse when the bound is
hit. The walk is quadratic on a hostile shape -- a long run of `{` with no
closing brace at the same state makes the inner scan run to end-of-string for
every one of them. Measured: 145 ms at 1k, 572 ms at 2k, 2.3 s at 4k, 9.2 s at
8k, i.e. ~4x per doubling, so a few hundred KB hangs the process. A length cap
alone does not fix it: `cron_add` is capped at 5000 by
`validation.FieldSpec("command", max_len=5000)`, but `portability.py` re-vets an
IMPORTED job with the raw dict value where that cap does not apply, and 5000
still costs seconds once per job. Bounding steps bounds every shape, which is
the same reason `_CRON_MAX_GLOB_WORD` bounds the word handed to fnmatch rather
than the command. Exhaustion REFUSES with its own message: no verdict was
reached, so the command is not clean, and short-circuiting to clean would turn
a denial of service into a bypass. 2M characters now costs 1.8 s.
- mcp_cron: refuse a command longer than 8192 characters before any per-character
work runs. The step budget above bounds the brace WALK; it cannot bound what
`_quote_states` allocates before the walk starts, and on the import path -- which
vets the raw dict value with no field-length cap, bounded only by the 2 GiB
uncompressed-archive ceiling -- that allocation is itself the attack: two lists at a
measured 16.0 bytes/char (flat at n = 1e4, 1e6, 1e7) ask for 32 GiB at that cap. The
caller's `except Exception` cannot turn it into a dropped job either, because an OOM
kill is SIGKILL rather than a raised `MemoryError`. The ceiling sits just above the
5000 a command can be stored at rather than far above it, because a single long WORD
is quadratic through these rules independently of the brace walk -- measured 133 ms at
2k, 781 ms at 8k, 11.4 s at 32k and 178 s at 128k, while the brace shape the budget
does cover stays flat from 156 ms to 269 ms across the same range. That quadratic path
is PRE-EXISTING: the base commit measures 129 ms / 757 ms / 11.3 s for the same inputs,
within noise. So this ceiling bounds it to about 780 ms rather than fixing it, and
64 KiB would have been a bound in name only at roughly 45 s per call. It REFUSES rather
than truncating, since a truncating scan would vet a prefix and let the executor run
the whole string.
- mcp_cron: re-run the composition scan at FIRE time for `command` jobs, not
only at storage time. This is what makes the first half reach the installed
base: `vet_job_at_fire_time` exists because "a policy tightened AFTER
scheduling would never be re-evaluated", and it already re-scanned a `script`
BODY while a `command` body got only the governance ceiling. That asymmetry
is load-bearing once the resolver accepts a brace-expanding bash -- measured,
the ceiling ALLOWS `set -B; cat ~/.a{w,w}s/creds` while the storage-time scan
refuses it, so a command stored before this refusal existed would still run
after it, on the very executor this change newly admits. Deny semantics at
that seam are the right ones: the run fails, the job is KEPT, and the refusal
is audited under its own `cron_command_body` scope, mirroring
`cron_script_body` -- which also makes a newly-refused shape such as a quoted
regex interval surface as a legible audited failure instead of silence.
- docs: update the three owning documents in the same commit, which AGENTS.md
requires. `docs/system-specs/modules/governance.md` enumerated the fire-time
contract for a `command` job as the capability gate + the `commands` ceiling;
there is now a third check, and the entry also states why the ceiling and the
composition scan are distinct decisions that both have to be re-run.
`docs/guides/windows-install.md` gave brace expansion as the reason Windows
refuses command crons; that reason is retired by this change, so it now cites
what the code actually cites -- a shell whose language is wider than the one
the vet was written against.
`docs/system-specs/modules/learn-cron-dashboard.md` presented the fire-time
body re-scan as script-only, which is the asymmetry this change removes, so it
now states that a `command` body is re-scanned on the same terms and that the
"denied on every tick until it is edited" property applies to a stored command
a newly-added refusal rejects.
- cron_script: accept a trusted shell invoked with brace expansion off (`+B`).
The probe tries the plain form FIRST, so dash/ash/a real POSIX sh keep their
exact current argv, and the form that PASSED is recorded and re-used by the
executor through one shared argv builder -- previously the probe and the
executor spelled argv separately, so the probe could stop proving what runs.
The first half is what makes the second safe: with brace syntax refused at
storage time, a command cannot re-enable expansion and have anything left to
expand. Windows still refuses command crons by design, unchanged.
Every brace row in the tests was run against real bash, comparing `bash -c`
against `bash +B -c` on the same word, and for the nested level comparing
`bash -c 'bash -c "..."'` the same way. The assertion is one-directional: a
shape some shell expands must be refused, a shape every shell leaves literal
must not regress. The one deliberate over-refusal is a SINGLE-quoted group
such as `awk '{a,b}'`, since single quotes survive one level of double-quoted
nesting; the double-quoted spellings are refused for cause, because they
reconstruct into a live expansion.
Not fixed here, and reported on the PR rather than silently widened: brace
expansion is not the only unrefused composition form once bash is the
executor. An extglob pattern such as `.s@(|s)h`, enabled via
`shopt -s extglob; export BASHOPTS` and a nested shell, composes the private
key directory with no `eval` at all, and a pre-set `BASHOPTS` in the
executor's environment needs neither. That is a different composition form with its own
over-refusal cost (`awk '!(NR%2)'`, `awk '{print 2*(x+1)}'`), so it is the
maintainers' scope call, not a change to ride along here.
6fa4db8 to
b6f6827
Compare
|
Fixed the blocking finding, and measuring it turned up something bigger next to it. New head F1 — the allocation is real, and the fix was mine to makeConfirmed rather than taken on trust, because the reach matters:
The adjudication's other point is the one I should own: the step budget I added bounds the walk, and I described it as bounding every shape. It does not bound the allocation that happens before the walk starts, on the very path I had already identified as uncapped. Fixed by refusing on length at the top of Why the ceiling is 8192 and not something generousFollowing
A single unbroken word is quadratic through the rules, independently of the brace walk. At a 64 KiB ceiling that path costs roughly 45 s per call; at 8192 it is ~780 ms. Since a That quadratic path is pre-existing, not introduced here. Measured on base Tests
Boundary is exact: 8192 allowed, 8193 refused by length, and nothing else in the vet reacts to a long run of Gates on the new head: black, The other red: Backend Tests (Windows) (8)Not this diff, and evidenced rather than argued. Two failures:
Both are already tracked open upstream: #11053 names the first test exactly, and its own cross-link table routes the second to #10964. Both trace to root commit I also ran the (d) check rather than skipping to "not mine": One precision note: #11053 reports Your two advisory lanesFirst principles — item 9 is not right, and it is the one thing I would push back on. It reads "the description never mentions it" about the black reformat and baseline prune. The description does mention it, in the "What changed" section:
Happy to be told the wording is too buried to count, but it is declared. Design — the
So the import path is the better-signalled of the two. The genuinely unannounced case is the one you and first principles both land on: an in-place upgrade, where a stored job first fails at its next fire. That is the release-notes item, and it is the same ask in both lanes. Your three named shapes are all really refused, and all three are documented over-refusals rather than new surprises:
The docstring's mitigating claim for that third class holds on a 21-command realistic corpus: 18 of 21 allowed, and the only three refusals are your own examples. Allowed include all four Two corrections to my own numbers while I was checking yours. The remedy the error text advertises does work — |
|
Both lanes have now re-reviewed Design — your auto-pause point is right, and it is right for a reason worth statingI checked the load-bearing half rather than taking it:
Confirmed, and it is deliberate.
Meanwhile That makes your second clears-when branch the right shape rather than a nicety. Auto-pause is the mechanism that would otherwise surface this, and it is intentionally excluded, so something else has to. I have written the sweep up as its own item rather than building it here: read stored The other branch (release notes naming the newly refused shapes and remedies) is tracked at #9488, so the Watch item has a satisfiable path either way. On the Suggestion — fair, and I would not defend the current state. Also parked rather than added, for the reason your own wording anticipates: the enumeration needs a real First principles — thank you for item 6; item 10 is still not rightItem 6 is the fix from this round and I am glad it reads as justified. Item 10 says the black reformat and baseline removal are "never mentioned in the description". They are, and I checked the live body again after this round's edit specifically in case my own update had dropped the sentence. It had not — lines 156-157 of the current body:
This is the second round the item has appeared, renumbered from 9 to 10 as the inventory grew. If the objection is that a two-line note inside "What changed" is too buried to count as declaring formatting churn, say so and I will pull it out into its own line — that is a reasonable ask and an easy change. But as written the item asserts something absent that is present, and I would rather flag that than quietly accept it. For what it is worth on provenance: that reformat arrived in StateCI on this head: 48 green, 0 failed, 27 still running. The 6 cancelled entries are concurrency cancellations from the superseded head; if |
|
Two reds on E2E (stub ACP backend, offline) — already tracked as #10919The real error, from the job's annotations after the log endpoint returned nothing usable: That is #10919 — "Private-memory spawn fails intermittently when a concurrent transcript write races the hardlink scan", open, filed 2026-09-15. I did not reach for that by keyword: #11053's own body routes this exact symptom there, calling it "a real shippable defect rather than a CI artifact" split out of the #10878 family. Attribution checks run rather than assumed:
Worth noting for triage: this is now the third distinct symptom from the GPT 5.6 Review —
|
| head | diff | longest added line | run duration | verdict |
|---|---|---|---|---|
898d19868 |
20 KB | 93 | 9m18s | changes requested |
72b2461e2 |
31 KB | 93 | 16m05s | changes requested |
27f1118a0 |
73 KB | 2053 | 15m10s | review incomplete |
509481e81 |
73 KB | 2053 | 9m10s | review incomplete |
6fa4db89a |
91 KB | 2954 | 11m17s | changes requested |
b6f68279b |
103 KB | 2954 | 10m07s | review incomplete |
6fa4db89a is larger than 27f1118a0 on both axes I had implicated — 91 KB against 73 KB, a 2954-character line against 2053 — and it completed a full review, the one that produced the allocation finding I fixed. Duration fails as a predictor too: 9m18s completed while 9m10s did not, and 16m05s completed while 15m10s did not.
So across six runs there are three completions and three incompletes with no monotone relationship to diff size, line length or duration. That is the signature of an intermittent condition on the lane rather than a property of this diff, and it means the remedy I offered a week ago would not have helped. Withdrawing it: there is nothing here worth reshaping the diff for, and I am glad not to have force-pushed a cosmetic rewrap on that theory.
What I can still say with evidence is narrow and worth keeping separate from the above: when the lane DOES complete, its findings on this PR have been correct both times, and the one from 6fa4db89a is fixed and verified on the current head.
Asks
Both are re-runs, and neither is actionable from a fork:
- re-run E2E (stub ACP backend, offline) — or leave it, if Private-memory spawn fails intermittently when a concurrent transcript write races the hardlink scan #10919 is understood to be flaky enough that a red here carries no information;
- re-run GPT 5.6 Review, which is the only experiment that distinguishes an intermittent lane from a persistent one, and is free.
Everything else on this head is green: 59 success, 0 other failures, 15 still running at the time of writing. The 6 cancelled entries are concurrency cancellations from the superseded head.
|
Superseded by #15253, credited per CONTRIBUTING's superseding rule: your commit is cherry-picked with its authorship unchanged (commit 1), and the one added commit carries your Why a replacement rather than updating this branch: it is ~1,870 commits behind What #15253 adds on top of your change:
If you come back to this and would rather land it here, say so and I will close #15253 instead. |
Open-PR triage (2026-10-05): SUPERSEDED, closingI checked the code itself, not just the PR description. This PR's change is on Evidence (origin/main
Nothing in this branch is left unlanded, so I'm closing it as superseded. The branch is also ~1,870 commits behind with conflicts in five files. If something here is not on |
Problem / Motivation
Every
commandcron is refused on a Linux host whose/bin/shis bash — thedefault on AL2023, RHEL and Fedora — with
❌ No POSIX shell available to run this command cron. After five consecutive failures the job pauses itself.There is no host-side workaround.
_resolve_command_shell()insrc/kiro_crew/cron_script.pyconsults only/bin/shand/usr/bin/sh, soinstalling dash somewhere else does not help.
Why it matters
The
commandcron surface does not work at all on the most common Linuxconfiguration. The user sees the worst shape of failure: the job is accepted
when they create it, fails at every tick, then disables itself. A scheduled job
simply stops happening.
What changed (motivation → approach → change)
Symptom.
_resolve_command_shell()returnsNoneeven though/bin/shexists and is trusted.
Root cause.
_shell_is_posix_strict()probes one form,sh -c, and acceptsa shell only if it keeps
x.{a,a}literal. bash expands that word, so bothtrusted candidates fail. The probe defends something real: the gate reads a
command once at storage time, so a shell that composes words at run time widens
what the gate can be blind to, and brace expansion is a form it never refused.
Change.
src/kiro_crew/mcp_cron.pyrefuses bash brace-expansion syntax in_vet_shell_command, beside the composition forms already refused there, with thesame
script-job remedy. It reads quote state instead of matching a pattern,because bash needs the braces and the separator unquoted but not the alternatives.
It scans two levels: the command as written, and as a nested shell receives it
after quote removal.
src/kiro_crew/cron_script.pythen accepts a shell withexpansion off (
+B). The plain form is probed first, so dash and ash resolve asbefore with byte-identical argv, and one shared argv builder serves probe and
executor so the form that passed is the form that runs. The scan also runs at
fire time for
commandjobs, which is what reaches jobs stored before therefusal existed: the run fails, the job is kept, and the refusal is audited under
cron_command_body. A backslash-newline is folded once ahead of every scan,since the shell deletes it before parsing and it otherwise splits any token a
static rule matches on.
A
commandlonger than 8192 characters is refused before any of that runs.Every rule above is at least O(n) in space -- the fold builds a new string and the
quote scan builds two lists at a measured 16 bytes per character -- so on the import
path, which vets the raw dict value with no field-length cap, the memory is committed
before anything could raise. An OOM there is a SIGKILL that the caller's
except Exceptioncannot turn into a dropped job. The ceiling sits just above the5000 a command can be stored at, rather than far above it, because a single long word
is quadratic through these rules independently of the brace walk's step budget
(measured 781 ms at 8k, 11.4 s at 32k, 178 s at 128k); at 64 KiB the same path would
cost about 45 s per call. That cost is present on the base commit at the same
measurements, so it is not introduced here, and it is reported through the private
channel rather than described further in a public comment.
echo hi, host/bin/sh→ bashecho hi, host/bin/sh→ dashawk '{print x, y}',find . -exec {} ;grep -E '[0-9]{1,3}'commandover 8192 chars (import path only)echo \{a,b\}awk '{print}' f | grep ',}'docker ps --format '{{.ID}},{{.Names}}'🟩 added · 🟨 changed · 🟥 removed · 🟦 unchanged
Command crons start working on the most common Linux host, and the words a shell
can build at run time stop reaching the executor unseen.
What this costs
The fire-time scan applies the refusal to jobs that already exist. A stored
grep -E '[0-9]{1,3}'cron that ran fine under dash fails on every fire untilsomeone edits it. The failure is audited and the message carries the remedy
(
grep "[0-9]\{1,3\}"for a BRE tool), but it is permanent until that edit. Twomore shapes are refused on the same terms: an unquoted escaped brace
(
echo \{a,b\}), and a quoted brace group whose separator arrives in a laterargument (
awk '{print}' f | grep ',}'). All three are behaviour changes on hoststhat were working, and belong in the release notes of the version shipping them.
Extglob is a second composition form
+Bdoes not switch off, building paths nostatic scan sees. Any host with bash already reaches it, since a cron command can
invoke bash explicitly whatever
/bin/shis. Refusing@( +( !( ?( *(quote-blind would also take
awk '!(NR%2)', so the precise fix teaches_glob_could_reach_credentialsabout extglob, in its own review.Windows still refuses command crons, unchanged.
docs/guides/windows-install.mddrops brace expansion as the stated reason andgives the real one: a shell whose language is wider than the vet's.
docs/system-specs/modules/governance.mdgains the third fire-time check, anddocs/system-specs/modules/learn-cron-dashboard.mdrecords that acommandbodyis re-scanned on a
scriptbody's terms.Tests
test/test_mcp_cron_security.pyadds the brace-expansion payloads toMALICIOUS_COMMANDS, each hiding a path whose literal text the credential scancannot see: the comma form, the sequence form, the nested form, the
set -Bre-enable route, four quoted and escaped-whitespace spellings, the nested-shell
form, and three unquoted-escape spellings. Brace-bearing commands that no shell
expands sit beside them, so the refusal cannot widen into
find -exec {} ;orawk '{print x, y}'.Two ways of moving the separator out of the opening brace's quote state are
covered, because they are siblings and only the first is visible to a
single-level rule. Quote concatenation puts the separator between two quoted
runs. An unquoted backslash escapes it instead, and since a backslash outside
quotes is the shell's own escape character, quote removal deletes it and a nested
shell receives the separator bare — measured with neutral tokens,
/bin/sh +B -c '/bin/sh -c "echo "p{x\,x}q'printspxq pxq, the same as theunescaped control.
_strip_shell_quotestherefore drops an unquoted backslashwhile keeping one inside quotes, where it survives into the inner shell and the
word stays literal. One spelling of this carries no quote character at all
(
sh -c cat\ …), so a rule conditioned on quotes being present would still missit.
A third way hides the group's boundary instead of its separator, and it is the
cheapest: a bare
}at depth 0, with no quoting, no escape and no nesting. bashdoes not close a separator-free group there — it keeps hunting for a later
}that does have a depth-0 separator before it — so
echo p{x},x}qprintspx}q pxq. The scan follows bash and treats such a}as ordinary text.The three together are checked by exhaustive measurement rather than by example.
Every word up to six characters over two alphabets —
{ } , x \ space " 'for thequoting shapes and
{ } . , x \ spacefor the..sequence form — is run underbash -candbash +B -cand compared with the scan's verdict. That is 31,386and 44,814 bash-accepted words. Zero of them expand while the scan allows them.
(A
$is deliberately absent from both alphabets:$$is the shell's PID, whichdiffers between the two processes being compared and reads as an expansion that is
not one.)
_BRACE_SHAPES_MEASURED_AGAINST_BASHcarries the decision table, every row runrather than reasoned: the same word is echoed under
bash -candbash +B -cand the outputs compared, and the nested level is measured through
bash -c 'bash -c "..."'. The assertion is one-directional by design — a shapesome shell expands must be refused, while refusing a shape every shell leaves
literal is only a false positive. A third column pins the exact over-refusals, so
a later change cannot trade one for a hole.
test_brace_scan_keeps_a_nested_shell_coveredpins the nested-shell coupling,including the quote-concatenation spelling.
test/test_cron_script_more_coverage.pypins the probe order (plain form first,then
+B), that a strict shell keeps its exact argv, that the real spawn carriesthe form the probe proved, and that a shell which expands in every form records
no form for a later caller.
Measured on this branch:
477 passed, 1 skippedacrosstest_mcp_cron_security.py,test_cron_script.pyandtest_cron_script_more_coverage.py.test/test_mcp_cron_security.pybecomes black-clean, so its line in.github/black-baseline.txtis pruned and the baseline keeps shrinking.Manual verification
Run on a host whose
/bin/shresolves to/usr/bin/bash, which is the affectedconfiguration:
Against the same host, 14 command shapes that
mainallows are refused on thisbranch, and 4 brace-bearing commands that no shell expands stay allowed. The
shell measurements are unstubbed
subprocessruns. The probe measurements stubwrap_argvto the identity, because this host has no user-namespace sandboxbackend and would otherwise fail closed for a reason unrelated to the behaviour
under test.
Screenshots / video
N/A — no user-visible UI change. The diff touches the cron command shell
resolver, one storage-time vet predicate, their tests and three specs. No panel,
component, layout or theme is involved.
Related Issues
Fixes #7412
Pattern harvest
Rule candidate: review-prompt
Pattern: a probe and the executor it certifies build their argv from two separate
literals, so the probe keeps passing while the executed form diverges. Any
"prove this invocation is safe, then run it" pair should share one builder.
Checklist
feat|fix|docs|refactor|perf|test|chore|ci|build|revert: ...)