From 85238a982027d790879fec079d196c69e73cbed5 Mon Sep 17 00:00:00 2001 From: Nick Vigilante Date: Tue, 15 Sep 2026 11:48:08 -0400 Subject: [PATCH 1/8] ci: add CodeQL and OSV-Scanner workflows Mirror coder/coder's security workflow shape for this TypeScript/pnpm monorepo: CodeQL for javascript-typescript and OSV-Scanner against pnpm-lock.yaml, both uploading SARIF to the Security tab, pinned to full commit SHAs, on push/PR/weekly schedule/dispatch. Assisted-by: AI --- .github/workflows/security.yaml | 107 ++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 .github/workflows/security.yaml diff --git a/.github/workflows/security.yaml b/.github/workflows/security.yaml new file mode 100644 index 00000000..100b5ac0 --- /dev/null +++ b/.github/workflows/security.yaml @@ -0,0 +1,107 @@ +name: security + +# CodeQL and OSV-Scanner, mirroring coder/coder's security workflow shape for +# a TypeScript/pnpm monorepo instead of a Go binary. Every job is read-only +# except for the SARIF upload step it needs security-events: write for. + +on: + push: + branches: [main] + pull_request: + schedule: + # Weekly, off the standard push/PR path, so a dependency-only advisory + # still gets caught even when nobody touches the repo that week. + - cron: "0 6 * * 1" + workflow_dispatch: + +permissions: + contents: read + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: ${{ github.event_name == 'pull_request' }} + +jobs: + codeql: + name: CodeQL (javascript-typescript) + runs-on: ubuntu-latest + timeout-minutes: 15 + permissions: + contents: read + security-events: write + steps: + - name: Harden Runner + uses: step-security/harden-runner@e14015d583714f6e62063499dc959a02595150a1 # v2.21.1 + with: + egress-policy: audit + + - name: Checkout + uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4 + + - name: Initialize CodeQL + uses: github/codeql-action/init@4bd7200e1f146b1c937cae12d258b50f41a53cf8 # v4.38.0 + with: + languages: javascript-typescript + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@4bd7200e1f146b1c937cae12d258b50f41a53cf8 # v4.38.0 + + osv-scanner: + name: OSV-Scanner (pnpm-lock.yaml) + runs-on: ubuntu-latest + timeout-minutes: 15 + permissions: + contents: read + security-events: write + actions: read + env: + OSV_SCANNER_VERSION: v2.6.0 + steps: + - name: Harden Runner + uses: step-security/harden-runner@e14015d583714f6e62063499dc959a02595150a1 # v2.21.1 + with: + egress-policy: audit + + - name: Checkout + uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4 + + - name: Install OSV-Scanner + run: | + set -euo pipefail + curl -fsSL -o /usr/local/bin/osv-scanner \ + "https://github.com/google/osv-scanner/releases/download/${OSV_SCANNER_VERSION}/osv-scanner_linux_amd64" + chmod +x /usr/local/bin/osv-scanner + + - name: Run OSV-Scanner against pnpm-lock.yaml + id: scan + run: | + set -euo pipefail + set +e + osv-scanner scan source \ + --lockfile=pnpm-lock.yaml \ + --format sarif \ + --output osv-results.sarif + scan_exit_code=$? + set -e + + echo "exit_code=${scan_exit_code}" >> "${GITHUB_OUTPUT}" + + if [[ "${scan_exit_code}" -eq 0 ]]; then + exit 0 + fi + + if [[ "${scan_exit_code}" -eq 1 ]]; then + echo "OSV-Scanner found vulnerabilities in pnpm-lock.yaml." + echo "Results will be uploaded to GitHub Security." + exit 0 + fi + + echo "::error::OSV-Scanner failed with exit code ${scan_exit_code}" + exit "${scan_exit_code}" + + - name: Upload OSV-Scanner scan results to GitHub Security tab + if: ${{ always() && hashFiles('osv-results.sarif') != '' }} + uses: github/codeql-action/upload-sarif@4bd7200e1f146b1c937cae12d258b50f41a53cf8 # v4.38.0 + with: + sarif_file: osv-results.sarif + category: "OSV-Scanner" From 71c8c4d9c2a2654eaea7db24bb4e8befade0f488 Mon Sep 17 00:00:00 2001 From: Nick Vigilante Date: Tue, 15 Sep 2026 11:48:12 -0400 Subject: [PATCH 2/8] chore: add Renovate config with vulnerability alerts and pnpm catalog support Extend config:recommended, enable vulnerabilityAlerts and osvVulnerabilityAlerts, pin GitHub Actions to digests, pick up pnpm-workspace.yaml catalog entries via the npm manager, group fumadocs-* packages, and pin ranges rather than leaving them floating. Assisted-by: AI --- renovate.json | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 renovate.json diff --git a/renovate.json b/renovate.json new file mode 100644 index 00000000..296543de --- /dev/null +++ b/renovate.json @@ -0,0 +1,19 @@ +{ + "$schema": "https://docs.renovatebot.com/renovate-schema.json", + "extends": ["config:recommended", "helpers:pinGitHubActionDigests"], + "vulnerabilityAlerts": { + "enabled": true + }, + "osvVulnerabilityAlerts": true, + "schedule": ["before 6am on monday"], + "rangeStrategy": "pin", + "npm": { + "fileMatch": ["(^|/)package\\.json$", "(^|/)pnpm-workspace\\.yaml$"] + }, + "packageRules": [ + { + "groupName": "fumadocs", + "matchPackageNames": ["fumadocs-*"] + } + ] +} From 65da5c6c1f93ff536f3c25c38bbe40890341608d Mon Sep 17 00:00:00 2001 From: Nick Vigilante Date: Tue, 15 Sep 2026 11:48:17 -0400 Subject: [PATCH 3/8] chore: add CODEOWNERS with stricter rules on the sanitizer boundary Default ownership on everything, plus explicit owners on the mdx-config/sanitizer/sync files that gate untrusted corpus content and on the workflows directory, since those are the files where a mistake has the highest blast radius. Individuals stand in for a team handle that doesn't exist yet. Assisted-by: AI --- .github/CODEOWNERS | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 .github/CODEOWNERS diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 00000000..96f758a9 --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1,22 @@ +# Code owners for coder/docs-engine. +# +# Individuals are listed by GitHub handle (@nickvigilante = Nick Vigilante, +# @bpmct = Ben Potter) because no team handle exists for this repository yet. +# Replace these individual owners with a team handle (e.g. @coder/docs-engine) +# once one is created, so review load does not sit on two people. + +# Default owners for everything in the repo, unless a later, more specific +# rule below overrides it. +* @nickvigilante @bpmct + +# The sanitizer boundary: the plugins and config that keep untrusted +# corpus-authored Markdown/HTML from producing script execution or DOM +# clobbering in the prerendered static export, and the sync step that gates +# which file extensions ever reach that pipeline. +packages/docs-transforms/src/mdx-config.ts @nickvigilante @bpmct +packages/docs-transforms/src/mdx-plugins/rehype-sanitize-coder-docs.ts @nickvigilante @bpmct +packages/docs-transforms/src/mdx-plugins/html-delimiters.ts @nickvigilante @bpmct +packages/docs-build/src/sync.ts @nickvigilante @bpmct + +# CI/CD and security workflows. +.github/workflows/ @nickvigilante @bpmct From 279608f828739b2a96580e3cf8c7467e674c56df Mon Sep 17 00:00:00 2001 From: Nick Vigilante Date: Tue, 15 Sep 2026 11:48:22 -0400 Subject: [PATCH 4/8] docs(workflows): explain the Depot vs ubuntu-latest runner rule One sentence per header comment: Depot (depot-ubuntu-22.04-4) runs only the jobs that compile content and need 16 GB of memory, and everything else runs on ubuntu-latest since it needs no memory and Depot is metered. Comments only, no behavior change. Assisted-by: AI --- .github/workflows/backfill-versions.yml | 4 ++++ .github/workflows/docs-pr-preview.yml | 3 +++ .github/workflows/publish-version.yml | 4 ++++ .github/workflows/reconcile-versions.yml | 3 +++ .github/workflows/republish-lines.yml | 4 ++++ 5 files changed, 18 insertions(+) diff --git a/.github/workflows/backfill-versions.yml b/.github/workflows/backfill-versions.yml index 23eda224..d60215d5 100644 --- a/.github/workflows/backfill-versions.yml +++ b/.github/workflows/backfill-versions.yml @@ -4,6 +4,10 @@ # GitHub caps a matrix at 256 jobs; run the tags in two chunks, split by # minor-version parity (Y % 2 of vX.Y.Z) rather than list position, so a tag # cut between the two dispatches never shifts which chunk any tag belongs to. +# +# Runner choice: this workflow only dispatches publish-version runs (which do +# the actual compiling on Depot), so it runs on `ubuntu-latest` itself rather +# than metered Depot capacity. name: backfill-versions on: diff --git a/.github/workflows/docs-pr-preview.yml b/.github/workflows/docs-pr-preview.yml index 17bf2565..9cf468b1 100644 --- a/.github/workflows/docs-pr-preview.yml +++ b/.github/workflows/docs-pr-preview.yml @@ -16,6 +16,9 @@ # The job's first step validates content_repository, content_ref, and # pr_number before any other step checks out, builds, deploys, or calls an # API with them. +# +# Runner choice: this job compiles content and needs 16 GB of memory, so it +# runs on Depot (`depot-ubuntu-22.04-4`) rather than `ubuntu-latest`. name: docs-pr-preview on: diff --git a/.github/workflows/publish-version.yml b/.github/workflows/publish-version.yml index 3c4c0411..a3289e06 100644 --- a/.github/workflows/publish-version.yml +++ b/.github/workflows/publish-version.yml @@ -27,6 +27,10 @@ # ref+commit and every upload allows overwrite, so retrying either job after # any failure is safe; "a tag is published once" is enforced solely by the # tag-exists check, never by refusing to overwrite an archive object. +# Runner choice: `build` compiles content and needs 16 GB of memory, so it +# runs on Depot (`depot-ubuntu-22.04-4`); `publish` needs neither, so it runs +# on `ubuntu-latest` rather than metered Depot capacity. +# # The same concurrency group cancels an older run of the same ref when a # newer push arrives; if that lands between the manifest write and the # mirror or cleanup steps, /versions.json stays stale until the next publish diff --git a/.github/workflows/reconcile-versions.yml b/.github/workflows/reconcile-versions.yml index 3b8630d3..9ed20349 100644 --- a/.github/workflows/reconcile-versions.yml +++ b/.github/workflows/reconcile-versions.yml @@ -10,6 +10,9 @@ # on this repository (`gh label create docs-archive-drift`) before the first # run that needs to open an issue — `gh issue create --label` does not create # a missing label, it fails the step. +# +# Runner choice: this job only compares manifest state, no compiling and no +# memory need, so it runs on `ubuntu-latest` rather than metered Depot capacity. name: reconcile-versions on: diff --git a/.github/workflows/republish-lines.yml b/.github/workflows/republish-lines.yml index d1254bcb..561c099d 100644 --- a/.github/workflows/republish-lines.yml +++ b/.github/workflows/republish-lines.yml @@ -11,6 +11,10 @@ # still links to them. The manifest's `engine` and `publishedAt` for the tag # are updated to the new build. archivePrefix, cleanup.mjs, and upload.mjs # are unchanged by this path. +# +# Runner choice: this workflow only dispatches publish-version runs (which do +# the actual compiling on Depot), so it runs on `ubuntu-latest` itself rather +# than metered Depot capacity. name: republish-lines on: From 2074731a14eed0e1e86b0337bbfff56807ade209 Mon Sep 17 00:00:00 2001 From: Nick Vigilante Date: Tue, 15 Sep 2026 11:48:28 -0400 Subject: [PATCH 5/8] test(docs-transforms): cover every sanitizer passthrough type MDX_PASSTHROUGH_TYPES lists five node kinds the sanitizer must let through untouched (mdxjsEsm, mdxFlowExpression, mdxTextExpression, mdxJsxFlowElement, mdxJsxTextElement); only two of the five had direct coverage. Add one pair of tests per type: an engine-generated node of that type survives verbatim, and a corpus-authored raw-HTML lookalike carrying a dangerous attribute (onclick, style, javascript:) is sanitized as ordinary raw HTML rather than treated as passthrough. Assisted-by: AI --- .../rehype-sanitize-coder-docs.test.ts | 106 ++++++++++++++++++ 1 file changed, 106 insertions(+) diff --git a/packages/docs-transforms/src/mdx-plugins/rehype-sanitize-coder-docs.test.ts b/packages/docs-transforms/src/mdx-plugins/rehype-sanitize-coder-docs.test.ts index 2c2e3659..f5c686a5 100644 --- a/packages/docs-transforms/src/mdx-plugins/rehype-sanitize-coder-docs.test.ts +++ b/packages/docs-transforms/src/mdx-plugins/rehype-sanitize-coder-docs.test.ts @@ -441,6 +441,112 @@ test("sanitizes attacker attributes on raw HTML nested in a Callout", () => { assert.equal((img.properties as Record).onError, undefined); }); +// --- One pair of tests per passthrough type -------------------------------- +// `MDX_PASSTHROUGH_TYPES` lists five mdast/hast node kinds that only ever +// originate from this codebase's own remark/MDX pipeline (mdxjsEsm and +// mdxJsxFlowElement are exercised above through realistic Tabs/Callout +// trees). For each type: (a) an engine-generated node of that exact `type` +// survives the sanitize pass verbatim, and (b) a corpus-authored raw-HTML +// lookalike — a node `rehype-raw` could actually produce from `.md` source, +// carrying a classic dangerous attribute — is never treated as that +// passthrough type and gets sanitized like any other raw element. Per the +// module's PRECONDITION comment, raw HTML reparsed by `rehype-raw` can only +// ever become plain `element`/`text`/`comment` nodes, never a real mdast/mdx +// node `type` — so the lookalike case is what an attacker gets by naming a +// tag/attribute after the construct, not by forging the node's `type`. + +test("mdxjsEsm: an engine-generated ESM node survives with its value untouched", () => { + const esm: HastNode = { type: "mdxjsEsm", value: "export const toc = []", children: [] } as HastNode; + const tree: HastNode = { type: "root", children: [esm] }; + rehypeSanitizeCoderDocs()(tree); + assert.deepEqual(tree.children, [esm]); +}); + +test("mdxjsEsm: a raw HTML lookalike (a "); + assert.doesNotMatch(out, /\n"); assert.doesNotMatch(out, /alert\(1\)/); diff --git a/packages/docs-transforms/src/mdx-plugins/rehype-sanitize-coder-docs.test.ts b/packages/docs-transforms/src/mdx-plugins/rehype-sanitize-coder-docs.test.ts index 18d84ac7..3617af95 100644 --- a/packages/docs-transforms/src/mdx-plugins/rehype-sanitize-coder-docs.test.ts +++ b/packages/docs-transforms/src/mdx-plugins/rehype-sanitize-coder-docs.test.ts @@ -4,6 +4,7 @@ import { raw } from "hast-util-raw"; import { toHtml } from "hast-util-to-html"; import { defaultSchema } from "hast-util-sanitize"; import { + MDX_PASSTHROUGH_TYPES, coderSanitizeSchema, rehypeProtectTrustedIds, rehypeRestoreTrustedIds, @@ -143,7 +144,8 @@ test("strips data-fd-step from non-heading elements (raw HTML cannot forge steps }); test("admits the gating marker attributes on every element (fail closed)", () => { - // The gating markers (decision: DOCS-768) must survive sanitize so the theme's + // The gating markers (a deliberate decision, recorded in the tracker) must + // survive sanitize so the theme's // fail-closed rule (`[data-cond],[data-feature]{display:none}`) can hide any // marker the remark plugin did not rewrite. Stripping the attribute from a // non-div element would keep the content but lose the marker — gating would @@ -268,6 +270,14 @@ function collectTags(node: HastNode, acc: string[] = []): string[] { return acc; } +function collectTypes(node: HastNode, acc: string[] = []): string[] { + if (typeof node.type === "string") acc.push(node.type); + if (Array.isArray(node.children)) { + for (const child of node.children) collectTypes(child, acc); + } + return acc; +} + test("preserves MDX components while sanitizing raw HTML nested inside them", () => { const tabsAttributes = [{ type: "mdxJsxAttribute", name: "items", value: "UI" }]; const tree: HastNode = { @@ -441,6 +451,60 @@ test("sanitizes attacker attributes on raw HTML nested in a Callout", () => { assert.equal((img.properties as Record).onError, undefined); }); +// --- The precondition the passthrough list rests on ------------------------ + +test("corpus raw HTML cannot become any node type the sanitizer waves through", () => { + // The module's PRECONDITION is the reason `MDX_PASSTHROUGH_TYPES` is safe to + // skip the schema at all: in `.md` mode, HTML reparsed by `rehype-raw` can + // only ever become plain element/text/comment nodes, so a node carrying one + // of those five types must have come from our own remark plugins. Every + // other test here trusts that claim; this one checks it, against input + // written specifically to manufacture each type by name — a tag named after + // the node type, MDX expression and component syntax, an ESM statement, and + // the plugin's own marker element. + // + // If this ever fails, the passthrough allowlist is handing attacker-authored + // nodes straight past the schema and nothing downstream will notice. + const hostile = [ + "export const toc = []", + "{alert(1)}", + "{alert(1)}", + "x", + "x", + "", + "export const toc = [{ depth: 1 }]", + "{alert(1)}", + "
{alert(1)}
", + 'x', + "", + ].join("\n"); + + const reparsed = raw({ + type: "root", + children: [{ type: "raw", value: hostile }], + }) as unknown as HastNode; + + // Before sanitizing: whatever `rehype-raw` made of that input, none of it + // may be a passthrough type. Checking pre-sanitize is the stricter + // assertion — post-sanitize the marker walk has already run. + const produced = new Set(collectTypes(reparsed)); + for (const passthrough of MDX_PASSTHROUGH_TYPES) { + assert.equal( + produced.has(passthrough), + false, + `rehype-raw produced a ${passthrough} node from corpus HTML, so the passthrough allowlist no longer describes only engine output`, + ); + } + assert.deepEqual([...produced].sort(), ["element", "root", "text"]); + + // And the payloads themselves are gone or inert after the pass. + rehypeSanitizeCoderDocs()(reparsed); + const html = toHtml(reparsed as never); + assert.doesNotMatch(html, /