Skip to content

feat: gate the site behind Cloudflare Turnstile - #13

Merged
comdotlinux merged 1 commit into
mainfrom
feat/turnstile-gate
Nov 12, 2026
Merged

comdotlinux merged 1 commit into
mainfrom
feat/turnstile-gate

Conversation

@gurukulkarni

Copy link
Copy Markdown
Collaborator

Gate the whole blog behind Cloudflare Turnstile, ported from the bio repo.

  • functions/_middleware.ts (Pages Functions) serves a self-contained challenge page (401, noindex) to page loads without a valid blog_session cookie, and a bare 401 to other requests.
  • functions/api/verify-turnstile.ts verifies the token with Cloudflare siteverify and sets blog_session (HMAC-SHA256 signed with TURNSTILE_SECRET_KEY, HttpOnly; Secure; SameSite=Lax, 24 h).
  • Public without the cookie: /api/*, /rss.xml, sitemaps, /robots.txt, favicons, /og.png, /astropaper-og.jpg, /posts/<slug>/index.png and the pre-v7 OG PNG.
  • PREVIEW=true (set on the Preview environment) leaves preview deployments open. A missing secret fails closed (500).
  • Accepted trade-off: search engines and link-preview bots can no longer read post pages.

Cloudflare (already configured): new Turnstile widget blog (managed, blog.kulkarni.cloud + blog-7qk.pages.dev); Pages project blog has TURNSTILE_SITE_KEY and TURNSTILE_SECRET_KEY on Production and PREVIEW=true on Preview.

Local checks: lint 0 errors, build 27 pages, unit 71 passed (21 new in tests/functions/turnstile.test.ts), e2e 96 passed, Lighthouse 99.8% avg. Functions do not run locally, so e2e and Lighthouse exercise the ungated site.

After merge: curl -sI https://blog.kulkarni.cloud/ should return 401, /rss.xml 200, and passing the widget in a browser should load the blog.

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying blog with  Cloudflare Pages  Cloudflare Pages

Latest commit: 5ecadc4
Status: ✅  Deploy successful!
Preview URL: https://0093d005.blog-7qk.pages.dev
Branch Preview URL: https://feat-turnstile-gate.blog-7qk.pages.dev

View logs

@comdotlinux
comdotlinux merged commit 28e0983 into main Nov 12, 2026
2 checks passed
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