Repository navigation
Description
Follow-up from #1045 Phase 2 review (PR #1050). While fixing the resolveProjectLexicons bypass (a full, unsandboxed discover() call that executed every project source file before the sandboxed build ever ran), the same reviewer asked for a broader audit of pre-build paths that import project source. chant lint and watch mode came back clean; components/discover.ts did not.
The finding
discoverComponents() (packages/core/src/components/discover.ts) always does:
exports = await import(pathToFileURL(resolve(filePath)).href);for every discovered *.component.ts file — unconditionally, in the CLI's own process, with no --fold/--sandbox equivalent at all. A *.component.ts file is project source the same way a src/*.ts infra file is; a malicious one (e.g. console.error(readFileSync("/etc/passwd")) at module top level, plus a real Component export so discovery doesn't just error out) executes with full filesystem/network/environment access the moment discoverComponents reaches it.
Call sites (all unsandboxed today):
packages/core/src/components/cli-support.tspackages/core/src/cli/handlers/components.tspackages/core/src/cli/handlers/graph.tspackages/core/src/cli/handlers/lifecycle.tspackages/core/src/lifecycle/status.tspackages/core/src/lint/component-checks.ts(chant lint's COMP* checks)
Why this wasn't folded into #1045 Phase 2 / PR #1050
Sandboxing this properly touches at least six call sites plus new CLI flag plumbing, and deserves its own differential-style verification the way #1045 Phases 1–2 got for the resource-entity discovery path — not something to bolt on under time pressure onto an already-large security PR. resolveProjectLexicons (the reported bug) is fixed and regression-tested in PR #1050; this is a distinct, analogous gap in a different discovery convention.
Why this one should be materially EASIER than #1045's entity sandbox
Component (packages/core/src/components/component.ts) is plain JSON data, not a Declarable — no AttrRef/live-object cross-references, no entity-wire codec needed. isComponent() is a duck-type check (name/dependsOn/deploy shape), and projectToJson() already proves a Component round-trips through a bare JSON.parse(JSON.stringify(...)). That means the child process in a sandboxed variant can hand back plain JSON directly — no EntitySetWire-equivalent needed, no AttrRef reconstruction. The one thing to preserve carefully: discoverComponents's existing duplicate-name check compares by object identity (existing.component !== value, tolerating the same object re-exported from multiple bindings) — that check needs to run INSIDE the child, over live objects, before anything is serialized, mirroring how collectEntities runs inside chant#1045 Phase 2's sandboxed child today (see packages/core/src/discovery/sandbox/run.ts/driver.ts).
Suggested shape
- Refactor
discoverComponentsto separate "import each file" from "collect + duplicate-check the already-imported exports" (mirrorscollect.ts'scollectEntitiestaking pre-importedmodules). - Add a sandboxed variant reusing
packages/core/src/discovery/sandbox/bundle.ts'sbundleDriver(generic — doesn't care what the driver does) with a new, much simpler driver template: import each*.component.tsfile via a literal-string dynamic import (same lazy-init trick), run the collect+duplicate-check step,JSON.stringifythe result, send over IPC. - Thread a
sandboxoption throughdiscoverComponents(path, { sandbox })and wire--sandboxthrough the CLI call sites listed above. - Hostile-fixture regression test analogous to
packages/core/src/cli/security-boundary.test.ts, but for*.component.ts.
Related, smaller finding worth a look in the same pass
chant lint's own file-linting is already execution-free (runLint works over file text/AST, not live imports) — confirmed safe. But loadPluginRules/loadLocalRules (packages/core/src/cli/commands/lint.ts) import project-specified lint-plugin files (chant.config.ts's lint.plugins, .chant/rules/*.ts) unconditionally too. This is arguably closer to chant.config.ts itself (an explicit, project-authored extension point, not an automatically-discovered infra file) than to the resolveProjectLexicons bug, but it's the same class of "no isolation option exists here at all" gap and is worth deciding on explicitly rather than by omission.
Activity
fix(cli): resolveProjectLexicons must not execute project source (cha…
feat(core): sandbox the --fold run-fallback path (chant#1045 Phase 2) (…
lex00 commentedon Jul 26, 2026
Closed by #1053 (
d5b94031).Verified independently with a hostile
*.component.tsdriven through the real CLI, evidence routed through the component name:--sandboxreadu-writeok-spawnok-env77--sandboxblkerraccessdenied-…-…-env2Read, write and spawn all denied; environment cut from 77 variables to 2; component still discovered correctly.
The duplicate-name identity check runs inside the child before serialization, as the issue required. The related
loadPluginRules/loadLocalRulesquestion got an explicit recorded decision rather than being settled by omission — not sandboxed, because aLintRule.check()is invoked inline per file across the whole lint run rather than being a one-shot data producer, so isolating the import alone would not contain it.