Skip to content

feat: authorize commit previews and add /pr/:number preview routes - #31

Open
atinux wants to merge 1 commit into
mainfrom
feat/secure-fork-previews
Open

feat: authorize commit previews and add /pr/:number preview routes#31
atinux wants to merge 1 commit into
mainfrom
feat/secure-fork-previews

Conversation

@atinux

@atinux atinux commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

Written by an AI agent on behalf of @atinux, who has reviewed it.

Problem

/blob/:sha only validated the SHA format before serving content through the upstream GitHub API. GitHub shares git objects across the fork network: once a fork opens a PR, its head commit is fetchable through the upstream repo. Anyone could open a fork PR with arbitrary markdown and have it rendered on the docs domain — a content-spoofing/phishing vector, even with scripts and embeds stripped by the security plugin.

What changed

Server-side authorization (the core fix)

  • authorizePreviewSha(sha) in server/utils/github.ts: a commit renders under /blob/:sha only when it is (1) vouched for by a same-repo PR, (2) vouched for by a fork PR carrying the preview:enabled label, or (3) in the production branch's history (keeps version-history links working). Everything else answers 404.
  • Short SHAs resolve to the full commit before pinning, so one commit pins one content instance.
  • Decisions (positive and negative) live in the short-TTL ref cache: repeated probes cost no GitHub calls, and removing the label revokes access within a TTL. Retryable failures (rate limit, 5xx) are never cached.
  • parseBranchName now rejects the pull/ and refs/ namespaces, so the label check can't be sidestepped via GitHub's hidden pull/<n>/head refs on /tree/.

/pr/:number shortcut

  • New landing-pr/docs-pr routes and /api/content/pr/[number]/[...path] endpoint: previews the PR's head commit under the same authorization rule, following new pushes like /tree follows a branch. Noindex + sitemap-excluded like the other preview modes; "Edit this page" is disabled (a fork branch can't be linked to an editor).

Workflow

  • .github/workflows/preview-comment.yml: sticky PR comment with the /pr/<number> links and a pinned /blob/<head sha> link. For unlabeled fork PRs it explains that a maintainer can add preview:enabled; the labeled/unlabeled triggers refresh the comment. Uses pull_request_target but never checks out or executes PR code.

Docs

  • Updated the versioned-previews concept page (new "Fork pull requests" section), the PR preview comments guide (label-aware workflow for consumers), and the preview-versions agent skill.

Notes for review

  • The upstream-history check uses one extra compare/{base}...{sha} API call, cached like the rest.
  • /blob/** is isr: true: a 404 for a not-yet-labeled fork commit may be cached at the edge until purge; the /pr/ route uses the short ISR TTL, so the workflow's primary links recover on their own once the label lands.

Verification

Ran locally: pnpm lint (no new warnings), pnpm test (140 tests pass, including new authorization boundary tests in test/preview-auth.test.ts), pnpm typecheck, pnpm build.

GitHub shares git objects across the fork network, so /blob/:sha would
render any fork PR's markdown on the docs domain with only a format
check. Commits now render only when they are in production history or
vouched for by a PR: same-repo PRs always, fork PRs only when a
maintainer adds the preview:enabled label. Decisions live in the
short-TTL ref cache, so removing the label revokes access within a TTL.

- /pr/:number and /pr/:number/<page> preview a PR's head commit under
  the same rule, following new pushes like /tree does for branches
- /tree rejects the hidden pull/ and refs/ namespaces so the label
  check can't be sidestepped via GitHub's pull/<n>/head refs
- blob previews resolve short SHAs to the full commit before pinning
- preview-comment workflow posts sticky PR comments with the links and
  tells fork contributors how a maintainer enables their preview
@vercel

vercel Bot commented Aug 23, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
comark-docs-layer Ready Ready Preview Aug 23, 2026 4:33pm

@pkg-pr-new

pkg-pr-new Bot commented Aug 23, 2026

Copy link
Copy Markdown
npm i https://pkg.pr.new/comarkdown/comark-docs@31

commit: 1ba3893

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.

1 participant