Skip to content

core, ui-sdk, ui-server: rule on the containment answers the shared resolver still keeps per caller #3422

Closed

Description

@schlessera

Context

#2506 moved symlink-safe containment into one implementation, @schlessera/brain-common/internal/safe-path. Under that move every caller kept its own answers, except two named corrections. The callers' rows are now stated in one place each, and they still disagree. Each disagreement is a security policy question. Which rule wins needs a ruling, so this issue records the differences and a recommendation. Nothing here is implemented.

Line references are to the #2506 branch, which lands with the next epic/2539-security-helpers batch:

  • core: const CORE_CONTAINMENT and export function safeResolve, packages/core/src/lib/safe-path.ts:7-24. This is a public export of @schlessera/brain/module.
  • ui-sdk: const SDK_CONTAINMENT and export function resolveInRepo, packages/ui-sdk/src/server/bridge-tools/resolve-in-repo.ts:4-18.
  • ui-server: const SERVER_CONTAINMENT and export async function safeResolve, packages/ui-server/src/files/walker.ts:71-107.
Question core safeResolve ui-sdk resolveInRepo ui-server safeResolve Strictest
Absolute request inside the root accepted refused refused refuse
.. that stays inside accepted accepted refused refuse
: or \ in a segment accepted accepted refused refuse
Dangling link whose target is inside followed (danglingLinks: "follow") followed refused refuse
Out through one link and back through another (bounce/back/a.md) accepted (components: "final") accepted refused (components: "every") refuse
Root whose realpath fails refused refused a missing root falls back to the lexical root refuse
Answer canonical path canonical path lexical path —

A second, separate question concerns the containment predicates. With the default rule (isWithin(root, path)), a root of / holds nothing below it. That is the safe answer for an allow-check and the unsafe one for a deny-check. Example: the transport mount check within(source, brain) || within(brain, source) in packages/ui-sdk/src/server/worker-launcher.ts:298 would not refuse a --bind whose source is /. Some deny-checks spell out === "/" (worker-launcher.ts:420, :469, :487) and some do not (:298, :861, :874, sync-mirror.ts within(input.brain, path) || within(path, input.brain)). Whether any of the unguarded sites can receive / has not been verified.

Scope

Rule on each row, then implement the ruling as a change to the wrapper's policy object or request refusals. The shared algorithm already exposes each dimension as a parameter.

Recommendation, separate from approval:

  1. ui-sdk and ui-server: adopt the strictest answer in every row. Their callers are first-party tool and file routes, which have no reason to send absolute paths, .., Windows syntax or dangling links.
  2. core safeResolve: it is public, so a stricter answer is a contract change. Keep its answers and add a stricter sibling for new callers, or rule that the change ships as breaking in a named minor.
  3. Deny-direction predicates: use isWithin(root, path, { trailingSeparator: "boundary" }), so / holds every absolute path, and drop the hand-written === "/" checks.

Out of scope

  • The shared algorithm itself (packages/common/src/safe-path.ts), apart from new tests a ruling needs.
  • The roughly 110 inline startsWith checks, which are tracked separately.

Acceptance criteria

  • A maintainer ruling on each row of the table and on the / deny-direction question is recorded on this issue.
  • Each changed row has a test in that package's tests/containment-rows.test.ts that fails on the losing answer.
  • Each changed public answer has a changeset, a CONTRACT: commit and an update to the integration contract.

Verification

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

Contract impact

core safeResolve is exported from @schlessera/brain/module. Changing its answers is a contract change and needs the ruling first.

Refs #2506

Blocked by #2506

Triage 2026-11-03: declared the #2506 dependency (its shared safe-path implementation is not on main; PR #3424 is open). Work based on epic/2539-security-helpers can proceed there; the label clears when #2506 closes.

Activity

  1. added
    type: refactor
    area: core
    area: ui-sdk
    area: ui-server
    priority: p2
    needs: decision
    security
    on Nov 3, 2026
  2. schlessera commented on Nov 3, 2026

    @schlessera
    OwnerAuthor

    Decision (maintainer, 2026-11-03):

    1. ui-sdk resolveInRepo and ui-server safeResolve: take the strictest answer in every row. Refuse absolute requests even inside the root, .. even when it stays inside, : or \ in a segment, dangling links, and out-and-back links (components: "every"). Refuse a root whose realpath fails. Each changed row needs a test in that package's tests/containment-rows.test.ts that fails on the losing answer.
    2. core safeResolve (public, @schlessera/brain/module): tighten it to the same strictest answers as a breaking change in the 0.45.0 minor. That means a CONTRACT: commit, the integration-contract index updated and the change marked breaking, a changeset with migration notes, and every in-repo caller checked.
    3. Deny-direction predicates: use isWithin(root, path, { trailingSeparator: "boundary" }) everywhere, so / holds every absolute path. Drop the hand-written === "/" checks. Test each deny site with a / source, including worker-launcher.ts:298, :861, :874 and sync-mirror.ts.
  3. added
    agent-ready
    contract
    breaking
    on Nov 3, 2026
  4. added this to the 0.45.0 milestone on Nov 3, 2026
  5. removed
    needs: decision
    on Nov 3, 2026
  6. self-assigned this
    on Nov 3, 2026
  7. schlessera commented on Nov 3, 2026

    @schlessera
    OwnerAuthor

    Claiming (claim token c3422-4b10). Implementing the 2026-11-03 ruling on branch fix/3422-strict-containment, based on epic/2539-security-helpers; the PR targets that epic branch.

    Collision report: path collisions on packages/ui-sdk/src/server/worker-launcher.ts with #3396 and #3408 (both on other bases); closure-only overlaps otherwise. I'll keep off #3418's files.

  8. added
    blocked
    on Nov 3, 2026
  9. schlessera commented on Nov 3, 2026

    @schlessera
    OwnerAuthor

    Triage 2026-11-03 (maintainer-approved): added blocked and Blocked by #2506. This issue edits the containment rows that #2506 moves into @schlessera/brain-common/internal/safe-path, which exists only on epic/2539-security-helpers (PR #3424 open), not on main. The current claim already bases its branch on that epic branch, so this records the dependency rather than stopping that work.

  10. schlessera commented on Nov 3, 2026

    @schlessera
    OwnerAuthor

    Implementation is up in #3465, against epic/2539-security-helpers. It applies the 2026-11-03 ruling:

    • every resolver row now gives the strictest answer;
    • core safeResolve changes as a breaking CONTRACT: change in 0.45.0, with a changeset and the contract index;
    • deny-direction predicates use the boundary rule, so / holds every absolute path.

    The PR records the caller audit, failing-first and mutation receipts, and three open points:

    1. Absolute CLI path arguments are now refused, as the containment guarantee states.
    2. Two === "/" checks in maintenanceMounts are kept, because they refuse / itself rather than an ancestor of the brain.
    3. transportMounts is shadowed for a / read path by validateRuntimePlacement, which now refuses it first.

    The issue closes when the epic batch lands on main. I keep the assignment while the PR is live.

  11. schlessera commented on Nov 3, 2026

    @schlessera
    OwnerAuthor

    Follow-up on #3465 for the 2026-11-03 CLI ruling. Head is now 3f653943c, with epic/2539-security-helpers at 88547621a merged in.

    • One shared helper: brainRelativeArgument(root, arg), from @schlessera/brain/module.
    • What it does: every CLI path argument that reaches safeResolve/resolveWritable goes through it. An absolute path inside the brain becomes brain-relative before resolution.
    • Still refused:
      • an absolute path outside the brain;
      • one with a .. segment;
      • one through a symlink that leaves the brain.
    • safeResolve stays strict.
    • Commands covered: the audit is in the PR body (core read, archive, process, import, render, eval, geo, okf; image, diagram, travel).
    • Tests: the eval and image tests that accept an absolute in-brain --out are restored. New tests cover inside, outside and symlink escape. Mutation receipts M21–M31 are in the PR.
    • Docs: the changeset, the contract index and the package API component now describe the CLI behaviour.

    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-serverblockedbreakingcontractpriority: p2securitytype: refactor

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions