Repository navigation
fix(cli): confine the file layout expand writes, not just its folder - #6564
Conversation
`astryx layout expand <expr> <dir>` passed only the directory through the path guard, so a symlink named <Name>.tsx inside it carried the generated TSX outside the project. The guard now sees the file that will be written.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
There was a problem hiding this comment.
This change correctly restores write confinement for layout expand: the directory target previously passed the path guard while the file actually written (<dir>/<Name>.tsx) did not, so a symlinked generated file could silently overwrite a file outside the project. Guarding the file path matches the CLI spec's rule that every write is confined and an escape is ERR_PATH_TRAVERSAL, with no new API, option, or output change, and the new tests cover both the symlink rejection (outside file untouched) and the unchanged plain-directory write.
One disclosed limitation remains out of scope here: a dangling symlink at the generated file name is still missed by the shared path guard — that pre-existing gap affects all writers and is tracked separately.
[Automated review]
…6887) `astryx layout expand`, `astryx layout check` and `astryx layout grammar` shipped in published `@astryxdesign/[email protected]`, as ordinary registered top-level commands with documented examples, manifest entries, a `layout` docs topic, and the `layout.expand` / `layout.check` / `layout.grammar` response schemas. Four fixes to them (#6564, #6569, #6565, #6572) are in 0.6.4's changelog. They are a stable released CLI surface under `spec:AST-017` FR3. #6615 removed that surface in one step. `spec:AST-017` (authority: current) does not allow this yet: - FR28 requires a replacement-first deprecation patch and a public `DEP-*` record before a removal becomes eligible. There is none. - FR31 allows a removal only when its `DEP-*` and `CLN-*` ids appear in a frozen minor manifest. There is no such manifest. - FR37 requires an owner-approved public minor plan before freeze. There is no approved minor plan. - FR22 forbids retroactively demoting a released stable surface to experimental. `layout` was never behind an experimental boundary: FR27 requires a dedicated experimental namespace, and only the `experimental.xle.components` config key had one — the command did not. So this reverts #6615 and drops its `[breaking]` Changeset. Effect on the next release, measured with `changeset status`: - before: all ten fixed-group packages bump **minor** -> 0.7.0 - after: all ten bump **patch** -> 0.6.5 The ten manifests read 0.6.4, which is the published base; the target is derived from that base plus the highest pending bump. One `minor` Changeset in a `fixed` group moves all ten, which is why a single unplanned removal re-targeted the whole release. This is compatibility restoration, not new behavior. Nothing is invented and no deprecation metadata is added: `layout` returns to exactly its 0.6.4 shape, and its deprecation is left to be decided explicitly under AST-017. Because the removal was never published, main after this change is identical to 0.6.4 for consumers, so the restoration needs no Changeset of its own. The retained `@astryxdesign/cli/xle` barrel and the `experimental.xle.components` config key are untouched. Conflicts with later main commits were resolved toward main, not toward the revert: - `packages/cli/README.md` keeps main's rewritten descriptions and is regenerated, so the `layout` row and config row come from the restored docs. - `packages/cli/test/docs-graph.test.mjs` stays deleted; #6737 removed it for unrelated reasons. - `doc-routes.ids.json` keeps both `integration verify` (#6737) and the layout ids. Note for a follow-up: #6737 re-added the layout ids to `packages/cli/test/doc-routes.ids.json` while the command stayed deleted, so main currently claims four layout commands and three layout functions that do not exist. This change makes that file honest again. Test plan: - `npx vitest run --root . packages/cli` — 5314 passed, 0 failed - `pnpm check:repo` — passes, including `check:changesets` - `npx changeset status` — all ten packages at patch (0.6.5), none at minor - `astryx layout grammar|check|expand` run again from the built CLI - `astryx manifest --json` reports 17 top-level commands, matching the restored `spec:AST-042` text
User impact
Anyone who runs
astryx layout expand <expr> <dir>(or callslayoutExpand(expr, {targetPath})) in a project where<dir>/<Name>.tsx—GeneratedLayout.tsxby default — is a symlink to a file outside the project. The directory passed the path guard, but the file inside it was never checked, andlayout expandhas no overwrite guard, so the generated TSX silently replaced the outside file. No flag was needed.After the change the command refuses with
ERR_PATH_TRAVERSALand writes nothing.Problem and solution fit
api/layout/expand/expand.mjsranassertWithinon the target directory, then joined<Name>.tsxonto the result and wrote there. The joined path never passed the guard.The fix computes the file that will be written first and passes that path through the same guard.
data.writtenis unchanged.Expected behavior and authority
docs/architecture/cli-surface.md(authority: current), INV10: "Every write is confined. Output paths passassertWithin, which canonicalises symlinks and rejects a NUL byte; an escape isERR_PATH_TRAVERSAL."The output path is the file, so it has to pass
assertWithin.Smallest restoration
One guard call moves from the directory to the file path; the file-vs-directory decision, the file name and the receipt are unchanged. No new option, code, or output field.
Evidence
@astryxdesign/coreinstalled,lay/GeneratedLayout.tsx -> ../../outside/victim.tsx;astryx --json layout expand 'V > B' ./layreturnedlayout.expandandoutside/victim.tsxnow held the generated TSX.ERR_PATH_TRAVERSALand the outside file keeps its content.<Name>.tsxand reports it indata.written(new test), and a./file.tsxtarget is unchanged (it already passed the guard as the file path).api/layout/expand/expand.path-safety.test.mjs› "rejects a directory target whose generated file is a symlink leading outside cwd". With only the fix reverted, that test fails; with the fix it passes.A dangling symlink at the file name is not caught yet:
assertWithinfinds the deepest existing ancestor withexistsSync, which follows links, so a link to a missing file is skipped. That gap is in the shared guard and affects every writer; it is tracked separately. This change is still needed for that fix to reach the directory branch.Scope
Testing