Skip to content

feat(cms): sign in through Cloudflare Access with a GitHub App proxy - #20

Merged
comdotlinux merged 2 commits into
mainfrom
feat/cms-access-auth
Nov 15, 2026
Merged

comdotlinux merged 2 commits into
mainfrom
feat/cms-access-auth

Conversation

@comdotlinux

Copy link
Copy Markdown
Owner

Do not merge until the GitHub App exists and the four Production settings are in the blog-cms Pages project (cms/README.md, "One-time setup"). Without them every /gh/ call answers 503 and the editor cannot load posts.

What

  • cms/functions/gh/[[path]].ts: Pages Function on /gh/*, the only path from Sveltia to GitHub.
    • Same-origin check (Sec-Fetch-Site, else Origin).
    • Access JWT from Cf-Access-Jwt-Assertion or the CF_Authorization cookie: RS256 only, key by kid from the team certs (5 min cache, refetch on unknown kid at most every 30 s), aud, iss, exp, nbf (60 s skew), email equal to OWNER_EMAIL.
    • Path decoded once; rejects .., ., empty segments, encoded slashes, double encoding, control chars; allows only /user, /repos/comdotlinux/blog/**, /graphql.
    • Writes: allow-list of what Sveltia's editorial workflow sends. No DELETE, no PR merge, ref PATCH only under heads/cms/. GraphQL: root mutations limited to createCommitOnBranch (branch cms/ only), createRef (refs/heads/cms/ only), convertPullRequestToDraft, markPullRequestReadyForReview, disablePullRequestAutoMerge; fragment spreads, directives and inline arguments at the mutation root are refused; the parsed body is what gets forwarded.
    • GitHub App installation token minted with WebCrypto, cached in memory, re-minted under 5 min left. Never forwards Cookie, Cf-* or the incoming Authorization; responses carry Cache-Control: no-store. Logs fixed text and status codes only.
    • Shims: GET /user from the public comdotlinux profile; permissions.push added to the repo response (installation tokens get neither).
    • Missing or invalid GITHUB_APP_ID, GITHUB_APP_INSTALLATION_ID, GITHUB_APP_PRIVATE_KEY (PKCS#8), OWNER_EMAIL: 503 "CMS GitHub App not configured".
  • cms/public/auth.html: static popup answering Sveltia's handshake with the placeholder token cf-access; postMessage only to location.origin.
  • cms/public/admin/config.yml: base_url, auth_endpoint: auth, api_root (proxy), auth_methods: [oauth]. cms/test/unit/config.test.ts backend assertion extended for these keys (owner-approved edit).
  • Tests: access-jwt.test.ts, gh-proxy.test.ts, auth-page.test.ts (generated RSA keys, fake JWKS, mocked GitHub), e2e auth.spec.ts (real Sveltia from the CDN, stubbed /gh/: the /user call carries token cf-access, no request goes to api.github.com, no access-token field).
  • Docs: cms/README.md (how sign-in works, owner setup steps), cms/AGENTS.md, root CLAUDE.md.

Checks

Root gate: lint 0 errors, build 27 pages, unit 75, e2e 96, Lighthouse 99.6% avg. CMS: format clean, unit 159, integration 2, e2e 2. Local wrangler pages dev on a copy of cms/: Functions compile; 503 without settings, 401 without or with a forged JWT, 403 cross-site.

Not verified (needs the App and a deploy)

  • Pages builds cms/functions with root cms, no build command, SKIP_DEPENDENCY_INSTALL=1.
  • Access injects the JWT header or cookie on /gh/* requests.
  • Installation-token behaviour of /user and repo permissions (shims assume the documented 403 and missing field).
  • End-to-end save of a post through the real GitHub API.

https://claude.ai/code/session_01426xQEC2VhQSZVe7cBXuz5

Sveltia's GitHub calls go to a same-origin Pages Function that verifies
the Access JWT (RS256, kid, aud, iss, exp, nbf, owner email) and forwards
an allow-list of paths, writes and GraphQL mutations with a GitHub App
installation token held in memory. No DELETE, no merges, commits only on
cms/ branches. The sign-in popup (auth.html) completes Sveltia's
handshake with a placeholder token, so no GitHub credential reaches the
browser. Missing settings fail closed with 503.

Claude-Session: https://claude.ai/code/session_01426xQEC2VhQSZVe7cBXuz5
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

Deploying blog with  Cloudflare Pages  Cloudflare Pages

Latest commit: f826aed
Status: ✅  Deploy successful!
Preview URL: https://5dbc4ff1.blog-7qk.pages.dev
Branch Preview URL: https://feat-cms-access-auth.blog-7qk.pages.dev

View logs

Reject %2E and %5C as well as %2F in proxied paths, build the upstream
URL by concatenation onto the fixed api.github.com origin, stop passing
GitHub's Link header (its /repositories/<id>/ links 404 behind the
proxy), and redirect /gh/comdotlinux/blog/... (Sveltia's "View on
GitHub" links) to github.com. Tests for each path and write rule, query
forwarding and the User-Agent on every upstream call. README: Publish is
refused, reload after the 24 h Access session, keep the key until the
live check passes.

Claude-Session: https://claude.ai/code/session_01426xQEC2VhQSZVe7cBXuz5
@comdotlinux
comdotlinux marked this pull request as ready for review November 15, 2026 16:19
@comdotlinux
comdotlinux merged commit 9a95ab5 into main Nov 15, 2026
8 checks passed
@comdotlinux
comdotlinux deleted the feat/cms-access-auth branch November 15, 2026 16:19
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