Repository navigation
Description
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_CONTAINMENTandexport function safeResolve,packages/core/src/lib/safe-path.ts:7-24. This is a public export of@schlessera/brain/module. - ui-sdk:
const SDK_CONTAINMENTandexport function resolveInRepo,packages/ui-sdk/src/server/bridge-tools/resolve-in-repo.ts:4-18. - ui-server:
const SERVER_CONTAINMENTandexport 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:
- 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. - 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 asbreakingin a named minor. - 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
startsWithchecks, 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.tsthat 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-serverContract 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
schlessera commentedon Nov 3, 2026
Decision (maintainer, 2026-11-03):
resolveInRepoand ui-serversafeResolve: 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'stests/containment-rows.test.tsthat fails on the losing answer.safeResolve(public,@schlessera/brain/module): tighten it to the same strictest answers as a breaking change in the 0.45.0 minor. That means aCONTRACT:commit, the integration-contract index updated and the change marked breaking, a changeset with migration notes, and every in-repo caller checked.isWithin(root, path, { trailingSeparator: "boundary" })everywhere, so/holds every absolute path. Drop the hand-written=== "/"checks. Test each deny site with a/source, includingworker-launcher.ts:298,:861,:874andsync-mirror.ts.schlessera commentedon Nov 3, 2026
Claiming (claim token
c3422-4b10). Implementing the 2026-11-03 ruling on branchfix/3422-strict-containment, based onepic/2539-security-helpers; the PR targets that epic branch.Collision report: path collisions on
packages/ui-sdk/src/server/worker-launcher.tswith #3396 and #3408 (both on other bases); closure-only overlaps otherwise. I'll keep off #3418's files.schlessera commentedon Nov 3, 2026
Triage 2026-11-03 (maintainer-approved): added
blockedandBlocked by #2506. This issue edits the containment rows that #2506 moves into@schlessera/brain-common/internal/safe-path, which exists only onepic/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.schlessera commentedon Nov 3, 2026
Implementation is up in #3465, against
epic/2539-security-helpers. It applies the 2026-11-03 ruling:safeResolvechanges as a breakingCONTRACT:change in 0.45.0, with a changeset and the contract index;/holds every absolute path.The PR records the caller audit, failing-first and mutation receipts, and three open points:
=== "/"checks inmaintenanceMountsare kept, because they refuse/itself rather than an ancestor of the brain.transportMountsis shadowed for a/read path byvalidateRuntimePlacement, which now refuses it first.The issue closes when the epic batch lands on main. I keep the assignment while the PR is live.
CONTRACT: fix(cli): convert absolute CLI path arguments inside the br…
CONTRACT: docs(contract): describe the CLI conversion of absolute in-…
schlessera commentedon Nov 3, 2026
Follow-up on #3465 for the 2026-11-03 CLI ruling. Head is now
3f653943c, withepic/2539-security-helpersat88547621amerged in.brainRelativeArgument(root, arg), from@schlessera/brain/module.safeResolve/resolveWritablegoes through it. An absolute path inside the brain becomes brain-relative before resolution...segment;safeResolvestays strict.read,archive,process,import,render,eval,geo,okf;image,diagram,travel).--outare restored. New tests cover inside, outside and symlink escape. Mutation receipts M21–M31 are in the PR.I keep the assignment while the PR is live.
CONTRACT: fix(core,ui-sdk,ui-server): give the strictest containment …