Skip to content

fix(cli): grade-compare opens a grades file's LUT paths only inside the project - #8724

Merged
miguel-heygen merged 1 commit into
mainfrom
fix/grade-compare-lut-containment
Nov 24, 2026
Merged

miguel-heygen merged 1 commit into
mainfrom
fix/grade-compare-lut-containment

Conversation

@miguel-heygen

Copy link
Copy Markdown
Collaborator

What

hyperframes grade-compare --grades <file> now opens a LUT path from the grades file only when it names a regular file inside the project. A rooted path (\\host\share\…, //host/share/…, \\?\…, another drive, an absolute path) or one that climbs out (../…) is refused from its text alone, before any file call. A path that leaves the project through a link, or names something other than a regular file (a FIFO, a device), is refused too. LUT paths typed with --luts behave as before.

media-use resolve --candidates now lists a project record's path only when it is inside the project, so a manifest path pointing elsewhere is not handed on to grades.json.

Why

A grades file is project data: it travels with the project folder, and the documented flow builds it from the project's .media/manifest.jsonl. prepareGradeCompareTempProject resolved its LUT paths with resolveFromBase, which keeps any absolute value, then called existsSync, readFileSync and copyFileSync on the result. On Windows, merely checking whether \\host\share\x.cube exists signs in to that host. On any OS, a FIFO path blocks the read for good.

Related work

None.

How

  • lutSourcePath in packages/cli/src/commands/grade-compare.ts reuses the in-project rule media-use resolve already applies to manifest records (packages/cli/src/media-use/lib/record-path.mjs). It calls recordPathInProject first, which judges the text alone, then insideProject once links are resolved, plus statSync(...).isFile(). The command passes lutPathsTypedWithLutsFlag only for --luts, so typed paths keep resolveFromBase.
  • listCandidates in packages/cli/src/media-use/lib/candidates.mjs shows a project record's path only when recordPathInProject accepts it, and null otherwise.
  • record-path.d.mts declares the two helpers for TypeScript, like the other media-use .d.mts files.

No visible change

Command-line behaviour only; a grades file with in-project LUT paths renders as before.

Test plan

  • Unit tests added/updated
  • Manual testing performed
  • Documentation updated (if applicable)
  • Comments follow CONTRIBUTING.md "Comments": they say why, not what, and a bug fix says what the code must do and how to reproduce the bug

fails without the fix: packages/cli/src/commands/grade-compare.lutPaths.test.ts wraps node:fs in pass-through spies. refuses %s before any file call on it covers UNC, //host/share, \\?\, another drive and ../. The file also has refuses an absolute path outside the project, though the file is a valid .cube, refuses a link in the project that leads out of it and refuses a FIFO in the project without reading it. With main's grade-compare.ts, 7 of these fail, and the FIFO case blocks the run until it is killed. With the fix, 10 of 10 pass, including still stages a LUT inside the project and keeps a typed --luts path as given. lists a project record's path only when it is inside the project in packages/cli/src/media-use/lib/candidates.test.mjs fails with main's candidates.mjs (1 of 9) and passes with the fix (9 of 9). grade-compare.test.ts (26), record-path.test.mjs (19) and resolve.test.mjs pass, as do cli tsc and fallow.

@vanceingalls vanceingalls 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.

Checked at e1a0ca1. lutSourcePath refuses a rooted path (UNC, //host, \?, drive, absolute) or a ../ climb from the text alone before any file call, then requires a realpath-inside-project check (separator-aware) and statSync().isFile() for grades-file paths. --luts keeps resolveFromBase, and the media-use candidates filter uses the same recordPathInProject rule. The named tests cover each escape case, the link and the FIFO, and the refusal is a plain Error with a clear message. Two non-blocking notes: existsSync runs on the in-project path before links are resolved, so a project symlink pointing at a UNC path is still touched once, and there is a small check-to-read window with no comment saying so. All checks are green.

@miguel-heygen
miguel-heygen added this pull request to the merge queue Nov 24, 2026
Merged via the queue into main with commit 534607f Nov 24, 2026
72 checks passed
@miguel-heygen
miguel-heygen deleted the fix/grade-compare-lut-containment branch November 24, 2026 17:28
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