Skip to content

fix(docs): refuse artifact paths that GitHub could read as workflow commands - #234

Merged
nickvigilante merged 4 commits into
mainfrom
vigilante/docs-1348-stop-the-publish-job-printing-artifact-derived-text-that
Oct 21, 2026
Merged

nickvigilante merged 4 commits into
mainfrom
vigilante/docs-1348-stop-the-publish-job-printing-artifact-derived-text-that

Conversation

@nickvigilante

@nickvigilante nickvigilante commented Oct 21, 2026 •

Copy link
Copy Markdown
Collaborator

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 publish job 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.mjs is the one place that reads _publish.json. It refuses the artifact unless every entry's path passes the router's hasUnsafePathSegment rule and an allowlist with no control characters (no leading, trailing or doubled slash, at most 1024 characters), and every sha256 is 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.mjs and smoke.mjs all read the index through it, and upload.mjs also checks the names of the files it finds on disk. Anything still printed from artifact data goes through describeForLog, which quotes it, replaces every character outside the path allowlist with ?, and truncates it.

upload.mjs also 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/coder docs/ 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.txt payload 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 on main and on release/2.9 through release/2.38 already 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: describeForLog now 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, verify and smoke steps should log exactly as before. The unit tests in apps/docs/scripts/publish/ show the hostile shapes being refused.

Pages to compare

What to check Production Preview
No site change https://coder.com/beta-docs/ not applicable

Testing

New tests in publish-index.test.mjs, upload.test.mjs and verify.test.mjs cover a newline in an index path, a newline in a file name on disk, a reserved root file, _redirects.json still accepted, and a poisoned index read back from the store. The three upload tests fail on the old code. All 116 tests under apps/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.json parse 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.

…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
@nickvigilante

Copy link
Copy Markdown
Collaborator Author

/coder-agents-review

@vercel

vercel Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
coder-docs Ready Ready Preview Oct 21, 2026 10:44pm UTC
1 Skipped Deployment
Project Deployment Actions Updated
coder-docs-router Ignored Ignored Preview Oct 21, 2026 10:44pm UTC

Request Review

@linear-code

linear-code Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
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 publish job prints artifact-derived paths and keys at column 0, so a crafted name injects ::error, ::add-mask, ::add-matcher or ::stop-commands (reproduced). Fix: wrap untrusted output in ::stop-commands::<random token>, or prefix and escape it, with a test that a path starting :: prints inert.

Review in Linear

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

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, "?");

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.

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 ::.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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);

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.

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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",

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.

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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");

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.

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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

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.

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in de1b7d3: the $ note is one line, and the module header is one line too.

Comment thread apps/docs/scripts/publish/upload.mjs Outdated
// 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";

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.

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in de1b7d3: upload.mjs imports VERSION_REDIRECTS_KEY from @coder/docs-manifest and the private copy is gone.

Comment thread apps/docs/scripts/publish/upload.mjs Outdated
`upload: the artifact has a file with an unsafe path: ${describeForLog(file)}`,
);
}
// The publisher writes every other underscore-prefixed root file itself.

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.

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in de1b7d3 with your wording.

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 Jesswinters 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.

Re-reviewed at de1b7d3. Approving: the blocker is fixed, and so is every other point from my last review.

  • Blocker: describeForLog now replaces every character outside the path allowlist with ?, and that allowlist is the same SAFE_PATH_CHARS that SAFE_ARTIFACT_PATH uses. So refused text can no longer contain #, [, ], :, %, a control character or a line break, and the only characters JSON.stringify adds are the outer quotes. I ran the payloads from my last review through it: ##[error]x prints 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.mjs swapped back in, the three new tests fail: the describeForLog command test, the hostile list through parsePublishIndex, and the on-disk ##[error ...] file in upload.test.mjs. They pass again with this commit's version.
  • Other items: the shared VERSION_REDIRECTS_KEY replaces the private copy, the comments are cut to one line, and the test imports are at the top with a finally cleanup.
  • Print sites: I rechecked every console.* and process.std*.write call in scripts/publish/. Nothing changed outside this diff, and the only places that print artifact text are still the three describeForLog calls.

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
@nickvigilante
nickvigilante merged commit 0d55a50 into main Oct 21, 2026
29 checks passed
@nickvigilante
nickvigilante deleted the vigilante/docs-1348-stop-the-publish-job-printing-artifact-derived-text-that branch October 21, 2026 22:45

This branch was successfully deployed

1 active and 1 inactive (outdated) deployments
Preview – coder-docs — c86e24e0 Deployed Oct 21, 2026 by vercel[bot]
Preview – coder-docs-router — de1b7d32 Deployed Oct 21, 2026 by vercel[bot]
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