Repository navigation
fix(cli): confine every swizzle write, not just the output base - #6573
Conversation
swizzle checked --output with assertWithin but then wrote the component folder and files without checking them. A symlinked component folder or file inside the output base sent the copy outside the project, with exit 0.
|
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 confines astryx swizzle writes to the project. Previously only --output was checked, so a symlinked component folder or destination file could silently write — or overwrite with --overwrite — outside the project while reporting success. Now every destination file is checked before any write and an escape is refused with ERR_PATH_TRAVERSAL, matching the documented confined-write contract. The new regression tests cover both the symlinked folder and the symlinked file cases, and normal swizzle paths are unchanged.
One scope note: dangling symlinks are not yet resolved by the shared path guard itself, so coverage for that case depends on the separate guard fix — this change already routes every destination through the guard, so no further swizzle change should be needed once that lands.
[Automated review]
User impact
Anyone who runs
astryx swizzle <Component>in a project whose output folder (defaultcomponents/astryx/) contains a symlink. If the component's folder, or one of the files it would write, is a symlink that points outside the project, the copy follows the link and writes outside the project root. The command exits 0 and its receipt names the in-project path, so neither a person nor an agent can tell. With--overwrite, an existing symlinked file overwrites the file it points to, wherever that file is. After this change the command refuses withERR_PATH_TRAVERSALbefore it writes anything.Problem and solution fit
swizzleCopyruns--outputthroughassertWithin, which resolves symlinks for that one path. It then joins the component name and each file name onto that base and writes, and it never checks those joined paths.The fix runs every destination file through the same
assertWithincheck before the firstmkdiror write, and reports an escape asERR_PATH_TRAVERSAL, the code the architecture assigns to a path escape.Expected behavior and authority
docs/architecture/cli-surface.md(current), INV10:Compatibility (
spec:AST-017FR5): this restores the documented contract. No valid use changes. Writing outside the project through a symlink was never a supported result.Smallest restoration
api/swizzle/copy/copy.mjs: one small helper,confineWrite. It callsassertWithinand mapsPathSafetyErrortoERR_PATH_TRAVERSAL, as the existing--outputcheck already did. The helper is used for--outputand for each destination file, all before anymkdiror write. Nothing else moves.api/swizzle/swizzle.doc.mjs: theERR_PATH_TRAVERSALentry names the symlink case.A dangling symlink, whose target does not exist yet, is not resolved by
assertWithintoday. That belongs to the shared guard and is fixed separately there. With that fix, this change covers the dangling case too, because every destination now passes the guard.Evidence
components/astryx/Button -> ../../../outside,astryx --json swizzle Buttonexits 0, reportsoutputDir: components/astryx/Button, and writesoutside/Button.tsx. Withcomponents/astryx/Button/Button.tsxsymlinked to an outside file,astryx --json swizzle Button --overwriteexits 0 and replaces that outside file's contents.{"code": "ERR_PATH_TRAVERSAL"}, and nothing outside the project changes.--overwriteover real files, and the existing--output ../xand absolute-path refusals (swizzle.path-safety.test.mjs,copy.test.mjs,swizzle.routing.test.mjs, all green).clients/cli/commands/swizzle.path-safety.test.mjs(a symlinked component folder, and a symlinked existing file with--overwrite). Both fail onmain. They also fail when only the per-file check is removed, and pass with the fix.Scope
Testing