diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS
new file mode 100644
index 00000000..6673ed63
--- /dev/null
+++ b/.github/CODEOWNERS
@@ -0,0 +1,31 @@
+# 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.
+#
+# These rules name the same two owners as the `*` default above, so today
+# they are documentary, not an added requirement — they exist to name the
+# boundary and to make code-owner review meaningful here the moment it's
+# turned on (the `main` ruleset's "require code owner review" setting). Once a security-focused team
+# handle exists, add it here as an additional owner alongside (or instead
+# of) the individuals, so these specific paths get a narrower, genuinely
+# stricter reviewer set than the rest of the repo.
+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. Same "documentary until a team handle
+# exists" caveat as above.
+.github/workflows/ @nickvigilante @bpmct
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:
diff --git a/.github/workflows/security.yml b/.github/workflows/security.yml
new file mode 100644
index 00000000..b5458821
--- /dev/null
+++ b/.github/workflows/security.yml
@@ -0,0 +1,197 @@
+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 steps, which need security-events: write.
+#
+# GitHub Code Security (GHAS) is not yet enabled on this private repository,
+# and both jobs' SARIF uploads 403 against a repo without it — a permanently
+# failing check trains reviewers to ignore it. So the codeql job, and the
+# upload-sarif step in osv-scanner, are gated behind the
+# vars.CODE_SCANNING_ENABLED repository variable. Until an admin enables Code
+# Security for this repository (Settings → Code security) and then creates
+# the repository variable CODE_SCANNING_ENABLED with the value "true",
+# codeql does not run at all, and osv-scanner still runs and still uploads
+# its SARIF as a plain workflow artifact so the results are not lost.
+#
+# While that gate is closed the osv-scanner job announces it on every run, in
+# the log and in the job summary: a skipped scanner that says nothing is
+# indistinguishable from a scanner that found nothing.
+#
+# OSV findings do not fail this workflow. A transitive advisory with no
+# available fix would otherwise block every unrelated pull request, and the
+# archive serves prerendered static files rather than running this dependency
+# tree in production. Findings are surfaced instead — job summary, warning
+# annotations, and the Security tab once the gate above is open — so the
+# signal is visible without being a merge gate. A scanner that fails to run,
+# by contrast, does fail the job: "found nothing" and "could not look" must
+# not report the same way.
+
+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)
+ # See the header comment: skipped until GitHub Code Security is enabled
+ # for this repository and vars.CODE_SCANNING_ENABLED is set to "true".
+ if: vars.CODE_SCANNING_ENABLED == 'true'
+ runs-on: ubuntu-latest
+ timeout-minutes: 15
+ permissions:
+ contents: read
+ security-events: write
+ actions: read
+ steps:
+ - name: Harden Runner
+ uses: step-security/harden-runner@e14015d583714f6e62063499dc959a02595150a1 # v2.21.1
+ with:
+ egress-policy: audit
+
+ - name: Checkout
+ uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
+ with:
+ persist-credentials: false
+
+ - name: Initialize CodeQL
+ uses: github/codeql-action/init@b96794f015dfd88f77b49b1c93e0fa7110f94c63 # v4.38.0
+ with:
+ languages: javascript-typescript
+
+ - name: Perform CodeQL Analysis
+ uses: github/codeql-action/analyze@b96794f015dfd88f77b49b1c93e0fa7110f94c63 # 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
+ steps:
+ - name: Harden Runner
+ uses: step-security/harden-runner@e14015d583714f6e62063499dc959a02595150a1 # v2.21.1
+ with:
+ egress-policy: audit
+
+ # Every run says whether code scanning is actually wired up. Without
+ # this the gate is invisible: the codeql job reports as skipped, the
+ # Security tab stays empty, and nothing distinguishes that from a clean
+ # scan.
+ - name: Report the code-scanning gate
+ if: ${{ vars.CODE_SCANNING_ENABLED != 'true' }}
+ run: |
+ set -euo pipefail
+ note="GitHub Code Security is not enabled for this repository: CodeQL is skipped and OSV-Scanner results are not uploaded to the Security tab. Enable Code Security (Settings → Code security), then set the repository variable CODE_SCANNING_ENABLED=true."
+ echo "::warning::${note}"
+ {
+ echo "### Code scanning is partially disabled"
+ echo
+ echo "${note}"
+ echo
+ echo "OSV-Scanner still ran; its SARIF is attached to this run as the \`osv-scanner\` artifact."
+ } >> "$GITHUB_STEP_SUMMARY"
+
+ - name: Checkout
+ uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
+ with:
+ persist-credentials: false
+
+ - name: Run OSV-Scanner against pnpm-lock.yaml
+ id: scan
+ continue-on-error: true
+ uses: google/osv-scanner-action/osv-scanner-action@a345acffa64b0eaede81a3d9aae6141214d9c8fc # v2.6.0
+ with:
+ scan-args: |-
+ --lockfile=pnpm-lock.yaml
+ --format=sarif
+ --output-file=osv-results.sarif
+
+ # Findings are reported, not fatal (see the header). What IS fatal is a
+ # scanner that did not produce a result set: OSV-Scanner exits non-zero
+ # both when it finds vulnerabilities and when it fails, so the two are
+ # told apart by the SARIF it leaves behind rather than by the exit code
+ # alone.
+ - name: Summarize OSV-Scanner results
+ if: always()
+ env:
+ # Read through the environment rather than interpolated into the
+ # script body: `outcome` is a fixed enum today, but a `${{ }}`
+ # expansion inside `run:` is the shape of a shell-injection bug and
+ # should not be the pattern this repo copies from.
+ SCAN_OUTCOME: ${{ steps.scan.outcome }}
+ run: |
+ set -euo pipefail
+
+ if [[ ! -f osv-results.sarif ]]; then
+ if [[ "${SCAN_OUTCOME}" == "success" ]]; then
+ echo "OSV-Scanner reported no vulnerabilities in \`pnpm-lock.yaml\`." >> "$GITHUB_STEP_SUMMARY"
+ exit 0
+ fi
+ echo "::error::OSV-Scanner did not produce a SARIF file (outcome: ${SCAN_OUTCOME}); the lockfile was not scanned"
+ exit 1
+ fi
+
+ findings="$(jq '[.runs[]?.results[]?] | length' osv-results.sarif)"
+
+ if [[ "${findings}" -eq 0 ]]; then
+ if [[ "${SCAN_OUTCOME}" != "success" ]]; then
+ echo "::error::OSV-Scanner exited unsuccessfully with an empty result set; treating that as a failed scan rather than a clean one"
+ exit 1
+ fi
+ echo "OSV-Scanner found no known vulnerabilities in \`pnpm-lock.yaml\`." >> "$GITHUB_STEP_SUMMARY"
+ exit 0
+ fi
+
+ jq -r '.runs[]?.results[]? | "\(.ruleId // "unknown")\t\((.message.text // "no detail") | split("\n")[0])"' \
+ osv-results.sarif > findings.tsv
+
+ {
+ echo "### OSV-Scanner: ${findings} finding(s) in \`pnpm-lock.yaml\`"
+ echo
+ echo "Reported, not blocking. Review each advisory and bump the dependency, or record why it does not apply."
+ echo
+ echo "| Advisory | Detail |"
+ echo "| --- | --- |"
+ while IFS=$'\t' read -r rule detail; do
+ printf '| %s | %s |\n' "${rule}" "${detail}"
+ done < findings.tsv
+ } >> "$GITHUB_STEP_SUMMARY"
+
+ while IFS=$'\t' read -r rule detail; do
+ echo "::warning title=OSV-Scanner ${rule}::${detail}"
+ done < findings.tsv
+
+ # Always uploaded, independent of GitHub Code Security, so results are
+ # never lost while vars.CODE_SCANNING_ENABLED is unset.
+ - name: Upload OSV-Scanner scan results as an artifact
+ if: ${{ always() && hashFiles('osv-results.sarif') != '' }}
+ uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
+ with:
+ name: osv-scanner
+ path: osv-results.sarif
+ retention-days: 30
+
+ # See the header comment: skipped until GitHub Code Security is enabled
+ # for this repository and vars.CODE_SCANNING_ENABLED is set to "true".
+ - name: Upload OSV-Scanner scan results to GitHub Security tab
+ if: ${{ always() && hashFiles('osv-results.sarif') != '' && vars.CODE_SCANNING_ENABLED == 'true' }}
+ uses: github/codeql-action/upload-sarif@b96794f015dfd88f77b49b1c93e0fa7110f94c63 # v4.38.0
+ with:
+ sarif_file: osv-results.sarif
+ category: "OSV-Scanner"
diff --git a/packages/docs-transforms/src/mdx-config.e2e.test.ts b/packages/docs-transforms/src/mdx-config.e2e.test.ts
index 766463be..62a15b66 100644
--- a/packages/docs-transforms/src/mdx-config.e2e.test.ts
+++ b/packages/docs-transforms/src/mdx-config.e2e.test.ts
@@ -92,6 +92,43 @@ function collectText(node: unknown, skipType?: string): string {
return collectText(node.props.children, skipType);
}
+test("e2e: the corpus cannot author an MDX expression, component, or ESM statement", async () => {
+ // The sanitizer's passthrough allowlist is only safe because the corpus
+ // compiles as `.md`: expression and JSX node types reaching the sanitizer
+ // can then only have come from the engine's own remark plugins. This pins
+ // the `format: "md"` half of that (the reparse half is pinned in
+ // rehype-sanitize-coder-docs.test.ts) by feeding the compiler the three
+ // constructs that would each produce a passthrough node in `.mdx`.
+ //
+ // If any of them were evaluated, `run()` below would throw a ReferenceError
+ // on `alert` rather than returning a tree — so reaching the assertions at
+ // all is part of what this test proves.
+ const tree = await renderMd(
+ [
+ "export const toc = [{ depth: 1, title: 'injected' }]",
+ "",
+ "inline {alert(1)} expression",
+ "",
+ "{alert(2)}",
+ "",
+ 'framed',
+ "",
+ ].join("\n"),
+ );
+
+ const rendered = collectText(tree);
+ // Braces survive as literal text: they were never an expression.
+ assert.match(rendered, /\{alert\(1\)\}/);
+ assert.match(rendered, /\{alert\(2\)\}/);
+ assert.match(rendered, /export const toc/);
+
+ // The component-shaped raw HTML did not become a real Callout, so nothing
+ // carried its attacker attribute into a component's props.
+ assert.deepEqual(findAll(tree, "Callout"), []);
+ assert.match(rendered, /framed/);
+ assert.doesNotMatch(JSON.stringify(tree), /onClick/i);
+});
+
test("e2e: raw \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 2c2e3659..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,189 @@ 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, /");
+ assert.doesNotMatch(out, /