From 656e9baffccd28f2279278ef4311a96c3b01ad35 Mon Sep 17 00:00:00 2001 From: Nick Vigilante Date: Wed, 21 Oct 2026 14:23:17 -0700 Subject: [PATCH] docs(security): bootstrap the .security threat model the security review gates against The Coder Agents security review skips its model-backed gate on every PR here because the repository has no .security/ model at the base ref, so its invariant checks and probes never run. This adds that model in the layout the Security team's threat-model-persistent and quick-pr-review-model skills define: threat-model.md for the argument (assets, actors, trust boundaries, attacker stories, severity calibration) and boundaries.yaml for the lookup the reviewer parses (eight boundaries with invariants, enforcing code, tests, review focus and known failures; seven assets with reachability probes; nine surface probes). It is built from ARCHITECTURE.md, AGENTS.md, the publisher and router READMEs, the workflows as they stand at this commit, and the two security assessments and their findings, recording each fixed failure and each open gap on the boundary it belongs to. Every probe was run against this commit and returns a non-empty or intentionally empty set. reviewed_by stays null, so the gate stays advisory until Security signs it off. .security/ joins CODEOWNERS because narrowing the model is the edit that most weakens future reviews. Assisted-by: AI --- .github/CODEOWNERS | 4 + .security/boundaries.yaml | 652 ++++++++++++++++++++++++++++++++++++++ .security/threat-model.md | 196 ++++++++++++ 3 files changed, 852 insertions(+) create mode 100644 .security/boundaries.yaml create mode 100644 .security/threat-model.md diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 6673ed63..17410b51 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -29,3 +29,7 @@ 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 + +# The threat model the security review gates PRs against. Narrowing it +# (removing a boundary, probe or path, relaxing an invariant) needs Security. +.security/ @nickvigilante @bpmct diff --git a/.security/boundaries.yaml b/.security/boundaries.yaml new file mode 100644 index 00000000..9bc36e93 --- /dev/null +++ b/.security/boundaries.yaml @@ -0,0 +1,652 @@ +version: 1 +repo: coder/docs-engine +model_path: .security/threat-model.md +model_revision: 843d38f7fa7cb16a6a0b4dd38817a16d001ad48a +reviewed_by: null +reviewed_on: null + +boundaries: + - id: corpus-render + summary: > + Markdown and raw HTML from coder/coder docs/ (any contributor whose PR merges) is + compiled into pages served on the coder.com origin and, later, inside the + authenticated Coder dashboard. The sanitizer is the primary defense; the CSP allows + 'unsafe-inline' and is only a second line. + invariant: > + Corpus content reaches a browser only as the output of rehypeSanitizeCoderDocs + (run immediately after rehype-raw, with coderSanitizeSchema) or as plain text with a + pinned non-HTML content type and nosniff. The sync emits only .md files, never .mdx, + so no corpus JSX or expression is ever evaluated. No corpus-derived string is passed + to dangerouslySetInnerHTML, innerHTML, allowDangerousHtml or a second rehype-raw. + Link hrefs pass the scheme check before rendering as an anchor. + enforced_by: + - packages/docs-transforms/src/mdx-plugins/rehype-sanitize-coder-docs.ts:102 + - packages/docs-transforms/src/mdx-plugins/rehype-sanitize-coder-docs.ts:265 + - packages/docs-transforms/src/mdx-config.ts:146 + - packages/docs-build/src/sync.ts:537 + - packages/docs-ui/src/mdx.tsx:171 + - packages/docs-ui/src/mdx.tsx:186 + - apps/docs/scripts/archive-layout-helpers.mjs:249 + tests: + - packages/docs-transforms/src/mdx-plugins/rehype-sanitize-coder-docs.test.ts + - packages/docs-ui/src/mdx.test.tsx + - packages/docs-transforms/src/processed-markdown.test.ts + paths: + - packages/docs-transforms/src/** + - packages/docs-build/src/** + - packages/docs-sources/src/** + - packages/docs-ui/src/** + - packages/docs-next/src/** + - packages/docs-config/src/** + - apps/docs/app/** + - apps/docs/lib/** + - apps/docs/source.config.ts + - apps/offlinedocs/app/** + - apps/offlinedocs/source.config.ts + - apps/docs/scripts/archive-layout*.mjs + review_focus: + - A new remark or rehype plugin placed after rehypeSanitizeCoderDocs that turns text or attributes into elements, or one placed before it that emits a node type outside MDX_PASSTHROUGH_TYPES which the sanitizer then trusts. + - An attribute, tag or protocol added to coderSanitizeSchema, or a MDX_PASSTHROUGH_TYPES entry added without an attribute-level test that shows a payload being stripped. + - Any path in sync.ts or read-tree.ts that writes a .mdx file, follows a symlink, or copies a file whose name is not a safe path segment. + - A new render path (component, OG image, RSS, feed, metadata) that receives corpus text and renders it as HTML instead of React text. + - A fumadocs default plugin left on that lets fence meta or frontmatter pick DOM ids, storage keys or class names. + - A content type for a .md, .txt or .svg object that is no longer pinned in contentTypeFor or the router's header map. + known_failures: + - "Raw corpus HTML rendered unsanitized before the sanitizer existed; fixed by adding rehypeSanitizeCoderDocs after rehype-raw (#28)." + - "fumadocs' code-tab plugin (remarkCodeTab) stays enabled, so fence meta tab-group/tab writes arbitrary localStorage/sessionStorage keys on the serving origin, including next-themes' theme key; open." + - "fumadocs customId emits author-chosen heading ids without the user-content- prefix; open." + severity_floor: high + + - id: search-client-sinks + summary: > + The static search index is built from corpus text and rendered in the browser by the + search dialog and the hybrid search dialog. Fumadocs' default result renderer parses + highlighted text as raw HTML. + invariant: > + Search hits are rendered only through SearchResultItem / renderSearchMarkdown, which + parses index text with no allowDangerousHtml and no rehype-raw; every html node + becomes text, and only paired bare becomes an element. Every dialog that + DocsProvider wires (static and hybrid) passes renderMarkdown; none falls back to + fumadocs' default SearchDialogListItem renderer. The index stays text-only. + enforced_by: + - packages/docs-next/src/search-markdown.tsx:20 + - packages/docs-next/src/search-markdown.tsx:87 + - packages/docs-next/src/search-markdown.tsx:92 + - packages/docs-next/src/search-dialog.tsx:30 + - packages/docs-next/src/hybrid-search.tsx:86 + - packages/docs-next/src/search.ts:133 + tests: + - packages/docs-next/src/search-markdown.test.tsx + - packages/docs-next/src/search-dialog.test.tsx + - packages/docs-next/src/hybrid-search.test.tsx + - packages/docs-next/test/search-xss.ts + - packages/docs-next/src/search.e2e.test.ts + paths: + - packages/docs-next/src/search*.ts + - packages/docs-next/src/search*.tsx + - packages/docs-next/src/hybrid-search*.tsx + - packages/docs-next/src/semantic-search*.ts + - packages/docs-next/src/provider.tsx + - packages/docs-ui/src/search-button.tsx + - apps/docs/scripts/semantic-index.mjs + - apps/*/app/api/search/** + review_focus: + - A search dialog, result list or suggestion component that uses fumadocs' SearchDialogListItem (or any renderer) without renderMarkdown set to the inert renderer. + - rehype-raw, allowDangerousHtml or dangerouslySetInnerHTML anywhere on a path from index text to the DOM. + - A change to toSearchText that reintroduces decodable entities, or a comment claiming index-level escaping alone keeps the dialog safe. + - A test that asserts only on the index file rather than on the rendered dialog DOM. + - A fumadocs-core or fumadocs-ui bump that changes highlightMarkdown or the list item renderer. + known_failures: + - "Search-index stored XSS (audit II H1), fixed by escaping in toSearchText (#48 to #56)." + - "Regression: fumadocs' highlightMarkdown decoded the escaped text and the default renderer parsed it with rehype-raw, so an iframe srcdoc payload ran on coder.com for any matching query; fixed by the inert renderer (#237). Live versions stay vulnerable until each is republished." + severity_floor: high + + - id: publish-build-split + summary: > + publish-version.yml compiles untrusted coder/coder content in a build job and writes + to the private archive, the public mirror and the Global Config manifest in a + publish job bound to the docs-publish environment. Code execution during next build + is assumed possible. + invariant: > + The build job holds no write-scoped secret (BLOB_READ_WRITE_TOKEN, + BLOB_READ_WRITE_TOKEN_MIRROR, DOCS_VERSIONS_WRITE_TOKEN, VERCEL_TOKEN) and fails if + one is readable; any token it uses is read-only and confined to steps that run before + the content checkout. The build job restores and saves no actions/cache entry. The + publish job never checks out content, regenerates the plan from its own engine-only + checkout, executes nothing from the build artifacts except the packages artifact + after its digest matches the step output recorded before the content checkout, and + never takes a value that decides the manifest write, an archive key or a response + header from the content artifact. Artifact-derived strings never reach the publish + job's stdout or stderr at the start of a line or unescaped, so they cannot form + workflow commands. + enforced_by: + - all_of: + - .github/workflows/publish-version.yml#jobs.build.steps[Refuse to run holding a write-scoped secret] + - .github/workflows/publish-version.yml#jobs.publish.environment + note: secrets live only in the docs-publish environment, and the build job checks that they do + - all_of: + - .github/workflows/publish-version.yml#jobs.build.steps[Build the workspace packages] + - .github/workflows/publish-version.yml#jobs.publish.steps[Check the restored packages against the build job's digest] + note: digest recorded as a step output before content is on disk, checked before anything restored runs + - .github/workflows/publish-version.yml#jobs.publish.steps[Regenerate the plan] + - .github/workflows/publish-version.yml#env.CONTENT_REPOSITORY + - apps/docs/scripts/publish/upload.mjs:54 + - apps/docs/scripts/publish/upload.mjs:90 + - apps/docs/scripts/archive-layout-helpers.mjs:249 + tests: + - apps/docs/scripts/publish/upload.test.mjs + - apps/docs/scripts/publish/verify.test.mjs + - apps/docs/scripts/publish/plan.test.mjs + - apps/docs/scripts/archive-layout-helpers.test.mjs + paths: + - .github/workflows/** + - .github/actions/** + - apps/docs/scripts/publish/** + - apps/docs/scripts/archive-layout*.mjs + - apps/docs/scripts/single-version.mjs + - apps/docs/scripts/build-versions.mjs + - apps/docs/scripts/sync-docs.mjs + - apps/docs/scripts/version-redirects.mjs + - packages/docs-manifest/src/** + - turbo.json + - package.json + - pnpm-workspace.yaml + - pnpm-lock.yaml + review_focus: + - A secret, or github.token, added to the env of a build-job step at or after "Check out the content tree at the resolved commit". + - A write-scoped secret added at repository scope, or the write-secret guard step removed, reordered or narrowed. + - An actions/cache, setup-node cache or turbo remote cache restored or saved in the build job, or restored into CI from a key the build job could write. + - A file from the content artifact read as plan, manifest item, archive key, content type or redirect target in the publish job, or executed there. + - A change to the digest command in one job but not the other, or a restored file executed before the digest check. + - console.log, echo or ::warning:: of a path, key, hash or error message that came from _publish.json, the archive or the build, without stripping control characters and prefixing the line. + - A new workflow_dispatch or workflow_call input that chooses the content repository, the archive prefix or the manifest key. + known_failures: + - "Archive prefix was not re-validated before store reads and writes; fixed by assertArchivePrefix (#81)." + - "The build job restored a Turbopack cache after the content checkout, and CI restored caches the build job could write; fixed by dropping those caches (#235)." + - "A free-form content_repository input let a dispatch-token holder publish another repository's docs; fixed by pinning CONTENT_REPOSITORY to coder/coder (#227)." + - "The build step received github.token; moved to a step before the content checkout (#236)." + - "Publish scripts print artifact-derived paths at column 0, so a newline in a corpus file name can inject workflow commands (log integrity only); open." + severity_floor: high + + - id: archive-lifecycle + summary: > + The private Blob archive holds every published version under versions///; + the Global Config manifest names which prefix serves each version. The publish job + uploads, verifies, writes the manifest, rolls back, mirrors and prunes. + invariant: > + Every store key is asserted to be under versions// with a 40-hex sha before + any read, write or delete. The manifest write is the last reader-visible step and + happens only after read-back verification passed; a failed post-write smoke check + restores the snapshot taken before the write. Cleanup never deletes a tag prefix or a + prefix the manifest references, and re-reads both _uploading.json and _publish.json + immediately before every delete call, including a delete retried after a rate limit, + keeping any prefix with activity inside the seven-day grace or with no _publish.json. + A manifest that references nothing never authorizes deleting everything. + enforced_by: + - apps/docs/scripts/publish/upload.mjs:54 + - apps/docs/scripts/publish/upload.mjs:124 + - apps/docs/scripts/publish/cleanup.mjs:38 + - apps/docs/scripts/publish/cleanup.mjs:106 + - apps/docs/scripts/publish/cleanup.mjs:145 + - apps/docs/scripts/publish/verify.mjs:114 + - apps/docs/scripts/publish/rollback.mjs + - packages/docs-manifest/src/write.ts:92 + - .github/workflows/publish-version.yml#jobs.publish.steps[Write the manifest (one request)] + tests: + - apps/docs/scripts/publish/cleanup.test.mjs + - apps/docs/scripts/publish/upload.test.mjs + - apps/docs/scripts/publish/verify.test.mjs + - apps/docs/scripts/publish/rollback.test.mjs + - apps/docs/scripts/publish/items.test.mjs + paths: + - apps/docs/scripts/publish/** + - packages/docs-manifest/src/** + - .github/workflows/publish-version.yml + - .github/workflows/republish-lines.yml + - .github/workflows/backfill-versions.yml + - .github/workflows/reconcile-versions.yml + review_focus: + - A delete, copy or put whose key is built without assertArchivePrefix, or from a value read out of the build's _publish.json. + - A keepReason re-read moved outside the retried closure, or a delete batch issued for several prefixes after one check. + - Cleanup that treats an empty or failed manifest read as "nothing referenced". + - A tag prefix made deletable, or a forced tag republish path that skips the tag-exists check. + - A manifest write moved before verify, or a smoke failure that does not restore the snapshot. + - Reuse (DOCS_UPLOAD_REUSE) that trusts an _objects.json the build artifact could supply, rather than the one the publish job wrote. + known_failures: + - "Cleanup could delete a prefix being re-uploaded between its listing and its delete; fixed by re-reading both markers inside the retried delete (#236)." + - "The upload accepts an artifact that ships its own _-prefixed root objects other than _redirects.json; open (low)." + severity_floor: high + + - id: router-serving + summary: > + apps/router answers every coder.com/beta-docs request from the private archive through + a route handler, applies per-version and static redirects, and sets the security + headers. It holds an OIDC credential to the archive store and reads the manifest. + invariant: > + The router fetches only from manifest deployments whose host is the private Blob + archive, never from another origin. Request paths containing //, a backslash, or an + unsafe segment (., .., percent-encoded slash, dot or backslash) are rejected before + the store is asked. Only GET and HEAD are served. Every archive response carries + nosniff, Referrer-Policy and a Content-Security-Policy chosen by the object key: the + page policy for .html only, sandbox for everything else including .svg in any case. + Store objects the build wrote (_redirects.json) are size-checked before and while + reading and parsed as strictly as they were written. A redirect Location is either + path-absolute on the same site or an allowlisted https URL (https://github.com/coder/, + https://coder.com/); a parameter never reaches the host part, and source parameters + use allowlist patterns. + enforced_by: + - apps/router/lib/archive.ts:75 + - apps/router/lib/archive.ts:105 + - apps/router/lib/archive.ts:123 + - apps/router/lib/archive.ts:251 + - apps/router/lib/archive.ts:283 + - apps/router/lib/archive-handler.ts:182 + - packages/docs-manifest/src/path-safety.ts:39 + - packages/docs-manifest/src/path-safety.ts:48 + - packages/docs-manifest/src/bounded-read.ts:43 + - packages/docs-manifest/src/version-redirects.ts:80 + - packages/docs-manifest/src/version-redirects.ts:167 + - apps/router/lib/redirects.ts:32 + - apps/router/vercel.json#headers + tests: + - apps/router/lib/archive.test.ts + - apps/router/lib/archive-handler.test.ts + - apps/router/lib/version-redirects.test.ts + - apps/router/lib/versioned-redirects.test.ts + - apps/router/lib/redirects.test.ts + - apps/router/lib/redirects.cases.json + - apps/router/lib/vercel-config.test.ts + - packages/docs-manifest/src/path-safety.test.ts + - packages/docs-manifest/src/version-redirects.test.ts + paths: + - apps/router/** + - packages/docs-manifest/src/** + review_focus: + - A store read of a build-written object through .text(), .json() or arrayBuffer() without readBlobTextWithLimit or a size check first. + - A new route handler or middleware that skips the path-safety checks, or matches before them. + - A response path (new status, 304, not-found, redirect) that does not go through responseHeadersFor or loses the per-key CSP. + - A fetch to a manifest deployment URL that is not an archive host, or a header from the request forwarded to the store. + - A redirect destination built from request input into the host, or a new external allowlist entry. + - A static redirect rule with a bare :name, (.*) or .+ parameter. + known_failures: + - "Open redirect: a match-anything wildcard turned /coder-oss//evil.example into a Location of //evil.example; fixed by allowlist segment patterns." + - "The router read _redirects.json in full before applying its 1 MiB cap; fixed by a bounded read (#228)." + - "The allowlisted https://coder.com/ destination admits a 308 self-loop; open (low)." + - "/_next/image is enabled on the router, the only runtime path to the sharp dependency; open (low)." + severity_floor: medium + + - id: csp-and-headers + summary: > + The public site's CSP and security headers are set in three places that must agree: + the router's per-key header map, apps/docs/vercel.json, and coder.com's own header + rules for /beta-docs, which replace upstream headers of the same name. + invariant: > + script-src names only 'self' and 'unsafe-inline' (plus the analytics origins only when + DOCS_ANALYTICS is on and Security has signed off); object-src 'none', base-uri 'self', + form-action 'self' and frame-ancestors 'self' stay. Every built page passes csp:check. + The router's policy and apps/docs/vercel.json's policy are built from the same + definition, and the weekly headers check compares production against the router. + enforced_by: + - packages/docs-config/src/analytics.ts:74 + - apps/router/lib/archive.ts:105 + - apps/docs/vercel.json#headers + - apps/offlinedocs/scripts/csp-check.mjs + - apps/router/scripts/headers-check.mjs + - .github/workflows/security.yml#jobs.production-headers + tests: + - apps/offlinedocs/scripts/csp-check.test.mjs + - apps/offlinedocs/scripts/csp-check-helpers.test.mjs + - apps/router/scripts/headers-check.test.ts + - apps/router/lib/vercel-config.test.ts + paths: + - packages/docs-config/src/analytics.ts + - apps/docs/vercel.json + - apps/offlinedocs/vercel.json + - apps/router/vercel.json + - apps/router/lib/archive.ts + - apps/router/scripts/headers-check* + - apps/offlinedocs/scripts/csp-check* + review_focus: + - Any new origin in script-src, connect-src, frame-src or a default-src change without a "needs security sign-off" note. + - The .svg sandbox rule made case-sensitive or dropped in one of the header sources. + - csp:check removed from a build, or an inline script allowlisted by content. + - A header set in the router handler that coder.com would replace, assumed to reach readers. + known_failures: + - "coder.com's catch-all header rule dropped the docs CSP for /beta-docs; fixed in coder.com and checked weekly since." + - "apps/docs/vercel.json matches .svg case-sensitively, unlike the router; open (low)." + severity_floor: medium + + - id: workflow-triggers-and-tokens + summary: > + Who can start which workflow, with which token. publish-version.yml is dispatched by + the hourly reconciler, the republish and backfill workflows, and coder/coder's + docs-publish workflows through a fine-grained PAT with Actions write. + docs-pr-preview.yml builds a coder/coder PR's docs and deploys a Vercel preview. + invariant: > + No workflow uses pull_request_target, workflow_run or issue_comment. pull_request + runs (ci.yml, security.yml) get no secret and only read permissions. Every action is + pinned by commit SHA. Every caller input is validated by regex in an env-quoted step + before it reaches a checkout, a runs-on or an API call, and is never interpolated into + run: scripts. The production publish path only ever builds coder/coder content, so a + dispatch credential can choose a ref but not what repository is published. A job that + builds untrusted content never holds, or shares a runner with, a deploy or write + credential. + enforced_by: + - .github/workflows/publish-version.yml#env.CONTENT_REPOSITORY + - .github/workflows/publish-version.yml#jobs.build.steps[Validate inputs] + - .github/workflows/docs-pr-preview.yml#jobs.preview.steps[Validate inputs] + - .github/workflows/docs-pr-preview.yml#jobs.preview.environment + - .github/workflows/ci.yml#permissions + - .github/CODEOWNERS + tests: + - .github/workflows/ci.yml#jobs.actionlint + paths: + - .github/** + - docs/superpowers/upstream/** + review_focus: + - A new trigger, or a new workflow_call/workflow_dispatch input, especially one naming a repository, a runner or a path. + - A permissions block widened to write, or a job without one. + - An action referenced by tag or branch instead of a 40-hex SHA. + - ${{ inputs.* }}, ${{ github.event.* }} or a step output interpolated directly into run:. + - A secret passed to the step that runs next build or vercel build in docs-pr-preview.yml, or the deploy step running in the same job as the untrusted build. + - An environment name changed, or a job that should be bound to docs-publish, docs-preview or docs-dist losing its environment. + known_failures: + - "docs-pr-preview.yml builds untrusted PR content and deploys with a team-scoped VERCEL_TOKEN in one job, so build-time code could persist into the deploy step; open, not yet wired from coder/coder." + severity_floor: high + + - id: dist-release + summary: > + apps/dist-release packs the @coder/* packages into tarballs released on the public + coder/docs-engine-dist repository. Nothing is published to npm. + invariant: > + Every packed manifest stays private, every @coder dependency is pinned to this + release's asset URL (never a range or registry name), and each tarball holds only + package.json, README.md, LICENSE and the PACKAGE_ALLOW paths, with no TypeScript + source other than declarations, no source maps or sourceMappingURL, no comments in + shipped code, no non-regular entries, and no gitleaks finding. A missing gitleaks + fails the pack except in an explicit local dry run. + enforced_by: + - apps/dist-release/src/config.mjs:18 + - apps/dist-release/src/contents.mjs:41 + - apps/dist-release/src/contents.mjs:75 + - apps/dist-release/src/contents.mjs:106 + - apps/dist-release/src/manifest.mjs:11 + - apps/dist-release/src/manifest.mjs:33 + - apps/dist-release/src/secrets.mjs:16 + tests: + - apps/dist-release/src/contents.test.mjs + - apps/dist-release/src/manifest.test.mjs + - apps/dist-release/src/secrets.test.mjs + - apps/dist-release/src/pack.test.mjs + paths: + - apps/dist-release/** + - packages/*/package.json + review_focus: + - A PACKAGE_ALLOW entry widened to a directory that holds source, fixtures or maps. + - '"private": true removed, or a publishConfig or npm publish step added anywhere.' + - A dependency check that accepts a range or registry name for an @coder package (dependency confusion). + - The gitleaks scan skipped under CI or --release, or its config made overridable from the working directory. + known_failures: [] + severity_floor: medium + +assets: + - id: archive-write-token + summary: BLOB_READ_WRITE_TOKEN (private archive store) and BLOB_READ_WRITE_TOKEN_MIRROR (public mirror store). + boundary: publish-build-split + gated_by: .github/workflows/publish-version.yml#jobs.build.steps[Refuse to run holding a write-scoped secret] + sinks: + - .github/workflows/publish-version.yml + - apps/docs/scripts/publish/** + reachability_probe: + grep: "BLOB_READ_WRITE_TOKEN" + include: + [ + ".github/**", + "apps/**", + "packages/**", + ":(exclude)**/*.test.*", + ":(exclude)**/*.e2e.*", + ":(exclude)**/*.md", + ] + emit: files + on_new: > + A new reader of an archive or mirror write token. Confirm it runs only in a job bound + to docs-publish, never in a job that checks out or compiles coder/coder content. + + - id: manifest-write-token + summary: DOCS_VERSIONS_WRITE_TOKEN, a Vercel token with write access to the docs-versions Global Config store, also used as VERCEL_TOKEN in publish steps. + boundary: publish-build-split + gated_by: .github/workflows/publish-version.yml#jobs.publish.environment + sinks: + - .github/workflows/publish-version.yml + - .github/workflows/reconcile-versions.yml + - .github/workflows/republish-lines.yml + - .github/workflows/historical-sync.yml + - packages/docs-manifest/src/write.ts + reachability_probe: + grep: "DOCS_VERSIONS_WRITE_TOKEN" + include: + [ + ".github/**", + "apps/**", + "packages/**", + ":(exclude)**/*.test.*", + ":(exclude)**/*.e2e.*", + ":(exclude)**/*.md", + ] + emit: files + on_new: > + A new reader of the manifest write token. Confirm the job is bound to docs-publish, + checks out no content, and that a read-only use could not take a read-scoped token. + + - id: vercel-deploy-token + summary: VERCEL_TOKEN, VERCEL_ORG_ID and VERCEL_PROJECT_ID used by the PR preview deploy; team-scoped today. + boundary: workflow-triggers-and-tokens + gated_by: .github/workflows/docs-pr-preview.yml#jobs.preview.environment + sinks: + - .github/workflows/docs-pr-preview.yml + reachability_probe: + grep: 'secrets\.VERCEL_' + include: [".github/**"] + emit: files + on_new: > + A new job holding a Vercel deploy credential. Confirm it never runs on the same runner + as an untrusted build and installs the Vercel CLI from the lockfile. + + - id: archive-objects + summary: Every published version's objects in the private archive; deleting or overwriting a live prefix takes that version down or replaces its content. + boundary: archive-lifecycle + gated_by: apps/docs/scripts/publish/upload.mjs:54 + sinks: + - apps/docs/scripts/publish/upload.mjs + - apps/docs/scripts/publish/cleanup.mjs + - apps/docs/scripts/publish/verify.mjs + - apps/router/lib/archive.ts + reachability_probe: + grep: '\b(del|put|copy|head|get|list|listWithRetry)\(|from "@vercel/blob"' + include: + [ + "apps/docs/scripts/**", + "apps/router/**", + "packages/docs-manifest/src/**", + ":(exclude)**/*.test.*", + ":(exclude)**/*.e2e.*", + ":(exclude)**/*.md", + ] + emit: files + on_new: > + A new caller of the Blob SDK. Confirm every key it builds passes assertArchivePrefix + (publish side) or hasUnsafePathSegment (router side), and that a delete re-checks the + prefix's markers immediately before the call. + + - id: version-manifest + summary: The docs-versions Global Config items that decide which archive prefix serves each version, plus the public /versions.json mirror. + boundary: archive-lifecycle + gated_by: packages/docs-manifest/src/write.ts:92 + sinks: + - packages/docs-manifest/src/write.ts + - apps/docs/scripts/publish/items.mjs + - apps/docs/scripts/publish/rollback.mjs + - apps/docs/scripts/publish/mirror.mjs + - apps/router/lib/manifest.ts + reachability_probe: + grep: 'writeManifestItems|buildItemsPatch|readManifestItems|edge-config|getAll\(' + include: + [ + "apps/**", + "packages/**", + ":(exclude)**/*.test.*", + ":(exclude)**/*.e2e.*", + ":(exclude)**/*.md", + ] + emit: files + on_new: > + A new reader or writer of the manifest. A writer must run in the publish job after + read-back verification; a reader that writes nothing should use a read-scoped token. + + - id: coder-com-origin + summary: Script execution on coder.com (pages are served same-origin through the /beta-docs rewrite) and, later, inside the authenticated Coder dashboard. + boundary: corpus-render + gated_by: packages/docs-transforms/src/mdx-plugins/rehype-sanitize-coder-docs.ts:265 + sinks: + - packages/docs-transforms/src/mdx-config.ts + - packages/docs-next/src/search-markdown.tsx + - packages/docs-next/src/display-preferences.tsx + reachability_probe: + grep: 'dangerouslySetInnerHTML|allowDangerousHtml|rehype-raw|rehypeRaw|\.innerHTML *=|outerHTML *=|insertAdjacentHTML|document\.write' + include: + [ + "packages/*/src/**", + "apps/*/app/**", + "apps/*/lib/**", + "apps/*/components/**", + ":(exclude)**/*.test.*", + ":(exclude)**/*.e2e.*", + ":(exclude)**/*.md", + ] + emit: files + on_new: > + A new raw-HTML sink. Confirm its input is a constant or has passed + rehypeSanitizeCoderDocs, and that no corpus or search-index text reaches it. + + - id: dist-tarballs + summary: Release tarballs on the public coder/docs-engine-dist repository, built from this private repository's source. + boundary: dist-release + gated_by: apps/dist-release/src/contents.mjs:41 + sinks: + - apps/dist-release/src/pack.mjs + - apps/dist-release/src/config.mjs + reachability_probe: + grep: "pnpm pack|npm publish|publishConfig|gh release (create|upload)" + include: + [ + "apps/**", + "packages/**", + ".github/**", + "package.json", + ":(exclude)**/*.test.*", + ":(exclude)**/*.e2e.*", + ":(exclude)**/*.md", + ] + emit: files + on_new: > + A new path that packs or publishes packages. Confirm it goes through the + dist-release checks and never reaches the npm registry. + +surface_probes: + - id: workflow-triggers + describes: Workflow trigger kinds in use + grep: "^ (push|pull_request|pull_request_target|workflow_run|workflow_call|workflow_dispatch|schedule|issue_comment|issues|release|repository_dispatch|merge_group):" + include: [".github/workflows/*.yml", ".github/workflows/*.yaml"] + emit: names + boundary: workflow-triggers-and-tokens + on_new: > + A trigger kind the repository did not use before. pull_request_target, workflow_run or + issue_comment combined with a checkout or a secret is a high finding. + on_removed: Confirm the removed trigger was not the only path that ran a required check. + + - id: workflow-write-grants + describes: Workflow files that grant a write permission + grep: "^ +(actions|attestations|checks|contents|deployments|id-token|issues|packages|pages|pull-requests|security-events|statuses): write" + include: [".github/workflows/*.yml", ".github/workflows/*.yaml"] + emit: files + boundary: workflow-triggers-and-tokens + on_new: > + A workflow that gained a write grant. Confirm the job that holds it never compiles + untrusted content and is not reachable from pull_request. + + - id: workflow-secrets + describes: Secret names referenced by workflows + grep: 'secrets\.[A-Za-z_][A-Za-z0-9_]*' + include: [".github/**"] + emit: names + boundary: publish-build-split + on_new: > + A new secret in CI. Confirm which job reads it, that the job checks out no untrusted + content, and whether it belongs in an environment rather than at repository scope. + + - id: unpinned-actions + describes: Third-party actions not pinned to a commit SHA + grep: "uses: +[A-Za-z0-9_.-]+/[A-Za-z0-9_./-]+@([^0-9a-f ]|[0-9a-f]{0,39}([^0-9a-f]|$))" + include: [".github/**"] + emit: names + boundary: workflow-triggers-and-tokens + on_new: An action referenced by tag or branch; pin it to a 40-hex SHA. + + - id: workflow-commands + describes: Files that print GitHub workflow commands or write GITHUB_ENV/GITHUB_PATH + grep: "::(error|warning|notice|debug|add-mask|add-matcher|stop-commands|group)|GITHUB_(ENV|PATH)" + include: [".github/**", "apps/docs/scripts/**", "apps/dist-release/src/**"] + emit: files + boundary: publish-build-split + on_new: > + A new emitter of workflow commands. Confirm nothing derived from the build artifact, + the archive or corpus content is interpolated into the line. + + - id: raw-html-sinks + describes: Raw-HTML sinks in shipped code + grep: 'dangerouslySetInnerHTML|allowDangerousHtml|rehype-raw|rehypeRaw|\.innerHTML *=|insertAdjacentHTML' + include: + [ + "packages/*/src/**", + "apps/*/app/**", + "apps/*/lib/**", + ":(exclude)**/*.test.*", + ":(exclude)**/*.e2e.*", + ":(exclude)**/*.md", + ] + emit: files + boundary: corpus-render + on_new: A new raw-HTML sink; trace whether corpus or index text reaches it. + + - id: router-routes + describes: Router route handlers + grep: "export" + include: + [ + "apps/router/app/**/route.ts", + "apps/router/app/**/route.tsx", + "apps/router/middleware.ts", + "apps/router/proxy.ts", + ] + emit: files + boundary: router-serving + on_new: > + A new route handler. Confirm it runs the path-safety checks first, serves only GET and + HEAD, and sets the security headers. + + - id: external-redirect-hosts + describes: Absolute https destinations the router can send a reader to + grep: "https://[A-Za-z0-9.-]+/?" + include: ["apps/router/redirects.json", "packages/docs-manifest/src/version-redirects.ts"] + emit: names + boundary: router-serving + on_new: A new off-site redirect host; confirm it is Coder-owned and the parameter stays in the path. + + - id: csp-origins + describes: Origins named by the Content Security Policy builder + grep: "https://[A-Za-z0-9.*-]+" + include: ["packages/docs-config/src/analytics.ts"] + emit: names + boundary: csp-and-headers + on_new: A new CSP origin; needs Security sign-off before the flag that uses it is on anywhere. diff --git a/.security/threat-model.md b/.security/threat-model.md new file mode 100644 index 00000000..596aca09 --- /dev/null +++ b/.security/threat-model.md @@ -0,0 +1,196 @@ +# docs-engine threat model + +This is the persistent threat model for coder/docs-engine, in the shape the Coder Security team's `threat-model-persistent` and `quick-pr-review-model` skills use. +`.security/boundaries.yaml` is its machine-readable half: the boundaries, invariants, enforcing code, review focus and probes a PR review gates against. +The model is a proposal until `reviewed_by` and `reviewed_on` are set in that file; until then a review against it is advisory. + +## 1. Overview + +docs-engine renders Coder's documentation. +The content lives in the public `coder/coder` repository under `docs/`; this repository holds no content of its own. +It ships three things: + +- The public docs site, served at `coder.com/beta-docs` through a same-origin rewrite on coder.com, so its pages run on the coder.com origin. +- The offline export, a static bundle for air-gapped deployments, and later the in-product docs, rendered inline in the authenticated Coder dashboard with no iframe boundary. +- Compiled `@coder/*` packages, released only as GitHub release assets on the public `coder/docs-engine-dist` repository and never to npm. + +Two untrusted inputs drive everything: Markdown and raw HTML from any contributor whose `coder/coder` PR merges, and the git ref named in a publish dispatch. +The repository is private; making it public is an open option, and the model marks what changes if it does. + +There is no deployed service with users or sessions of its own. +The runtime is the router plus static files, and the privileged part of the system is the CI pipeline that compiles content and writes the archive, so the pipeline is modelled as runtime. + +| Component | Source | Role | +| ------------------------ | ------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------- | +| Sync and sources | `packages/docs-build`, `packages/docs-sources` | Reads a coder/coder tree at a ref, validates it and writes `.md` files and assets | +| Transforms and sanitizer | `packages/docs-transforms` | Remark/rehype pipeline; `rehypeSanitizeCoderDocs` runs right after `rehype-raw` | +| UI and Next adapter | `packages/docs-ui`, `packages/docs-next` | Renders compiled pages, links, media and the search dialogs | +| Config and manifest | `packages/docs-config`, `packages/docs-manifest` | CSP builder, render context, Global Config manifest client, path safety, version redirects | +| Docs site build | `apps/docs`, `apps/offlinedocs` | Static export per version; `archive:layout` lays it out as the archive tree | +| Publisher | `apps/docs/scripts/publish/*`, `.github/workflows/publish-version.yml` | Builds one ref, uploads to the archive, verifies, writes the manifest, mirrors, prunes | +| Reconciler and fan-out | `reconcile-versions.yml`, `republish-lines.yml`, `backfill-versions.yml` | Dispatch `publish-version.yml` for missing or stale refs | +| Router | `apps/router` | Route handler serving every version from the private Blob archive, with redirects and headers | +| PR previews | `.github/workflows/docs-pr-preview.yml`, `apps/offlinedocs` | Builds a coder/coder PR's docs and deploys a protected Vercel preview | +| Public releases | `apps/dist-release` | Packs and checks the tarballs released on `coder/docs-engine-dist` | + +```mermaid +flowchart LR + C["coder/coder docs/ (untrusted)"] --> B["publish-version.yml build job
no write secret"] + B -- "content artifact + digest-checked packages" --> P["publish job
docs-publish environment"] + P -- "Blob write token" --> A[("private Blob archive
versions/id/sha/")] + P -- "Global Config write token" --> M[("docs-versions manifest")] + P -- "mirror token" --> MI[("public mirror
versions.json")] + R["apps/router
OIDC read"] --> A + R --> M + CC["coder.com /beta-docs rewrite"] --> R + U["reader's browser
coder.com origin"] --> CC +``` + +Effective resources that decide a boundary: + +| Workflow or deployment | Resource or capability | Config and precedence | Effective value or location | Readers, writers, recipients | Enforcing control | Evidence or unknowns | +| ---------------------------------------- | ---------------------------------------------------- | ------------------------------------------------------------------------------------ | ---------------------------------------------------------------------- | ---------------------------------------------------------------------------- | ------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------- | +| `publish-version.yml` build job | Archive, mirror and manifest write tokens | Environment-scoped secrets on `docs-publish`; the build job binds no environment | Unset in `build` | `publish` job only | The build job's first step fails the run if any of the three is readable | `.github/workflows/publish-version.yml#jobs.build.steps[Refuse to run holding a write-scoped secret]` | +| `publish-version.yml` build job | `github.token` (`contents: read`) | Passed only to the release-schedule fetch, which runs before the content checkout | Present on the runner for checkout; not in the build step's env | Engine checkout, release-schedule fetch | Step order; `persist-credentials: false` on every checkout | `publish-version.yml#jobs.build.steps[Fetch the release schedule]` | +| `publish-version.yml` publish job | Write tokens, `actions: write` | `environment: docs-publish`, deployment branch policy restricted to `main` | Available to every publish step | Upload, verify, manifest write, rollback, mirror, cleanup, mainline dispatch | No content checkout; nothing from the content artifact executed | `docs-publish` has a branch policy and no required reviewer, by design (hourly unattended runs) | +| `publish-version.yml` content repository | Which repository is built and published | Workflow-level `env.CONTENT_REPOSITORY`; no input overrides it | `coder/coder` | Every checkout, `ls-remote`, edit link and release lookup | Hard-coded value | `publish-version.yml#env.CONTENT_REPOSITORY` | +| coder/coder trigger | Dispatching `publish-version.yml` | `DOCS_ENGINE_PUBLISH_TOKEN` in coder/coder, fine-grained PAT, Actions write | Planned; not wired as of this model | Any coder/coder workflow that can read the secret | Ref regex in `Validate inputs`; content repository pinned | Unknown: who can read the secret in coder/coder, and whether it becomes a GitHub App token | +| `docs-pr-preview.yml` | `VERCEL_TOKEN`, `VERCEL_ORG_ID`, `VERCEL_PROJECT_ID` | Environment `docs-preview` in the calling repository | Team-scoped token, same job as the untrusted build | Deploy step; build-time code on the same runner | Environment required reviewers in the caller (not readable from here) | Open gap; the workflow has never run | +| Router (`coder-docs-router`) | Archive read, manifest read | Store connections on the Vercel project; OIDC for the archive | No token variable set by hand | Router functions | Archive host check, path-safety checks | `apps/router/README.md` "Serving the Blob archive" | +| Public page CSP | `script-src` | Router `SECURITY` map, `apps/docs/vercel.json`, coder.com's `/beta-docs` header rule | `'self' 'unsafe-inline'`; analytics origins only with `DOCS_ANALYTICS` | Every reader | `csp:check` at build, weekly `production-headers` job | coder.com replaces upstream headers of the same name, so its copy is the one readers get | + +## 2. Trust boundaries and assumptions + +### Assets and security objectives + +- **The coder.com origin.** + Script that runs on a docs page runs as coder.com. + coder.com HTML sets no session cookies, but HubSpot sets `.coder.com` analytics cookies, and the in-product target will put the same pages inside the authenticated dashboard. + The objective is that no corpus or index text ever executes or injects active markup. +- **Write credentials:** the private archive store's read-write token, the public mirror store's token, the Global Config write token, the team-scoped Vercel deploy token used by previews, and the `actions: write` job tokens of the publish and reconciler jobs. + Credential values never appear in this model. +- **The archive and the manifest.** + Integrity and availability of every published version: no prefix deleted while referenced or in use, no manifest entry pointing at content that was not built from `coder/coder` at the named ref. +- **CI integrity:** the packages the publish job executes, Actions caches, workflow logs and annotations. +- **The dist tarballs:** they must contain only the intended compiled output, with no source, source maps, comments or secrets from this private repository, and must never be resolvable from the npm registry. +- **Private source and internal identifiers** while the repository stays private: Vercel team and project ids, store hosts and the Global Config id are not secrets but should not be printed more widely than needed. + +### Actors + +| Actor and starting authority | Asset | Capability that must be denied | Enforcement and evidence / gap | +| --------------------------------------------------------------------------------------------- | --------------------------------- | --------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| Anonymous reader; can request any URL and type any search query | coder.com origin, router | Traversal outside a version's prefix, open redirect off coder.com, unbounded reads, non-GET writes | Path-safety checks before any store call, redirect allowlists, GET/HEAD only, bounded reads (`router-serving`) | +| coder/coder docs contributor; any merged PR, including literal raw HTML and file names | coder.com origin, dashboard DOM | Script or active markup in a page, a search hit, a twin, a storage key, a heading id | Sanitizer after `rehype-raw`, `.md`-only sync, inert search renderer, plain-text twins with `nosniff` (`corpus-render`, `search-client-sinks`) | +| coder/coder repo writer; can push to `main`, `release/*` and tags | Archive content for those refs | Choosing a repository other than coder/coder, writing outside `versions///`, deleting tags | Pinned content repository, `assertArchivePrefix`, tag prefixes never deleted; content they push is published by design | +| Holder of the publish dispatch token (coder/coder `DOCS_ENGINE_PUBLISH_TOKEN`, Actions write) | Archive, manifest, CI minutes | Publishing another repository, an arbitrary archive key, or anything but a valid ref | `Validate inputs` regexes and pinned `CONTENT_REPOSITORY`; can still run any workflow_dispatch in this repo and cancel runs (gap: token scope is repository-wide) | +| docs-engine repo writer or maintainer | Everything here | Weakening the sanitizer, the build split, or this model without review | `main` ruleset: one approval, code-owner review, `build & check` required; CODEOWNERS names the sanitizer files, the workflows and `.security/` | +| Fork PR author (only if the repository goes public) | CI, secrets | Secrets, write tokens, cache writes in `main` scope | No `pull_request_target`/`workflow_run`/`issue_comment`; `pull_request` jobs hold read permissions and no secret; fork-PR approval setting not yet verified | +| Code execution inside the untrusted build job (a corpus-triggered bug in the build toolchain) | Write tokens, publish job, caches | Reaching a write token, influencing what the publish job executes, keys or writes | No write secret in the job, digest-checked packages artifact, plan regenerated in `publish`, no `actions/cache`; it can still ship unsanitized HTML in its own output | +| Compromised dependency or action | Everything that runs it | Running unreviewed code | Actions pinned by SHA, `harden-runner`, pnpm 10 blocks lifecycle scripts, frozen lockfile, OSV-Scanner; a compromised build dependency is equivalent to build RCE | + +What the actors do **not** have: no actor here holds coder.com's deployment, the Vercel dashboard, or GitHub organization admin. +A coder/coder repo writer already decides what the docs say, so publishing their content is not a new capability; the boundary is about where it is published and whether it can execute. + +### Boundary crossings + +1. **Corpus to HTML (`corpus-render`).** + Contributor Markdown is parsed with raw HTML kept, reparsed by `rehype-raw`, then cleaned by `rehypeSanitizeCoderDocs` with GitHub's schema plus `