Repository navigation
fix(core): treat files package managers run by default as tool-trusted - #8129
Conversation
npm, pnpm, yarn and bun run `node-gyp rebuild` on install when a binding.gyp is present and package.json has no install script, and a .gyp file can include any .gyp or .gypi. npm, pnpm and yarn run `node server.js` for start when package.json has no start script. A project from `hyperframes init` has neither script, so both defaults apply. toolTrustedFileKind now classifies .gyp/.gypi files and server.js, in every spelling projectPathSegments folds, so Studio's file routes and the registry installer refuse to write them. Rename and duplicate refusals now report why: protected_path when the destination is inside the project, as POST and PUT already do.
6c8f0b0 to
dbcf83c
Compare
Edit accuracy: accurate 271 (base branch 271), smooth 62 of thoseThe gate passes. Quarantined, measured but not gated (0) Unstable (2)
|
jrusso1020
left a comment
There was a problem hiding this comment.
Reviewed at dbcf83c.
Looks good.
Matching. Both additions go through projectPathSegments, and the new cases pass for every spelling it folds:
- case and trailing dots or spaces (
BINDING.GYP.,Server.JS.); ::$DATA;- nested folders (
deps/common.gypi,sub/server.js); - short names.
BINDIN~1.GYP lands as tool-config through the .gypi?$ rule rather than as a short name, which is still a refusal. assets/webserver.js and assets/server.json stay writable.
Every write path.
- POST, PUT, rename and duplicate all resolve through
isWritableProjectPath→toolTrustedFileKind. - Uploads check each file with
isWritableProjectFile. - The batch edit path uses
pinWritableWithinProject. - The registry installer refuses the target before writing anything.
The rename and duplicate routes now return why: "protected_path" for a destination inside the project. A destination outside it still gets the bare forbidden.
Completeness. The other files a package manager reads implicitly are already refused:
.npmrc,.yarnrc,.yarnrc.yml,.pnpmfile.cjsand.pnp.cjsare hidden paths, which Studio writes and the installer both refuse;bunfig.toml, the lock files andpackage.jsonare on the existing lists.
So binding.gyp, .gypi and server.js were the gaps.
Tests. At this head:
- core
safePath.test.ts: 198 passed; - studio-server
files.pathSafety+helpers/safePath: 119 passed; - cli
installer.test.ts: 74 passed.
With the safePath.ts change reverted, 10, 6 and 5 of those fail respectively.
One note, not blocking: a project that already has a server.js or a .gyp file can no longer edit, rename onto or delete it through Studio. That matches how the existing program and tool-config kinds behave.
What
toolTrustedFileKindnow treats the files a package manager runs by default as tool-trusted, so Studio's file routes and the registry installer refuse to write them:.gypand.gypifiles, anywhere in the project: npm, pnpm, yarn and bun runnode-gyp rebuildon install when abinding.gypis present andpackage.jsonhas no install script (npm does it for any root.gyp), and a.gypfile can include any other.gypor.gypi.server.js, anywhere in the project: npm, pnpm and yarn runnode server.jsforstartwhenpackage.jsonhas no start script.Rename and duplicate refusals now also say
why: "protected_path"when the destination is inside the project, matching POST and PUT.Why
The existing list covered files that
package.jsonnames, plus config files tools load, but not these two defaults. Thepackage.jsonthathyperframes initwrites has no install or start script, so both defaults apply to a fresh project.Related work
None.
How
packages/core/src/safePath.ts: a\.gypi?$entry inTOOL_CONFIG_FAMILIES(kindtool-config) andserver.jsas aprogram. Both go throughprojectPathSegments, so every spelling it folds (case, Unicode form, trailing dots and spaces,::$DATA, short names) is covered.packages/studio-server/src/routes/files.ts: a smallforbiddenWriteTargethelper for the rename and duplicate routes. A destination outside the project still gets the bareforbidden.@npmcli/package-jsonnormalize, pnpm lifecycle, yarn 1 manifest fix), and ran bun 1.4 against a scratch project:bun installrunsnode-gyp rebuildfor a rootbinding.gyp, andbun run starthas noserver.jsfallback. No registry item or template uses either name.Test plan
toolTrustedFileKindcases for each spelling; POST, PUT, rename, duplicate and upload refusals infiles.pathSafety.test.ts; installer refusals for blocks inlib/,assets/andcompositions/, and for an example at the project root. The new cases fail without the change and pass with it. One existing test that wroteserver.jsas an ordinary file now writesrun.js.hyperframes initproject, writes ofbinding.gyp,server.jsand a nested.gypithrough Studio's file API returned 201 before the change. After it they return 403protected_pathin every spelling, and so do rename and duplicate onto those names. Ordinary saves (Code tab edit, compositions, CSS, JS assets, rename, duplicate) still succeed, and the console shows no errors.