Repository navigation
Releases
Releases · kokorono-group/rails-cloudflare-origin
v0.1.0
Immutable
release. Only release title and notes can be modified.
First release.
A Rack middleware, installed by a Railtie at the top of the middleware stack, for Rails apps served through Cloudflare:
- Refuses requests that did not come through Cloudflare (403,
cache-control: no-store), using an origin secret a Cloudflare Transform Rule adds. AGET/HEADof/upwithoutCF-Raystays open for the platform's health check. - Removes
Forwarded,Client-IP,X-Forwarded-For,X-Real-IPandX-Forwarded-Hoston every request, so no visitor-sent header can choose the client IP or make Rails raiseIpSpoofAttackError. - Sets
REMOTE_ADDRfromCF-Connecting-IP, sorequest.ipandrequest.remote_ipboth return the visitor. A verified request without a validCF-Connecting-IPis reported toRails.errorand raises. - Reads the current and previous secret from
CLOUDFLARE_ORIGIN_SECRET(_PREVIOUS)or from credentials, so the secret rotates without downtime. Installs only when a current secret is set, never in development or test.
Requires Ruby 4.0+ and Rails 8.1+. See the README for the Cloudflare setup it assumes.