Skip to content

Add turnstile token to subscription#810

Open
cocomarine wants to merge 8 commits intomainfrom
1353-add-turnstile-token-to-subscription
Open

Add turnstile token to subscription#810
cocomarine wants to merge 8 commits intomainfrom
1353-add-turnstile-token-to-subscription

Conversation

@cocomarine
Copy link
Copy Markdown
Contributor

@cocomarine cocomarine commented May 6, 2026

Part of https://github.com/RaspberryPiFoundation/digital-editor-issues/issues/1353
(frontend PR: https://github.com/RaspberryPiFoundation/editor-standalone/pull/859)

Notes

  • Generated turnstile secret keys for staging and prod in Cloudflare and added them as CLOUDFLARE_TURNSTILE_SECRET_KEY to config var using terraform
  • Updated .env.example to reflect this

Co-authored-by: Copilot <copilot@github.com>
@cla-bot cla-bot Bot added the cla-signed label May 6, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 6, 2026

Test coverage

89.84% line coverage reported by SimpleCov.
Run: https://github.com/RaspberryPiFoundation/editor-api/actions/runs/25504867221

@cocomarine cocomarine temporarily deployed to editor-api-p-1353-add-t-qbuyad May 7, 2026 08:10 Inactive
@cocomarine cocomarine temporarily deployed to editor-api-p-1353-add-t-pmdvip May 7, 2026 10:37 Inactive
Co-authored-by: Copilot <copilot@github.com>
@cocomarine cocomarine temporarily deployed to editor-api-p-1353-add-t-ojj2th May 7, 2026 14:21 Inactive
@cocomarine cocomarine marked this pull request as ready for review May 7, 2026 14:37
Copilot AI review requested due to automatic review settings May 7, 2026 14:37
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds Cloudflare Turnstile bot-protection to the subscriptions endpoint by accepting a turnstile_token in the request and verifying it server-side (with fail-open behavior on upstream/network errors), supporting issue RaspberryPiFoundation/digital-editor-issues#1353.

Changes:

  • Add turnstile_token to subscription request payloads and add request specs covering success/failure/fail-open scenarios.
  • Add Turnstile verification before_action to Api::SubscriptionsController#create using Cloudflare’s siteverify endpoint.
  • Add application configuration and example env var for the Turnstile secret key and enablement flag.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
spec/requests/api/subscriptions_spec.rb Extends subscription request payload and adds Turnstile integration request specs (failure + fail-open cases).
app/controllers/api/subscriptions_controller.rb Enforces Turnstile verification (when enabled) before processing subscription creation.
config/application.rb Adds config.x.cloudflare_turnstile secret + enablement derived from env.
.env.example Documents CLOUDFLARE_TURNSTILE_SECRET_KEY for local/testing setup.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread app/controllers/api/subscriptions_controller.rb
Comment thread app/controllers/api/subscriptions_controller.rb Outdated
Comment thread app/controllers/api/subscriptions_controller.rb
Comment thread .env.example Outdated
@cocomarine cocomarine temporarily deployed to editor-api-p-1353-add-t-ld5hgs May 7, 2026 15:12 Inactive
@cocomarine cocomarine temporarily deployed to editor-api-p-1353-add-t-ld5hgs May 7, 2026 15:17 Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants