Repository navigation
fix(cli): show control characters in printed names as visible escapes - #8008
Conversation
…capes check, info, compositions, benchmark, play, present and preview printed the project folder name, and in places the project path, straight to the terminal. A folder name can hold escape bytes on Linux and macOS, so a received project could move the cursor, rewrite earlier lines, set the window title or write the clipboard. Those lines now go through terminalText(), as validate, snapshot, layout and lint already do. This covers the preview summary, --status, --stop, --list and --kill-all lines, and the check report path. The CLI's own colours stay, and --json output is unchanged. The play page also HTML-escapes the name in its title and footer, as the present page does.
…ble escapes The human output of preview --selection and --context printed the selected element's label, source file, target and thumbnail URL, and the preview server's project name, straight to the terminal. These come from the composition or from whichever preview server answers, so control characters in them could move the cursor, rewrite earlier lines, set the window title or write the clipboard. They now go through terminalText(), as do the failure messages these commands print. The CLI's own colours stay, and --json output is unchanged.
…scapes The human output of cloud get printed render fields from the server, such as the failure message, title, composition and URLs, straight to the terminal. A failure message can quote text from the rendered project, so control characters in it could move the cursor, rewrite earlier lines, set the window title or write the clipboard. cloud get, cloud list (rows and the next-page token) and cloud delete now pass those fields through terminalText(). The CLI's own colours stay, and --json output is unchanged.
…eration id prepareLiveInspection wrote the project's absolute path into the preview page as window.__hfLiveInspection.project. Nothing in the page reads it, but any composition script on that page could, which told it the account name and folder layout. The page now gets only the generation id; the project path stays with the host that prepared the page.
locate.mjs drew its grid labels with a font at the fixed shared path /tmp/locate-font.ttf. It used whatever file was already there and copied a system font onto that path otherwise, following any link in its place. On a machine shared with other accounts, someone else could plant that file first, so the grid showed wrong numbers, a file appeared where they chose, or every run failed. The font is now copied into a folder made with mkdtemp (mode 0700) for each run and removed when the run ends, so no file another account can create is read or written. The skills manifest hash is regenerated.
…e.mjs font cleanup check's report path notice and its not-recorded warning, and preview's "Lint did not finish" warning, now print control characters as visible escapes, like the other lines that carry the project path. locate.mjs escapes the font path for ffmpeg's filter syntax, so a temp folder with ':', ',', quotes or brackets in its name still works, and it removes its font folder when the run is stopped by SIGINT or SIGTERM before re-raising the signal. play and present share one HTML escape helper.
Edit accuracy: accurate 271 (base branch 271), smooth 67 of thoseThe gate passes. Quarantined, measured but not gated (0) |
miguel-heygen
left a comment
There was a problem hiding this comment.
Escapes the listed CLI sinks with the shared core helpers, moves the live inspection stamp down to the generation id, and puts locate's font copy in a private temp folder. Every fix the body names is correct and tested. Some lines in check and preview were missed, and four sibling commands still print the same folder name raw, so I'm asking for changes.
Strengths
- One helper for every sink:
terminalText/terminalLines/terminalTextDeepfrompackages/core/src/terminalText.ts, applied after colouring is decided and never to--jsonoutput. The tests pin both sides, for examplepackages/cli/src/commands/info.test.tsasserts the escaped human line and the raw--jsonname. packages/cli/src/utils/escapeHtml.ts:1replaces the privateescHtmlthatpresent.tshad, andplay.ts:314now uses it for the<title>and the info line that were raw before.packages/inspector/src/live.ts:51now writes the same stamp shapeservice.ts:262already wrote. Every reader (liveRuntime.ts:4,pageQueries.ts:57,68,92,elementMap.js:91) only reads.generation.skills/hyperframes/scripts/locate.mjs:60escapes in the right order: option level (\ ' :) first, then filtergraph level (\ ' [ ] , ;).gridFiltersputs the path infontfile=unquoted, which is what this escaping assumes. The CodeQL "double escaping" alerts on this line and onlocate.test.mjs:60are false positives: the backslash is escaped twice on purpose, once per level.- Every test the body lists would fail on the base branch. Each one asserts the escaped
\x1btext, the stamp shape or the private folder, and none of them only checks that nothing crashed.
Blockers
All of these print the folder name (basename(dir), utils/project.ts:50) or the absolute project path raw at this head.
- Commands this PR touches:
packages/cli/src/commands/check.ts:897:check --snapshotsprints each finding crop withc.dim(file). Those entries are absolute paths:checkBrowser.ts:707pushesjoin(snapshotDir, filename), andcheckSnapshotDirectory.ts:14resolves the project. A cached pass replays the same list.packages/cli/src/commands/preview.ts:548: background start printsclack.log.error(message)raw. With--force-newor a GPU-mode replacement,startBackgroundPreviewcallsstopBackgroundPreview(previewLifecycle.ts:541). That throwsbackground preview did not stop for ${resolve(projectDir)}(:766) orpreview ownership could not be proven for ${resolve(projectDir)}(:525,:759). Lines 542-550 duplicatereportPreviewFailure(preview.ts:745), which now escapes, so calling it there fixes this and leaves one path.
- Sibling commands with the same failure:
packages/cli/src/commands/render/present.ts:37:hyperframes renderprints "Rendering " and the output path, which defaults to inside that folder.packages/cli/src/commands/cloud/render.ts:701: "Zipping ".packages/cli/src/commands/open.ts:103: "Opening in ...".packages/cli/src/commands/publish.ts:295: the publishedtitlethe server sends back, which comes from the folder name.
A folder named like the one in your tests still sets the window title or writes the clipboard (OSC 52) through any of these. render is the most-used command. Each fix is a one-line terminalText(...) wrap plus a test shaped like the ones here.
Important
packages/cli/src/commands/check.ts:492:check --prepare-mediaprints${file.file}: ${file.reason}raw.file.fileis a media file name from the project, andreasonis the ffmpeg error text. Wrap the line interminalLines.
Nits
packages/cli/src/auth/callbackPage.ts:41keeps its ownescapeHtml, which also escapes'. Folding it intoutils/escapeHtml.ts(with the'case added) leaves the CLI with one HTML escaper.skills/hyperframes/scripts/locate.mjs:68-73: with a SIGINT/SIGTERM listener installed, Node handles the signal only after the synchronousexecFileSynccalls return. A SIGTERM sent tooverlaytherefore no longer stops it between the two ffmpeg calls; cleanup still happens through theexithandler. A closed terminal (SIGHUP) is not listened for, so the folder stays behind in that case.
Verdict: REQUEST CHANGES
Reasoning: Each named fix is correct and has a test that fails without it. But check --snapshots and the background preview start still print the untrusted folder name raw, and so do render, cloud render, open and publish. Each one is a concrete repeat of the bug this PR fixes, with a one-line fix.
jrusso1020
left a comment
There was a problem hiding this comment.
Requesting changes at 64b97c6. I agree with Miguel's review on this sha and checked his blockers against the source.
The fixes the body names are correct, and each one has a test that fails without it. Against base sources the CLI suite fails 16 of 360 (every new test), liveStamp 1 of 1, and locate 1 of 2. Four of five mutants were killed. But the PR's claim is that folder names no longer reach the terminal raw, and these prints still send them raw at this head. With a folder named, for example, x\x1b]52;c;...\x07, any of these lines writes the user's clipboard.
Blockers
packages/cli/src/commands/check.ts:897:check --snapshotsprints each finding crop path withc.dim(file). These are absolute paths under the project folder, andcheckis a command this PR touches.packages/cli/src/commands/preview.ts:548: when a background start fails,clack.log.error(message)prints the message raw. With--force-new, that message is thepreviewLifecycle.tserror that containsresolve(projectDir).reportPreviewFailure(:745) already escapes the same message, so calling it here fixes the leak and removes the duplicate code.- The same raw print in other commands:
render/present.ts:37("Rendering ", and an output path that defaults to<name>_<ts>),cloud/render.ts:701("Zipping "),open.ts:103("Opening "), andpublish.ts:295(published.title, which the server derives from the folder name).
Important
check.ts:492:check --prepare-mediaprints${file.file}: ${file.reason}raw. That is a project media file name plus ffmpeg's error text, andterminalLinesfixes it.
Non-blocking
- The only failing check is CodeQL
js/double-escapingatlocate.mjs:60. It's a false positive, because ffmpeg escapes once for the option and once for the filtergraph. Someone still has to dismiss the alert or restructure the code. I ran real ffmpeg with TMPDIR set tot'm,p:[x];y: it exited 0 and the temp folder was cleaned up. - No test covers the escaping of
present's invalid-island-JSON error (present.ts:121); the mutant that removed it survived. locate.mjshas no SIGHUP handler, so closing the terminal leaves its temp folder behind.- For follow-ups outside this PR: the shared
terminalTexthelper doesn't neutralise bidi overrides or zero-width characters, which can make a name display as something else. Studio'sGET /api/projects/:idstill returns the absolutedir.
— Rames
…ont path in one pass The sign-in callback page uses the shared escapeHtml helper, which now also escapes single quotes. locate.mjs escapes the font path for ffmpeg's option list and filtergraph in a single replacement with the same result as before, and removes its font folder on SIGHUP as well as SIGINT and SIGTERM.
|
Thanks, Miguel and Rames. The changes are in 4a25169. That one commit holds all the fixes below; its message names only the last two groups because the separate commit for the CLI fixes was rejected by commitlint for a long header. Blockers
Important
Nits and non-blocking items
|
jrusso1020
left a comment
There was a problem hiding this comment.
Requesting changes at 4a251694. Every item from my last review is fixed and tested: check.ts:897, preview.ts:548 (now reportPreviewFailure), present.ts:37, cloud/render.ts:701, open.ts:103, publish.ts:295, check.ts:492, the untested present.ts:121, SIGHUP in locate.mjs, and the shared escapeHtml. CodeQL is green, and the escaping is now one lookup table; I fuzzed it against the old two-pass version on 200k strings with 0 mismatches. 7 of 8 mutants on the new escapes are killed.
Two blockers remain. Both are one-line wraps, and I missed both in round 1. The body says render and cloud render now escape the folder name, but each still prints it raw on its normal success path:
packages/cli/src/commands/render.ts:2174:printRenderCompleteprintsc.accent(outputPath)raw.- That path defaults to
<project.dir>/renders/<project.name>_<ts>.mp4(render/plan.ts:553), so every finishedhyperframes renderprints the folder name. - In the same function,
:2178printsdesktopHint(projectDir)raw. The single quotes fromshellArgdon't remove ESC;preview.ts:1357already wraps the same hint. - Fix:
c.accent(terminalText(outputPath))andc.dim(terminalText(hint)). - The
--batchlines atbatchRender.ts:368(row.outputPath) and:468(manifestPath) print the same kind of path.
- That path defaults to
packages/cli/src/commands/cloud/render.ts:900:reportUploadProgressprints${name}: N% …, and:995passes${project.name}.zip. That line prints on every non-JSON upload, right after the "Zipping" line this PR fixed. Fix:terminalText(name)at:900.
Follow-ups, not blocking (raw on base too, and not claimed in the body):
cloud/render.ts::753-754left-out warnings (the same stringspublish.ts:293now escapes):838,:845,:915and:924(project file paths in offload and dry-run output):716(font family from project CSS)
- Other commands:
render.ts:1298producer warningspublish.ts:141(candidate) and:247(priorLink.url)init.ts,feedback.ts,beats.ts,grade-compare.ts,capture/video.ts,templates.ts,figma/*,docs.ts
- No test covers the escape on
publish.ts:293; a mutant that removed it survived.
— Rames
A finished render printed its output path and the desktop app hint raw. The default output path sits under the project folder and is named after it, so the folder name reached the terminal on every render. Batch renders printed row output paths and the manifest path raw, and cloud render printed the archive name in its upload progress lines and walked file names in its left-out warnings raw. These lines now go through terminalText() or terminalLines(). --json output is unchanged.
|
Thanks, Rames. Both blockers are fixed in b46799b, with tests that fail without the fix. Blockers
Follow-ups
|
# Conflicts: # packages/cli/src/commands/cloud/render.ts
|
Merged main in 982fe45 to clear the conflict. The only conflict was in |
jrusso1020
left a comment
There was a problem hiding this comment.
Approving at 982fe455. Both round-2 blockers are resolved, and the merge from main dropped nothing.
render.ts:2228printsc.accent(terminalText(outputPath)), and the desktop hint at:2232goes throughterminalText.cloud/render.ts:925:reportUploadProgressprintsterminalText(name).batchRender.ts:369and:469: the batch row line and theManifest:line are escaped too.- Merge: main's #7995 turned
warnAndListLeftOutintoreportLeftOut, and the resolution keepsterminalLines(warning)there.
Tests: 191 of 191 pass across render, batchRender, cloud/render.terminal and publish. All 4 mutants were killed: outputPath, upload name, the batch row, and reportLeftOut. CI is green.
Non-blocking:
cloud/render.tsstill prints project file paths raw in offload and largest-file output, which the body doesn't claim to cover.- The desktop-hint and
Manifest:escapes have no test.
— Rames
miguel-heygen
left a comment
There was a problem hiding this comment.
Re-review at 982fe45. Each point from the change request at 64b97c6, checked at this head:
Blockers: all resolved
check --snapshots:check.ts:892and:897-898now print each PNG and finding-crop path throughterminalText.check.test.tsasserts the escaped path.- Background
previewstart: the failure branch now callsreportPreviewFailure(preview.ts:541-547), so the duplicate rawclack.log.error(message)is gone and thepreviewLifecycle.tsmessage containing the project path is escaped. The remaining rawclack.log.error(launchModeError)at:296prints only fixed flag-conflict text frompreviewLaunchModeError(:684-705), so it is safe. render:render/present.ts:38-40escapes both the name and the output path.render.tsandbatchRender.tsalso escape their output paths (b46799b).cloud render: "Zipping" escapes the name (cloud/render.ts:720), and so does the upload progress line (:925).open:open.ts:105escapes the name, and:99escapes the stop hint.publish:publish.ts:317and:333escape the server-sent title and URL.
Each of these has a test that asserts the escaped \x1b bytes (check.test.ts, preview.test.ts, render/present.test.ts, open.terminal.test.ts, publish.test.ts, cloud/render.terminal.test.ts, render.test.ts, batchRender.test.ts).
Important: resolved. check --prepare-media prints each failure through terminalLines (check.ts:492).
Nits: both resolved. callbackPage.ts now imports the shared escapeHtml, which gained the ' case, so the CLI has one HTML escaper. locate.mjs:79-80 also listens for SIGHUP.
Merge from main. The two conflict hunks are both in cloud/render.ts. The resolution keeps terminalText on "Zipping", and takes main's restructured staging. Main's reportLeftOut (:771-774) still prints the left-out warnings through terminalLines, so the merge drops no escaping.
CI is green at this head.
Verdict: APPROVE
# Conflicts: # skills-manifest.json # skills/hyperframes/scripts/locate.mjs # skills/hyperframes/scripts/locate.test.mjs
# Conflicts: # packages/cli/src/commands/play.ts
eddy-heygen
left a comment
There was a problem hiding this comment.
(Eddy's agent) Reviewed by Eddy's Claude agent at commit affc910.
Verdict: approved (partial: remainder stated below).
Summary. The CLI printed project folder names, paths, file names from a project, preview-server answers and cloud-service response fields straight to the terminal, so control characters in them could act on the terminal instead of being shown. This PR passes those values through the existing core escaping helper at the print sites in 17 command files, HTML-escapes the project name on the play page, merges three HTML escape helpers into one, and stops writing the absolute project path into the inspected preview page. JSON output paths are unchanged. Some print sites in the touched files are still raw and a newline in a file name can still start a new line in three places; both are gaps the default branch already has and the PR narrows, so they are non-blocking remainders.
I read the escaping helper and a sample of the changed print sites myself. The helper turns control characters into visible text and leaves tabs alone; the multi-line variant keeps line breaks and escapes each line. The print sites the PR touches pass project names, paths, preview-server answers and cloud response fields through it, and the JSON output paths are built from the unescaped values, so scripts that parse them are unaffected.
What is left, already so on the default branch and narrowed by this PR: some print sites in the same files are still raw, and a line break inside a file name can still start a new output line in a few places. Both are listed below and are worth a follow-up; neither is new.
Blockers
None.
Non-blockers
packages/cli/src/commands/cloud/render.ts:863: Several print sites in the touched files still print project- or server-controlled text raw. The PR escapes values one print site at a time, and some sites in the same files were not covered. cloud/render.ts:863 and 871-873 print a project media file path raw (describeOffload returns the path unescaped at line 970), and 976 prints the paths of the largest files raw, while the upload-progress line for the same archive is escaped. cloud/render.ts:377, 378 and 385 print the server's render id raw although delete/get/list now escape the same field. publish.ts:250 prints the stored URL of an earlier publish raw, and publish.ts:169 and 402 print caught error messages raw. batchRender.ts:388 prints a row's error message raw and 419 the manifest path raw, next to the two lines the PR did escape. A project whose media file name holds control characters therefore still reaches the terminal unescaped during a cloud render that offloads media. The default branch has the same gap at each of these lines; the PR narrows the class and does not widen it. To resolve: Wrap these values in terminalText / terminalLines as well, or escape once at the source (project resolution, cloud client response decoding, or inside the colour/print wrappers, as the error box already does) so new print sites are covered by default.packages/cli/src/commands/check.ts:492: A newline inside a file name still starts a new output line where the multi-line helper wraps a single record. terminalLines (packages/core/src/terminalText.ts:13-15) splits on newline and keeps the breaks. check.ts:492 applies it to one line built from a file name plus a reason, and cloud/render.ts:772-773 and publish.ts:314 apply it to left-out warnings that quote file names. A name that contains a newline followed by text that looks like a CLI status line is printed as its own line. Escape and other control characters are neutralised, so cursor movement, title and clipboard writes are closed; only plain extra lines remain. Before this PR these lines were fully raw. To resolve: Escape the file name with terminalText and use terminalLines only on the part that is meant to be multi-line (the reason or the fixed warning text).packages/cli/src/utils/escapeHtml.ts:1: PR description lists a skill-script change that is not in the diff. The body and test plan describe a font-path change in a skills script and a regenerated skills manifest hash. The diff against the merge base has 36 files, none under skills/; the main branch already holds its own fix for that script, so the merge from main dropped this part. A reader approving on the description would believe more is covered than the diff contains. To resolve: Remove the skills-script bullet and its test-plan line from the description.
What the change needed to do
- Project folder name and path are escaped where check, info, compositions, benchmark, play, present, preview, render, cloud render and open print them: met (packages/cli/src/commands/preview.ts:1353 and the matching one-line changes in check.ts:350, info.ts:124, compositions.ts:200-209, benchmark.ts:103, play.ts:195, present.ts:146, render/present.ts:37-40, cloud/render.ts:720, open.ts:104 all wrap the value in terminalText; a search of commands/ for raw prints of project name/dir found none left in the changed files.)
- preview --selection / --context escape label, source file, target, thumbnail URL and the server's project name: met (packages/cli/src/commands/preview.ts:1047-1053 and 1219-1226 wrap each field; failure messages go through terminalLines at 742 and 912.)
- cloud get, list and delete escape fields the server returns, including failure message, title and next-page token: met (packages/cli/src/commands/cloud/get.ts:40 and list.ts:128 deep-escape the whole response before printing; list.ts:145 escapes the token; delete.ts:82 escapes the id. JSON branches return before the escaping.)
- publish and cloud render escape server title/URL, left-out warnings and the upload progress name: partly met (publish.ts:314,317,333 and cloud/render.ts:772-773,952 are escaped, but cloud/render.ts:377-385, 863, 976 and publish.ts:250 still print server- or project-controlled text raw (see finding 1).)
- The inspected preview page no longer receives the absolute project path: met (packages/inspector/src/live.ts:51 writes only the generation id; every reader (elementMap.js:91, liveRuntime.ts:2, pageQueries.ts:57,68,92) uses only generation; service.ts:296 already wrote only generation.)
- play page HTML-escapes the project name; one shared HTML escape helper: met (packages/cli/src/commands/play.ts:317 escapes before both uses; packages/cli/src/utils/escapeHtml.ts:1-8 is byte-for-byte the helper removed from auth/callbackPage.ts and a superset of the one removed from present.ts.)
- Skill script font file kept in a private per-run folder (claimed in the PR body): not applicable (No file under skills/ is in the diff against the merge base; the main branch already carries a separate fix for that script, so this part of the PR description is stale.)
- Machine-readable output unchanged: met (cloud/get.ts:36-39, cloud/list.ts:118-123, preview.ts:741 and 909-910, cloud/render.ts:774 keep JSON built from the unescaped values; exit codes are set by the same calls as before (preview.ts:743).)
CI: 68 pass, 17 skipped, none failing or pending, including build, lint, format, both CLI test jobs, the runtime and studio tests and the required CLI smoke job.
How this was reviewed: a code-review pass and a security-review pass, by a reviewer agent in an isolated checkout of this commit; I then read the core of the fix and the cited lines myself. Nothing was built or run.
What
--status,--stop,--listand--kill-alllines, a failed background preview start, the check report path, snapshot paths and failed media lines, the finished render's output path and the batch render lines, and the warnings that quote them. The play page HTML-escapes the name.preview --selectionand--contextescape the selected element's label, source file, target and thumbnail URL, and the preview server's project name.cloud get,cloud listandcloud deleteescape the render fields the server returns, including the failure message, title and next-page token.publishescapes the title and URL the server returns.publishandcloud renderescape file names in left-out warnings, andcloud renderescapes the archive name in upload progress lines.skills/hyperframes/scripts/locate.mjscopies its grid font into a private per-run folder made with mkdtemp (mode 0700). It escapes that path for ffmpeg's filter syntax and removes the folder when the run ends or is stopped by SIGINT, SIGTERM or SIGHUP. The skills manifest hash is regenerated.Why
A folder name, a composition or a server response can carry terminal escape sequences. Printed raw, they can move the cursor, rewrite earlier lines, set the window title or write the clipboard. A composition script on an inspected preview page could read the absolute project path, which shows the account name and folder layout. A fixed font path in the shared temp folder could be created first by another account on the same machine.
Related work
Follows #7913 and #7958, which escape other CLI output with the same
terminalTexthelper from core.How
Each line that prints outside text passes it through
terminalText,terminalLinesorterminalTextDeep. The CLI's own colours are applied after escaping, so they stay.--jsonoutput is unchanged.No visible change
Ordinary names, paths and server fields print exactly as before. Only control characters now show as
\x1b-style text.Test plan
fails without the fix: the new folder-name tests in
info,compositions,check,checkArtifacts,benchmark,play,present,preview,render/presentandcloud/render.terminal.test.ts(folder name, upload progress and left-out warnings); therenderoutput-path test; thebatchRenderrow-path test; thepublishleft-out test;open.terminal.test.ts; thechecksnapshot-path and failed-media tests; thepreviewbackground-start and lint-failure tests; thepresentinvalid-island test; thepublishtitle and URL test;preview --selection and --context on a terminal;cloud/terminalOutput.test.ts;inspector/tests/liveStamp.test.ts;skills/hyperframes/scripts/locate.test.mjs.node --test skills/hyperframes/scripts/locate.test.mjspassestsc --noEmitfor cli and inspectorlint:skills, skills manifest in sync