Skip to content

fix(core): treat files package managers run by default as tool-trusted - #8129

Merged
andybpan merged 1 commit into
mainfrom
fix/tool-trusted-implicit-files
Nov 18, 2026
Merged

andybpan merged 1 commit into
mainfrom
fix/tool-trusted-implicit-files

Conversation

@andybpan

Copy link
Copy Markdown
Contributor

What

toolTrustedFileKind now 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:

  • .gyp and .gypi files, anywhere in the project: npm, pnpm, yarn and bun run node-gyp rebuild on install when a binding.gyp is present and package.json has no install script (npm does it for any root .gyp), and a .gyp file can include any other .gyp or .gypi.
  • server.js, anywhere in the project: npm, pnpm and yarn run node server.js for start when package.json has 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.json names, plus config files tools load, but not these two defaults. The package.json that hyperframes init writes 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 in TOOL_CONFIG_FAMILIES (kind tool-config) and server.js as a program. Both go through projectPathSegments, 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 small forbiddenWriteTarget helper for the rename and duplicate routes. A destination outside the project still gets the bare forbidden.
  • I checked each default against the package managers' own source (npm @npmcli/package-json normalize, pnpm lifecycle, yarn 1 manifest fix), and ran bun 1.4 against a scratch project: bun install runs node-gyp rebuild for a root binding.gyp, and bun run start has no server.js fallback. No registry item or template uses either name.

Test plan

  • Unit tests added/updated: toolTrustedFileKind cases for each spelling; POST, PUT, rename, duplicate and upload refusals in files.pathSafety.test.ts; installer refusals for blocks in lib/, assets/ and compositions/, and for an example at the project root. The new cases fail without the change and pass with it. One existing test that wrote server.js as an ordinary file now writes run.js.
  • Manual testing performed: in a hyperframes init project, writes of binding.gyp, server.js and a nested .gypi through Studio's file API returned 201 before the change. After it they return 403 protected_path in 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.
  • Documentation updated (if applicable): no docs list these names.
  • Comments follow CONTRIBUTING.md "Comments"

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.
@andybpan
andybpan force-pushed the fix/tool-trusted-implicit-files branch from 6c8f0b0 to dbcf83c Compare November 18, 2026 01:07
@github-actions

Copy link
Copy Markdown
Contributor

Edit accuracy: accurate 271 (base branch 271), smooth 62 of those

The gate passes.
Smoothness is reported in the artifact, not gated. A case fails only if it fails 2 of 3 runs.

Quarantined, measured but not gated (0)

Unstable (2)

  • seqplainkeys-none-pct-r0-nested-z100: tracking 0.05, pressJump 0, drop 0, reload 0, render 0.02, renderKey -, undo true, teleport true / tracking 0.05, pressJump 0, drop 0, reload 0, render 0.02, renderKey -, undo true, teleport true / tracking 0.05, pressJump 0, drop 0, reload 0, render 0.02, renderKey -, undo true, teleport true
  • seqab-none-pct-r0-root-z100: tracking 0.05, pressJump 0, drop 0, reload 0, render 0.03, renderKey -, undo true, teleport true / tracking 0.05, pressJump 0, drop 0, reload 0, render 0.03, renderKey -, undo true, teleport true / tracking 0.05, pressJump 0, drop 0, reload 0, render 0.03, renderKey -, undo true, teleport true

@andybpan
andybpan marked this pull request as ready for review November 18, 2026 01:17

@jrusso1020 jrusso1020 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.cjs and .pnp.cjs are hidden paths, which Studio writes and the installer both refuse;
  • bunfig.toml, the lock files and package.json are 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.

@andybpan
andybpan added this pull request to the merge queue Nov 18, 2026
Merged via the queue into main with commit 5f06e1b Nov 18, 2026
98 checks passed
@andybpan
andybpan deleted the fix/tool-trusted-implicit-files branch November 18, 2026 01:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants