Skip to content

perf(security): walk each shell payload once per deny decision - #14993

Closed
yiyabo wants to merge 2 commits into
kirodotdev:mainfrom
yiyabo:perf/deny-walk-once
Closed

yiyabo wants to merge 2 commits into
kirodotdev:mainfrom
yiyabo:perf/deny-walk-once

Conversation

@yiyabo

@yiyabo yiyabo commented Sep 29, 2026

Copy link
Copy Markdown

Problem / Motivation

Goal: One deny decision tokenizes each shell command once instead of once per floor, so a long command blocks the gateway's event loop for a fraction of the time.

Every shell tool call goes through is_denied on the event loop before it runs. Several structural floors each ask _shell_payload_walk to tokenize the same command, and on a long command that tokenizing is almost all of the decision's cost. #13980 reports an 8 KB command stalling the loop for seconds and a 32 KB one outlasting the 25 s hang watchdog, which kills the gateway.

Why it matters

The deny check is synchronous and sits in front of every shell call, so while it runs no other session, channel or dashboard request is served. An agent that writes a long heredoc script freezes the whole gateway, and past the watchdog budget the gateway dies mid-work. With one walk per decision the 30,946-character case below drops from ~51 s to ~6.3 s: under the watchdog, though still a multi-second stall (see Not a goal).

Not a goal

  • Moving the deny check off the event loop. That changes the guarantee that a verdict exists before a tool runs, which is a maintainer decision.
  • Making a single walk linear. One walk is still super-linear in command length (_self_tokens over _iter_shell_chars); rewriting the bash-fidelity scanner needs its own differential review.
  • Any verdict change. No rule, floor or pattern is added, removed or edited.

What changed (motivation → approach → change)

One deny decision tokenizes each command text once and shares the result with every floor that asks for it, so a long command pays for one walk instead of one per floor.

File Piece What it does
security/shell_normalizer.py _payload_walk_memo() Opens a memo for one block, held in a ContextVar and keyed by the exact text walked. It is dropped on exit, and a nested block reuses the outer one.
security/shell_normalizer.py _shell_payload_walk() Answers from the memo inside a block and walks otherwise. It always hands out fresh lists, and a walk that raises is not remembered. The walk itself is unchanged, as _shell_payload_walk_uncached.
security/__init__.py _one_payload_walk_per_decision A decorator that runs is_denied inside one memo block.

The walk is a pure function of its text, and the floors of one decision ask for it on the same text. So the decision can share one result without any floor seeing a different view. The self-subcommand floors walk the command with line continuations joined, which is a different text and gets its own entry.

The memo lives exactly as long as one is_denied call. The gate keeps no state between tool calls, so there is nothing to invalidate. A decorator leaves the body of is_denied and every floor's signature untouched.

security.md records the mechanism and the remaining single-walk cost. The package line budget in test_security_gate_liveness.py is re-pinned to the new measured total, with its reason.

Backwards compatibility

Compatible: verdicts are identical, because the walk is a pure function of its text and the memo is keyed by that exact text for one call; no signature, rule, config or output changes.

Tests

test/test_denied_commands_security.py::TestOneDecisionSharesEachPayloadWalk:

  • test_one_decision_walks_each_text_once: on a long heredoc, every text the floors request is walked exactly once, with a precondition that several floors requested it.
  • test_each_distinct_text_keeps_its_own_walk: a continuation-joined view is walked separately, and each text gets its own frames.
  • test_a_later_decision_walks_again: nothing carries between two decisions.
  • test_a_shared_walk_hands_out_fresh_lists, test_a_walk_that_raises_is_not_remembered, test_a_nested_block_reuses_the_enclosing_memo: the memo's isolation and lifetime.
  • test_verdicts_match_an_unshared_walk_on_the_floor_corpus and test_verdicts_match_an_unshared_walk_on_composed_commands (Hypothesis): shared and unshared decisions return the same verdict, over one command per structural floor and over generated compositions of them.

The pin counts walks instead of timing a budget, because a wall-clock complexity guard measures the scheduler and flips under load (testing-conventions).

test/test_security_gate_liveness.py: _PACKAGE_LINE_BUDGET re-pinned to the measured package total.

Manual verification

The reproducer from #13980, unchanged, on macOS arm64 with Python 3.12. Each cell is the median of 5 timed is_denied calls after a warm-up, with an empty data home:

Command length main 3b0f4ad04 this PR walks per decision
1,946 chars 259.7 ms 62.3 ms 9 → 1
7,746 chars 3,363 ms 503.4 ms 9 → 1
30,946 chars 51.07 s 6.35 s not counted

Walks are counted with cProfile on an untimed call; profiling the longest command is too slow to be worth it, and the count depends on the floors, not the length. All six verdicts are None on both sides.

Related Issues

Refs #13980 (the walk-once slice: one walk is still super-linear in command length, so the issue stays open).

Pattern harvest

Rule candidate: review-prompt
Pattern: several predicates of one decision each recompute the same pure parse of the same input; share it for that decision only, never across calls.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

Copilot AI balanced review requested due to automatic review settings September 29, 2026 08:52
@yiyabo
yiyabo requested a review from a team as a code owner September 29, 2026 08:52
@yiyabo
yiyabo requested a review from cruisercohen September 29, 2026 08:52

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions github-actions Bot added fork Pull request from a fork (external contributor) readiness: action required A blocking check or review needs attention labels Sep 29, 2026
@yiyabo

yiyabo commented Sep 29, 2026

Copy link
Copy Markdown
Author

Raw measurements behind the Manual verification table.

The command is the reproducer from #13980, verbatim. Each line is one checkout: main 3b0f4ad04, then this branch. Timings are the median / min / max of 5 timed is_denied calls after a warm-up, with an empty data home, on macOS arm64 with Python 3.12. requests counts calls to _shell_payload_walk and walks counts full tokenizing walks (on main every request walks). Both were counted with cProfile on one untimed call, for the two shorter commands only.

main git-status mean_us=127.1
main len=1946 verdict=None requests=9 walks=9 median_ms=259.7 min_ms=255.8 max_ms=260.0 runs=5
main len=7746 verdict=None requests=9 walks=9 median_ms=3363.0 min_ms=3354.7 max_ms=3373.8 runs=5
main len=30946 verdict=None requests=n/a walks=n/a median_ms=51069.3 min_ms=50498.6 max_ms=52400.4 runs=5
branch git-status mean_us=138.4
branch len=1946 verdict=None requests=9 walks=1 median_ms=62.3 min_ms=61.6 max_ms=64.6 runs=5
branch len=7746 verdict=None requests=9 walks=1 median_ms=503.4 min_ms=501.4 max_ms=508.2 runs=5
branch len=30946 verdict=None requests=n/a walks=n/a median_ms=6345.5 min_ms=6309.6 max_ms=6440.9 runs=5

The two git-status lines are the mean over 2,000 calls of a command that reaches no walk. They come from two separate processes on two trees, so their difference is not claimed as the memo's overhead.

Denial differential on the base-ref golden-paths corpus (scripts/deny_diff.py --base origin/main --head HEAD, posix): 55 rows, 41 classified, no regressions, and all 41 are allowed at both refs.

@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Sep 29, 2026
@github-actions

github-actions Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5, fork) — ✅ PASS

Design-level review of 848209d81dedaef57b07cc3febe51e54cd03b3f9 via the fork AI-review pipeline — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

Nothing blocks: the walk is a pure function of its text, the memo lasts one decision, and verdict equality is pinned against an unshared walk.

Notes

  • This adds a second per-call memo next to the existing shell_commands.sharing_views / _CALL_VIEWS, so is_denied now has two stacked decorators and two ContextVar lifetimes doing one job. Putting the walk memo inside sharing_views's scope would leave one owner for "what one decision may cache".
  • The description and security.md both say TestOneDecisionSharesEachPayloadWalk is in test_denied_commands_security.py. The patch puts it in test_denied_commands_security_walk_memo.py, so the spec's "Pinned by" pointer is wrong.

[DESIGN-REVIEWED] 848209d

Description read

[DESCRIPTION-READ] 1d3e354cfa62ec4e83666bb0159f1b09e9fb27a9723e6ad8e4531d9dd64d3644

That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review (fork) — ✅ no blocking findings

Reviewed f2e798d4946f73abeb64161ddd63cb955dfa2390 via the fork AI-review pipeline; updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] f2e798d

@github-actions

github-actions Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5, fork) — 🔴 BLOCK

Premise-level review of 848209d81dedaef57b07cc3febe51e54cd03b3f9 via the fork AI-review pipeline — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

First-Principles-Verdict: BLOCK

The walk memo adds a second per-call ContextVar scope around is_denied. is_denied already runs inside shell_commands.sharing_views, which opens a per-call cache (_CALL_VIEWS) for exactly this kind of sharing.

What this change ships

Inventory (6 items) — 4 justified

Intent: stop one long shell command from blocking the gateway's event loop past the watchdog by tokenizing it once per deny decision. This is a FIX (perf; #13980).

  1. One deny decision now tokenizes each distinct command text once instead of once per floor — justified
  2. New _PAYLOAD_WALK_MEMO ContextVar and _payload_walk_memo() scope in shell_normalizer — duplicate of shell_commands._CALL_VIEWS
  3. New _one_payload_walk_per_decision decorator stacked on is_denied — duplicate of shell_commands.sharing_views
  4. Package line budget raised from 33,723 to 33,753 — justified
  5. Spec entry in security.md for the memo and its remaining cost — justified
  6. New test module checking walk counts and that verdicts match an unshared walk — justified

Blockers

Second per-decision cache scope around is_denied — duplicate of src/kiro_crew/security/shell_commands.py:263-275
Trigger: I grepped sharing_views|_CALL_VIEWS and found 1 existing per-call scope, already applied to is_denied at deny_gate.py:422. The diff adds @_one_payload_walk_per_decision directly above it, plus a new ContextVar("shell_payload_walk_memo"). Two stacked decorators now open two ContextVars that live exactly as long as the same call. shell_normalizer already imports shell_commands lazily (shell_normalizer.py:1632), so the existing scope is reachable from the walk.
Outcome: two scope mechanisms with the same lifetime have to be kept in step. One resets on a nested call and the other reuses the outer memo, so the two will drift apart.
Subtraction: delete _one_payload_walk_per_decision and _payload_walk_memo. Keep the walk's frames inside the scope sharing_views already opens, under keys that cannot collide with the redirect-payload keys.
Clears when: is_denied carries one per-call cache scope and the walk memo lives inside it.

[FIRST-PRINCIPLES-REVIEWED] 848209d

Description read

[DESCRIPTION-READ] 096a6085782566a480e041902a859886976d8ae6b74c1b89c1e5d8453886e864

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions

github-actions Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Security Scope Review (fork) — ✅ PASS

Which legitimate operations does 848209d81dedaef57b07cc3febe51e54cd03b3f9 newly refuse? Model proposes, scripts/deny_diff.py decides — updated in place on each push. A script-confirmed regression blocks PR readiness.

adjudicated, zero confirmed regressions

Scope-Verdict: PASS

Reason: This change does not make any rule stricter. It adds a per-decision memo around _shell_payload_walk, keyed by the exact text walked, so each distinct text is walked once per is_denied call. The walk depends only on its text, the memo hands out fresh lists, it does not keep a walk that raised, and it is dropped when the decision ends, so no floor should see a different view than before. The 16 candidates (no confirmed regressions in hand) probe every floor that is fed by the shared walk.

TIGHTENING: No deny boundary got stricter. The only mechanism change is caching the walk the floors already share -- "memo[text_lower] = tuple((source, tuple(tokens)) for source, tokens in walked)" inside _shell_payload_walk, opened around is_denied by @_one_payload_walk_per_decision. It refuses no new threat. The risk it brings is a wrong verdict, either a new refusal or a new allow, if a memo key were ever answered with another text's frames.

ADJUDICATED: 16 candidates, 0 confirmed newly-refused

PLATFORM COVERAGE: posix rows: two heredoc-fed python3 - scripts, the shape the memo was built for, where the self-floor gate opens and every floor asks for the walk. any rows: wrapped and unwrapped scoped pushes (git-publish floor), kirocrew status/cron list in plain form, under bash -c, in a substitution and joined by a line continuation (self-subcommand floors, including the second memo key the joined text creates), pgrep/ps/kill $(pgrep ...) against non-product targets (kill floor), the mint verb as a quoted rg argument (mint floor), and eval-joined frames. windows rows: cmd /c and powershell -Command wrappers and a .venv\Scripts\python.exe test run, because the walk tokenizes nested interpreter payloads and the diff adds no Windows-specific spelling of its own. The diff makes no new assumption about paths, separators or environment variables, so no platform is left unprobed.

[SCOPE-REVIEWED] 848209d

Security scope review -- adjudicated candidates

  • macos-latest (platform posix): 13 classified, 0 newly refused, 13 still allowed.
  • ubuntu-latest (platform posix): 13 classified, 0 newly refused, 13 still allowed.
  • windows-latest (platform windows): 14 classified, 0 newly refused, 14 still allowed.

No candidate flipped from allowed to refused.

@github-actions

github-actions Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review (fork) — ✅ no blocking findings

Reviewed f2e798d4946f73abeb64161ddd63cb955dfa2390 via the fork AI-review pipeline; updated in place on each push.

Review details

No findings.

Notes:

  • docs/system-specs/modules/security.md:1956 says TestOneDecisionSharesEachPayloadWalk is in test_denied_commands_security.py, but the diff adds it in test_denied_commands_security_walk_memo.py.

[OPUS-REVIEWED] f2e798d

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Sep 29, 2026
@yiyabo

yiyabo commented Sep 29, 2026

Copy link
Copy Markdown
Author

Backend Tests (Windows) (1) is the cross-PR red tracked in #15006, not this diff: the two symlink tests #13568 added to test/test_apps_registry_coverage.py fail with the same node ids and the same 2 failed, 16066 passed on unrelated heads, e.g. #14990 (autonudge only). This PR touches neither src/kiro_crew/apps/ nor that test file. I'll rebase once #14986 lands.

On the Design Review's cost note: under CI's Hypothesis profile (20 examples), the composed-command differential runs in 0.10 s locally and the corpus differential in 0.02 s.

@github-actions github-actions Bot added the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Sep 29, 2026
@yiyabo
yiyabo force-pushed the perf/deny-walk-once branch from dcdc367 to ccce02d Compare September 29, 2026 16:55
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention merge conflict Branch has merge conflicts with its base — author must resolve before merge and removed merge conflict Branch has merge conflicts with its base — author must resolve before merge readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 29, 2026
@dwu96 dwu96 added needs-pr-triage PR scanner: awaiting automated triage needs-human-security-review Security scan flagged — needs manual review and removed needs-pr-triage PR scanner: awaiting automated triage labels Oct 3, 2026
@dwu96

dwu96 commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

🤖 Kiro Crew [operator: dwu96#8c08bee0]: Security scan flagged this PR for manual review.

Findings:

  • code layer, rule rm\s+-(?=[a-z]*r)(?=[a-z]*f)[a-z]+\s+(/|~|$HOME|..|/tmp/kc) — test/test_denied_commands_security.py:4930, added line: "rm -rf /",
  • code layer, same rule — test/test_denied_commands_security.py:4931, added line: 'bash -c "rm -rf /"',

A maintainer will review before any automated action is taken.

Context for the reviewer: both hits are in an added block of test/test_denied_commands_security.py, i.e. they look like deny-list fixtures asserting that these payloads stay blocked, not executable operations. The scan is content-based by design and triage does not override it, so this PR is parked for a human rather than classified. If you confirm the fixtures are intended, remove needs-human-security-review and re-add needs-pr-triage and the next cycle will classify it normally.

Copy link
Copy Markdown
Contributor

PR triage (2026-10-05): REBASE + merge-discussion (OVERLAPPING, no blocker)

Checked against origin/main cc7e79894e. I read the full diff from merge base 046e5c9815.

  • Not superseded. main still has no per-decision memo. _shell_payload_walk (shell_normalizer.py:3494) walks on every call, and security: is_denied is quadratic in command length and runs on the event loop — 8 KB heredoc = 4 s stall, 32 KB kills the gateway #13980 (an issue, still open) is unaddressed on main. No other open PR targets it.

  • Stale. mergeable_state=dirty. A merge with main conflicts in test/test_denied_commands_security.py and test/test_security_gate_liveness.py. The source files (security/__init__.py, shell_normalizer.py) still apply cleanly. test(apps): make the symlink-loop and deep-link tests platform-aware #14986 (a PR) merged on 2026-09-29, so the Windows red you were waiting on is cleared. On main, _PACKAGE_LINE_BUDGET is now 28_438. With this diff applied I measured the package at 28,508, so it needs re-pinning after the rebase.

  • Verified locally. I applied this PR's security/ changes to current main and ran test_denied_commands_security.py and test_security.py. Everything passed except the expected line-budget pin, plus one wall-clock linearity test that flaked under xdist load. That test also passes alone on both main and this branch. TestOneDecisionSharesEachPayloadWalk passes at the PR head.

  • Overlaps with open PRs (complementary, not duplicates):

    Both stay pure per text, so the memo stays sound. Whichever lands second will hit a textual conflict, because this PR renames that body to _shell_payload_walk_uncached. Please coordinate landing order with those authors.

  • No breaking change and no P0 found. Verdicts are unchanged by construction, and the security-scope review's deny_diff confirmed 0 regressions.

Recommendation: rebase onto main, re-pin the line budget, then proceed.

@yiyabo
yiyabo force-pushed the perf/deny-walk-once branch from f2bcdd1 to e91be95 Compare October 15, 2026 17:58
@github-actions github-actions Bot added readiness: checking Automated validation is still running merge conflict Branch has merge conflicts with its base — author must resolve before merge readiness: passed Eligible automated validation passed for the current revision and removed merge conflict Branch has merge conflicts with its base — author must resolve before merge readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Oct 15, 2026
Every structural floor of is_denied asks _shell_payload_walk to
tokenize the same command text, so one decision on a long heredoc-fed
script repeated the same super-linear walk once per floor, and that
repetition was nearly all of the decision's cost on the event loop.

Run is_denied inside a call-scoped memo keyed by the exact text
walked. The walk is a pure function of its text, so the floors of one
decision share one result without any floor seeing a different view;
the memo is dropped when the call returns, so the gate keeps no state
between tool calls. Each caller still receives fresh lists, and a walk
that raises is not remembered.

Re-pin the security package line budget to the new measured total.

Refs kirodotdev#13980
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running and removed readiness: passed Eligible automated validation passed for the current revision merge conflict Branch has merge conflicts with its base — author must resolve before merge readiness: action required A blocking check or review needs attention labels Nov 2, 2026
First Principles review found two per-call ContextVar scopes stacked on
is_denied. Drop _one_payload_walk_per_decision and the walk's own
ContextVar; _shell_payload_walk now keeps its frames in the cache
sharing_views already opens, under (tag, text) tuple keys that cannot
collide with the redirect-view str keys. The test helper restores the
scope by value (Semgrep contextvar-token-reset).

Refs kirodotdev#13980
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention merge conflict Branch has merge conflicts with its base — author must resolve before merge and removed readiness: checking Automated validation is still running labels Nov 2, 2026
@bolichen97

Copy link
Copy Markdown
Contributor

[operator: bolichen97] Continuing this in #32115; thanks for the start.

bolichen97 added a commit that referenced this pull request Nov 7, 2026
One is_denied call asked for the same shell payload walk once per
floor, about ten times on a heredoc-fed script, and each walk read
every $( span twice to find its close. The walk now keeps its frames in
the per-call cache sharing_views already opens, so each distinct text
is walked once per decision, and the paren walk skips its second
${...}-aware pass when the span holds no "{", where both passes take
the same steps. Verdicts are unchanged; on the issue's reproducer an
8 KB heredoc goes from about 15 s to 1.7 s.

Builds on #14993 by @yiyabo.

Part of #13980
bolichen97 added a commit that referenced this pull request Nov 7, 2026
One is_denied call asked for the same shell payload walk once per
floor, about ten times on a heredoc-fed script, and each walk read
every $( span twice to find its close. The walk now keeps its frames in
the per-call cache sharing_views already opens, so each distinct text
is walked once per decision, and the paren walk skips its second
${...}-aware pass when the span holds no "{", where both passes take
the same steps. Verdicts are unchanged; on the issue's reproducer an
8 KB heredoc goes from about 15 s to 1.7 s.

Builds on #14993 by @yiyabo.

Part of #13980
bolichen97 added a commit that referenced this pull request Nov 7, 2026
One is_denied call asked for the same shell payload walk once per
floor, about ten times on a heredoc-fed script, and each walk read
every $( span twice to find its close. The walk now keeps its frames in
the per-call cache sharing_views already opens, so each distinct text
is walked once per decision, and the paren walk skips its second
${...}-aware pass when the span holds no "{", where both passes take
the same steps. Verdicts are unchanged; on the issue's reproducer an
8 KB heredoc goes from about 15 s to 1.7 s.

Builds on #14993 by @yiyabo.

Part of #13980
bolichen97 added a commit that referenced this pull request Nov 9, 2026
One is_denied call asked for the same shell payload walk once per
floor, about ten times on a heredoc-fed script, and each walk read
every $( span twice to find its close. The walk now keeps its frames in
the per-call cache sharing_views already opens, so each distinct text
is walked once per decision, and the paren walk skips its second
${...}-aware pass when the span holds no "{", where both passes take
the same steps. Verdicts are unchanged; on the issue's reproducer an
8 KB heredoc goes from about 15 s to 1.7 s.

Builds on #14993 by @yiyabo.

Part of #13980
bolichen97 added a commit that referenced this pull request Nov 9, 2026
One is_denied call asked for the same shell payload walk once per
floor, about ten times on a heredoc-fed script, and each walk read
every $( span twice to find its close. The walk now keeps its frames in
the per-call cache sharing_views already opens, so each distinct text
is walked once per decision, and the paren walk skips its second
${...}-aware pass when the span holds no "{", where both passes take
the same steps. Verdicts are unchanged; on the issue's reproducer an
8 KB heredoc goes from about 15 s to 1.7 s.

Builds on #14993 by @yiyabo.

Part of #13980
bolichen97 added a commit that referenced this pull request Nov 9, 2026
One is_denied call asked for the same shell payload walk once per
floor, about ten times on a heredoc-fed script, and each walk read
every $( span twice to find its close. The walk now keeps its frames in
the per-call cache sharing_views already opens, so each distinct text
is walked once per decision, and the paren walk skips its second
${...}-aware pass when the span holds no "{", where both passes take
the same steps. Verdicts are unchanged; on the issue's reproducer an
8 KB heredoc goes from about 15 s to 1.7 s.

Builds on #14993 by @yiyabo.

Part of #13980

Backport note: the security package is 34,921 lines on release (main's
base was 35,071), so the pick's 20 lines need the budget raised by 5,
from 34,936 to the measured 34,941, instead of main's 20; the code
merged unchanged.

(cherry picked from commit 9093ac6)
@iamwhatever

Copy link
Copy Markdown
Contributor

Thank you for starting this. As noted above, the work continued in #32115, which merged on 2026-11-09 (merge commit 9093ac6) and now walks a shell command once per deny decision. Closing this PR as superseded by that merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fork Pull request from a fork (external contributor) merge conflict Branch has merge conflicts with its base — author must resolve before merge needs-human-security-review Security scan flagged — needs manual review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants