AL+

Language: RO (română) EN (English)

Email us: paul@alplustech.com

Measure Rails CSRF fallback before tightening the policy

Plan a Rails Fetch Metadata migration around missing-header clients, trusted cross-site flows and fallback events, while keeping API authorization separate.

Citiți articolul în română

A stricter CSRF policy is easier to adopt when you know which legitimate requests it will reject. Rails' move toward Fetch Metadata makes that compatibility question visible: modern browser headers can replace token checks in some circumstances, while older or altered request paths still need attention. The migration decision should follow evidence about those paths, with an explicit trust boundary for cross-site flows.

The 19 December 2025 Rails digest describes header_only and header_or_legacy_token, alongside notification events for fallback and blocked requests. The underlying PR 56350 was opened and merged into main on 12 December. This was work for Rails 8.2; the digest does not establish a stable December release containing the API.

Begin with the requests you actually support

An application can have several legitimate ways to reach the same state-changing endpoint. A browser form may travel directly through the normal ingress, while an older embedded client or an intermediary sends a request with different metadata. Listing those paths is a prerequisite for assessing compatibility. Calling all traffic “browser traffic” conceals the differences that decide whether a strict policy fits.

A missing header also deserves investigation rather than an automatic explanation. It can reflect an older client or a proxy that removes metadata. It does not establish that the request is malicious, and it does not make accepting the request safe. A secure migration needs a defined response to missing information. That response can differ from the handling of an explicitly cross-site request.

The policy names describe the relevant choice. In the December design, header-only checking rejects requests without acceptable metadata; the compatibility strategy retains legacy token checking where the header cannot make the decision. Teams should understand the exact behavior in the version they run before changing configuration. A strategy name is a starting point for review, not a substitute for reading the implementation and its documentation.

Treat fallback as migration evidence

The digest names csrf_token_fallback.action_controller. Where the deployed version provides that event, it offers a way to identify requests still relying on legacy verification. A migration plan can use such observations to locate compatibility work. The useful question is which legitimate path caused the fallback, rather than whether the overall count looks small enough to ignore.

A proposed observation record can describe the endpoint, client class and relevant ingress behavior without recording session tokens or credentials. That gives maintainers a route to reproduce the condition while limiting what enters logs. An aggregate count alone can miss a rarely used but essential flow. Conversely, a busy automated client can dominate a total without representing a large group of users.

This is an operating proposal, not a report of measurements from an AL+ application. No event stream was collected and no client population was tested. Before using it, a team needs to confirm that its Rails version exposes the event and understand what that version emits. Otherwise, an absent observation could be mistaken for proof that no compatibility problem exists.

Same-site is a broader boundary

The PR's design accepts both same-origin and same-site metadata. This describes the Fetch Metadata decision; the PR leaves the separate Origin check unchanged and combines it with metadata or token verification. Those relationships are different. Separate subdomains can be same-site while remaining different origins. A policy that trusts same-site traffic therefore does not, by that fact alone, isolate one subdomain from another. The trust decision includes what runs on the related subdomains and who can control it.

The current edge API documentation is useful for checking the evolving interface, but it is moving main-branch documentation. It cannot prove what a particular stable installation contains. This article offers no copy-and-paste configuration because stable-version inclusion was not independently established here. A real migration should use documentation and code matching the locked application version.

Legitimate cross-site flows deserve a narrow review of their own. Authentication callbacks or third-party embeds can require explicit treatment. Adding a trusted origin changes the accepted request boundary; it is not merely a compatibility convenience. Describe which flow needs the exception and which endpoint receives it. A broad exception adopted to silence a warning can outlive the integration that originally motivated it.

Keep authorization in its own place

Fetch Metadata helps a server reason about the browser context that initiated a request. It does not establish a caller's entitlement to a customer's records or a tenant's export. Non-browser clients can construct headers, and browser-origin checks do not replace application permissions. A request that passes CSRF verification still needs the relevant authentication and authorization decisions.

That distinction is particularly important when someone calls an endpoint an API and proposes removing protection. The label does not establish whether the endpoint uses ambient browser credentials. Review the actual credential and request model. Any alternative protection needs to fit that model, rather than rely on a header as a general identity assertion. Nothing in this migration argument justifies weakening an unrelated access check.

A controlled browser estate can move faster

The strongest counterargument to a long compatibility period is an application with only modern browsers, controlled ingress and well-understood integrations. It may be able to adopt strict checking quickly. Keeping legacy fallback indefinitely would then add complexity without serving a legitimate client. The sensible pace depends on evidence about the supported environment.

Even that case benefits from a clear acceptance decision. Identify the supported paths, confirm their metadata reaches the application and document intentional exceptions. For custom software development, make that part of the migration scope and handover. A successful change is a policy whose legitimate traffic and trust boundary are understood, with fallback removed when the application can support that decision.