Repository navigation
fix(docs): refuse artifact paths that GitHub could read as workflow commands - #234
Conversation
…ommands The secret-holding publish job printed paths and keys from the untrusted build artifact at the start of log lines, where the runner looks for workflow commands. Every _publish.json entry is now checked before use with the router's traversal rule plus an allowlist with no control characters, and an artifact that fails is refused with an error that never quotes its text. The same check covers the files found on disk, and the index is parsed with a generic error so a JSON snippet cannot leak. The uploader also refuses any underscore-prefixed root file other than _redirects.json, so an artifact cannot supply the publisher-owned _objects.json. The allowlist also admits the dollar sign, because Next names its dynamic-route payloads with it and every real export contains them. Assisted-by: AI
|
/coder-agents-review |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
1 Skipped Deployment
|
DOCS-1348 Stop the publish job printing artifact-derived text that GitHub can read as workflow commands
Low. https://github.com/coder/security-assessments/issues/383 The secret-holding |
Jesswinters
left a comment
There was a problem hiding this comment.
Not approving yet: there is one blocker, inline at publish-index.mjs:21. The path allowlist is complete. Allowing only [A-Za-z0-9._/@$-] rules out ::, ##[, %0A, CR, LF, U+2028, U+2029, U+0085 and other control characters, and no valid path can carry a workflow command. The gap is describeForLog, which prints rejected attacker text. It keeps #, [ and ], and GitHub's runner still parses the older ##[command]data syntax anywhere in a line. In actions/runner, ActionCommand.TryParse uses message.IndexOf("##["), and ActionCommandManager tries it after the :: parser fails. So the new error paths for an unsafe on-disk file (upload.mjs) and an unsafe index entry (publish-index.mjs) can still emit a forged annotation, add-mask or stop-commands.
Everything else is in good shape. All three consumers read the index through one function, files on disk are checked as well as index entries, bad entries are named by position, and JSON parse errors don't echo the input. I checked every console.* and process.std*.write call in scripts/publish/ and every run: step of the publish job; no other place prints unchecked artifact text. The $ exception holds up: a fixture test:e2e:single build produced 184 archive keys, including 28 with $, and all pass isSafeArtifactPath.
Checks I ran on 0dfe811: scripts/publish/*.test.mjs 102 of 102, apps/docs pnpm test 275 of 275, test:e2e:single passes, and oxlint and oxfmt are clean. The four new upload and verify tests fail against the old code. CI is green.
One correction to the PR body: it says the sync-side check was skipped because old release branches may have image names with spaces. I listed docs/ in coder/coder on release/2.9 through release/2.38 and on main, and found no file name outside the allowlist. If such names did exist, this publish-side check would refuse those versions anyway.
Generated by Coder Agents on behalf of @Jesswinters.
| * @param {number} [max] | ||
| */ | ||
| export function describeForLog(value, max = 80) { | ||
| const text = String(value).replace(/[^\x20-\x7e]/g, "?"); |
There was a problem hiding this comment.
Blocking: describeForLog keeps every printable ASCII character, including #, [ and ], then wraps the text in quotes. Quoting defeats ::command::, which the runner only matches at the start of a line, but not the older ##[command]data syntax, which it matches anywhere (ActionCommand.TryParse uses message.IndexOf("##[")).
To reproduce, create an artifact file named ##[error title=Publish compromised]rotate BLOB_READ_WRITE_TOKEN now and run upload.mjs. It prints Error: upload: the artifact has a file with an unsafe path: "##[error title=Publish compromised]rotate ..." to stderr, which the runner turns into an error annotation with an attacker-chosen title. An index entry with the path ##[add-mask]manifest behaves the same way. The job does fail, but forged annotations and ##[stop-commands] are exactly what this PR means to rule out.
Suggested fix: replace every character outside the path allowlist, defined once and shared with SAFE_ARTIFACT_PATH, for example String(value).replace(/[^A-Za-z0-9._\/@$ -]/g, "?"). That removes #, [, ], : and % along with control and non-ASCII characters. The module header at lines 1 to 3 should also mention more than ::.
There was a problem hiding this comment.
Fixed in de1b7d3. describeForLog now replaces every character outside the path allowlist with ?, and the allowlist is defined once (SAFE_PATH_CHARS) and used for both SAFE_ARTIFACT_PATH and the log form, so #, [, ], :, %, control characters and non-ASCII can no longer reach the log. I left out the space from your suggested class so the two sets are identical; a space prints as ?. Your ##[error title=Publish compromised]rotate ... file name now has its own upload test, and the index path case is covered in publish-index.test.mjs; both failed before the fix. The module header now names both ::cmd:: and ##[cmd].
| const hostile = "x\n::add-mask::secret\r\n::stop-commands::t\u001b[31m"; | ||
| const printed = describeForLog(hostile); | ||
| assert.doesNotMatch(printed, /[\r\n]/); | ||
| assert.equal(printed.startsWith("::"), false); |
There was a problem hiding this comment.
Should fix, together with the blocker: printed.startsWith("::") === false can never fail, because the output always starts with a quote. Test the failure mode itself instead: feed "##[error]x", "::error::x", "a\n::error::x" and "\u2028::x" through describeForLog and assert assert.doesNotMatch(printed, /##\[|::/). The first case fails on this head.
There was a problem hiding this comment.
Fixed in de1b7d3. The startsWith check is gone. The test now runs ##[add-mask]x, ##[error]x, ::error::x, a\n::error::x, CRLF, U+2028, U+2029, U+0085, %0A and an escape sequence through describeForLog and asserts the output matches none of ##[, ::, % or any line break. The same list goes through parsePublishIndex and is checked against the thrown message. Both tests failed on the old head.
|
|
||
| test("isSafeArtifactPath refuses control characters, separators tricks, and traversal", () => { | ||
| for (const key of [ | ||
| "beta-docs/\n::error title=x::y\n::stop-commands::z/index.html", |
There was a problem hiding this comment.
Nit: the allowlist is right, but this list only covers commands that follow a newline, plus é. Adding "::error::x" with no newline, "beta-docs/##[error]x", "beta-docs/a%0Ab", "beta-docs/a\u2028b" and "beta-docs/a\u0085b" would pin the guarantee the module documents.
There was a problem hiding this comment.
Added in de1b7d3: ::error::x, beta-docs/##[error]x, beta-docs/a%0Ab, beta-docs/a
b and beta-docs/a\u0005b.
| }); | ||
|
|
||
| test("readPublishIndex reads and validates a file", async () => { | ||
| const { mkdtemp, writeFile } = await import("node:fs/promises"); |
There was a problem hiding this comment.
Nit: the node:fs/promises, node:os and node:path imports are dynamic and inside the test instead of at the top of the file, and the mkdtemp directory is never removed. Move the imports up and add an rm(dir, { recursive: true, force: true }) at the end of the test.
There was a problem hiding this comment.
Fixed in de1b7d3: the imports are at the top of the file and the test removes its temporary directory in a finally.
| import { readFile } from "node:fs/promises"; | ||
| import { hasUnsafePathSegment } from "@coder/docs-manifest"; | ||
|
|
||
| // `$` is in the set because Next names its dynamic-route payloads |
There was a problem hiding this comment.
Nit: AGENTS.md asks for comments of at most one line, with the reasoning in the PR body, and the body already explains $. Something like // Next names dynamic-route payloads __next.$oc$slug.txt. is enough here. The module header at lines 1 to 3 could be cut the same way.
There was a problem hiding this comment.
Fixed in de1b7d3: the $ note is one line, and the module header is one line too.
| // prefix. That is what makes it safe to copy from on the next publish: | ||
| // `_publish.json` hashes are the untrusted build's claims. | ||
| const OBJECTS_KEY = "_objects.json"; | ||
| const REDIRECTS_FILE = "_redirects.json"; |
There was a problem hiding this comment.
Should fix: @coder/docs-manifest already exports VERSION_REDIRECTS_KEY = "_redirects.json". archive-layout.mjs writes the file with it and verify.mjs reads it back with it. AGENTS.md asks for shared constants to come from one place (#28, #44, #52), and if this copy drifts, upload would start refusing the real redirects file. Add VERSION_REDIRECTS_KEY to the existing import on line 6 instead. #228 already imports it into this file, so this also avoids two names for the same key once both land.
There was a problem hiding this comment.
Fixed in de1b7d3: upload.mjs imports VERSION_REDIRECTS_KEY from @coder/docs-manifest and the private copy is gone.
| `upload: the artifact has a file with an unsafe path: ${describeForLog(file)}`, | ||
| ); | ||
| } | ||
| // The publisher writes every other underscore-prefixed root file itself. |
There was a problem hiding this comment.
Optional: "The publisher writes every other underscore-prefixed root file itself" claims more than is true. The publisher writes only _objects.json and _publish.json, and the check refuses any root file starting with _. Something like // Underscore-prefixed root keys are reserved for the publisher. would be accurate.
describeForLog kept every printable ASCII character, so a refused path such as "##[error title=x]y" still reached the log with "##[" intact. The runner parses that legacy command syntax anywhere in a line once the "::" parser has failed, so quoting alone let an artifact forge annotations, add-mask or stop-commands through the new error messages. Every character outside the path allowlist now prints as "?", and the allowlist is defined once for both the check and the log form. The tests now assert the failure mode directly: no "##[", "::", "%" or line break of any kind in the printed text or the thrown errors. The upload check reuses VERSION_REDIRECTS_KEY from @coder/docs-manifest instead of a private copy of the name. Assisted-by: AI
Jesswinters
left a comment
There was a problem hiding this comment.
Re-reviewed at de1b7d3. Approving: the blocker is fixed, and so is every other point from my last review.
- Blocker:
describeForLognow replaces every character outside the path allowlist with?, and that allowlist is the sameSAFE_PATH_CHARSthatSAFE_ARTIFACT_PATHuses. So refused text can no longer contain#,[,],:,%, a control character or a line break, and the only charactersJSON.stringifyadds are the outer quotes. I ran the payloads from my last review through it:##[error]xprints as"???error?x",::as"??", and a NUL, a backslash, a double quote and backticks all print as?. - Fail-first: with the previous head's
publish-index.mjsswapped back in, the three new tests fail: thedescribeForLogcommand test, the hostile list throughparsePublishIndex, and the on-disk##[error ...]file inupload.test.mjs. They pass again with this commit's version. - Other items: the shared
VERSION_REDIRECTS_KEYreplaces the private copy, the comments are cut to one line, and the test imports are at the top with afinallycleanup. - Print sites: I rechecked every
console.*andprocess.std*.writecall inscripts/publish/. Nothing changed outside this diff, and the only places that print artifact text are still the threedescribeForLogcalls.
Checks I ran on de1b7d3: scripts/publish/*.test.mjs 103 of 103, apps/docs pnpm test 276 of 276, and oxlint and oxfmt clean on the changed files. CI is green (26 passed, 1 skipped).
I have no new inline comments. One trivial note on the PR body: the Testing section still says 102 tests under apps/docs/scripts/publish/, and there are now 103.
Generated by Coder Agents on behalf of @Jesswinters.
…top-the-publish-job-printing-artifact-derived-text-that # Conflicts: # apps/docs/scripts/publish/upload.mjs # apps/docs/scripts/publish/upload.test.mjs
…g it The reuse step from main logs why it skipped reuse, and for a JSON parse failure that reason was Node's own message, which quotes a snippet of the blob. The text is the store's copy of a file whose keys came from an earlier artifact, so it now reports "not valid JSON" instead, the same way _publish.json parse failures are reported. Assisted-by: AI
Merge order
Independent of the other publish hardening PRs. It touches
upload.mjs, which another open PR also edits for the redirects size cap; the changes are in different functions, and whichever merges second rebases.Summary
The
publishjob holds the write tokens and prints paths, keys and hashes taken from the build artifact at the start of log lines. GitHub Actions reads::command::lines from any step's output, so an artifact (or a corpus image filename containing a newline) could inject annotations, hide text from the log with::add-mask::, or switch command processing off with::stop-commands::. No secret is exposed, but log integrity matters more once the repository and its run logs are public. The same finding family also notes that an artifact could ship its own_objects.json, which the publisher treats as its own record.Fix
A new
publish-index.mjsis the one place that reads_publish.json. It refuses the artifact unless every entry's path passes the router'shasUnsafePathSegmentrule and an allowlist with no control characters (no leading, trailing or doubled slash, at most 1024 characters), and everysha256is 64 lowercase hex. Its errors name the entry by position and never quote the artifact's text, and a JSON parse failure is reported generically because Node's own message quotes a snippet of the input.upload.mjs,verify.mjsandsmoke.mjsall read the index through it, andupload.mjsalso checks the names of the files it finds on disk. Anything still printed from artifact data goes throughdescribeForLog, which quotes it, replaces every character outside the path allowlist with?, and truncates it.upload.mjsalso refuses any underscore-prefixed root file other than_redirects.json, so an artifact cannot supply_objects.json. Only root files are covered: the existing upload fixtures, and the layout step's own output for an unprefixed asset path, use a root_next/directory.The allowlist differs from the one suggested in the finding in one character: it also admits
$. I built the real coder/coderdocs/into the archive layout and checked every one of the 4,214 paths. The only characters outside the suggested set were the$in Next's__next.$oc$slug.txtpayload files (952 paths), so the suggested set would have failed every real publish.$has no meaning to the workflow command parser.Not done: a matching check on the sync side. Every file name under
docs/in coder/coder onmainand onrelease/2.9throughrelease/2.38already fits the allowlist, so it would refuse nothing today, and the publish-side check fails closed on any version that ever carries one.Review feedback applied in de1b7d3:
describeForLognow prints every character outside the path allowlist as?, so refused text can form neither a::cmd::nor a legacy##[cmd]workflow command.QA
There is nothing to see on the site. A publish run's
upload,verifyandsmokesteps should log exactly as before. The unit tests inapps/docs/scripts/publish/show the hostile shapes being refused.Pages to compare
Testing
New tests in
publish-index.test.mjs,upload.test.mjsandverify.test.mjscover a newline in an index path, a newline in a file name on disk, a reserved root file,_redirects.jsonstill accepted, and a poisoned index read back from the store. The three upload tests fail on the old code. All 116 tests underapps/docs/scripts/publish/pass, and oxfmt and oxlint are clean on the changed files. Main merged in 891bf9e. After the merge, c86e24e also stops the "nothing to reuse" warning from quoting Node's JSON parse error, which echoed a snippet of the recorded_objects.json; it now says only "not valid JSON", like_publish.jsonparse failures.Upstream
No. This is Coder-specific publish tooling.
Linear: https://linear.app/codercom/issue/DOCS-1348/stop-the-publish-job-printing-artifact-derived-text-that-github-can. Findings: coder/security-assessments#383 and the publish section of coder/security-assessments#386.
🤖 Built with AI assistance.