Skip to content

packages: inline startsWith containment checks bypass the shared isWithin #3423

Closed

Description

@schlessera

Context

#2506 added isWithin(root, path, rule) to @schlessera/brain-common/internal/safe-path and moved the twelve named containment predicates onto it. Outside those twelve, about 110 inline containment checks remain under packages/*/src. They use the shapes startsWith(\${dir}/`), startsWith(dir + sep)andstartsWith(dir + "/")`. Further named copies remain as well:

  • within in packages/ui-server/src/brain/private-index-cache.ts, protected-target.ts, governance-policy.ts, turn-data-tree.ts and packages/ui-server/src/inbox/provenance.ts;
  • under in packages/core/src/lib/scratch.ts;
  • inside in packages/core/src/lib/skills/core-installation.ts, packages/core/src/lib/skills/sync.ts and packages/core/src/lib/storage-inventory.ts (relative()-based).

Epic #2539's definition of done asks for a lint check that refuses a reintroduced inline startsWith(root + "/").

isWithin is not on main yet: it lands with #2506's PR #3424, which targets the epic/2539-security-helpers integration branch. Start from that branch (or main once the epic batch lands) after #3424 merges, and re-run the inventory grep there, since the counts above predate it.

The inventory came from this grep, which also matches some non-path prefixes, such as UI routes in ui-react:

grep -rnE 'startsWith\(\s*(`\$\{[A-Za-z_.!]+\}(/|\$\{sep\})`|[A-Za-z_.!]+ ?\+ ?(sep|"/")\s*\))' packages/*/src

Its heaviest files are packages/ui-sdk/src/server/worker-protection.ts (8), worker-native-output.ts (7), packages/ui-server/src/brain/provider-types.ts (6), packages/ui-sdk/src/server/worker-output.ts (6) and worker-launcher.ts (6).

Scope

  • Replace every path-containment instance the grep finds with isWithin and the parameters that keep its current answer, along with the named copies listed above. Leave non-path string prefixes alone, and list them.
  • Add a bun run lint gate that refuses the inline shapes in packages/*/src, with an allowlist for non-path prefixes.

Out of scope

Acceptance criteria

  • The grep above finds only allowlisted non-path prefixes.
  • The lint gate fails on a reintroduced startsWith(\${root}/`)` in a package source file, with a mutation receipt in the PR.
  • Existing tests for each touched file pass unchanged.

Verification

bun run lint
bun run test packages/core packages/ui-sdk packages/ui-server

Contract impact

None.

Refs #2506

Blocked by #2506

Triage 2026-11-03: verified the blocker: #2506 is open and its PR #3424 is unmerged (base epic/2539-security-helpers), so blocked stays. Named the integration branch, linked #3422 for the deny-direction question. Brief complete; agent-ready alongside blocked.

Activity

  1. added
    type: refactor
    area: core
    area: ui-sdk
    area: ui-server
    priority: p2
    security
    blocked
    on Nov 3, 2026
  2. added
    agent-ready
    and removed
    blocked
    on Nov 3, 2026
  3. schlessera commented on Nov 3, 2026

    @schlessera
    OwnerAuthor

    Unblocked: its only blocker, #2506, closed when epic #2539 batch 2 landed on main in #3506 (merge f4ea8ae6f). The epic branch epic/2539-security-helpers is now at that merge.

  4. self-assigned this
    on Nov 4, 2026
  5. schlessera commented on Nov 4, 2026

    @schlessera
    OwnerAuthor

    Claimed (token c3423-0e1c). Branch feat/3423-iswithin-inline from epic/2539-security-helpers (fast-forwarded to main 5c9b23d44); PR will target the epic branch.

  6. added this to the 0.45.0 milestone on Nov 4, 2026
  7. schlessera commented on Nov 4, 2026

    @schlessera
    OwnerAuthor

    PR #3575 (head 5391db4b6, base epic/2539-security-helpers) is ready for review. It moves every inline containment site and named copy onto isWithin without changing any answer, and adds the check-inline-containment lint gate with mutation receipts. Hosted proof is pending. Found during the run and filed separately: #3574 (a ui-server mount-timer flake under load). I keep the assignment while the PR is live.

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

Metadata

Metadata

Assignees

Labels

agent-readyarea: corearea: ui-sdkarea: ui-serverpriority: p2securitytype: refactor

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions