The Shared Redirect Pattern¶
Learning objectives
- Why federated sign-in quietly turns "create a customer" into a manual console task
- How one fixed redirect address per region replaces an unbounded per-customer list
- What has to travel in the
stateparameter for that to be safe — and what must never be trusted from it - Why the relay hop is the most attackable point in the design, and the small set of rules that defends it
The hidden manual step in federated sign-in¶
Federated sign-in — "sign in with the identity you already have" — rests on a strict contract: the identity provider will only ever redirect a browser back to an address that was registered with it in advance, exactly, character for character. No wildcards. This is a good rule; it is what stops an attacker from pointing a stolen authorization at a server they control.
Now give every customer their own isolated sign-in realm, which is the right architecture for strong tenant isolation. Each realm has its own callback address — so each new customer means registering one more address with every identity provider you broker to. Some providers offer an API for that list; some offer only a web console and a human with a clipboard. All of them cap the list's length.
The result is a scaling failure that produces no error message: onboarding works, isolation works, and yet somewhere in the middle of "provision a customer" there is a person pasting URLs into a console, and a ceiling you will eventually hit no matter how disciplined that person is.
Inverting the problem: one address, forever¶
The pattern that removes the manual step is used by some of the largest authentication platforms in production today. Instead of registering every realm's callback address, you register one fixed relay address per region — and never touch the list again.
Every realm's sign-in flow sends the provider that same relay address. The
information about which realm the flow belongs to — the thing the
per-realm address used to encode — moves into the state parameter, which
the provider passes through the round-trip untouched.
The relay itself is a small, stateless endpoint: it receives the provider's redirect, works out the destination realm from the state, and forwards the browser — authorization code intact — to that realm's real callback. The provider's registered list holds one entry per region, permanently, no matter how many customers exist.
The state is now load-bearing — treat it that way¶
Moving routing information into the state parameter changes its job. It used to be an opaque CSRF token; now it decides where an authorization code gets delivered. That makes its integrity the whole security story:
- Seal it. The state must be integrity-protected — signed by the party that created it, verified by the relay in constant time. A state the relay cannot verify is a request the relay refuses.
- Validate the destination against a strict shape. The realm name inside a verified envelope still gets checked against a tight pattern before it is used to build a forward address.
- Never build the forward target from request input. The relay knows its own region's sign-in host from configuration fixed at deploy time. The state selects a realm within that host — it can never select the host. This one rule is what makes the relay physically incapable of forwarding a sign-in across regions, and it is what separates a relay from an open redirector.
- Keep code-interception protection in the flow. The modern challenge mechanism that binds an authorization code to the client that requested it must survive the relay hop untouched — it is doing isolation work.
Anonymous, but not unguarded¶
There is one more uncomfortable property to design for: the relay endpoint must accept unauthenticated traffic, because the browser arriving from the identity provider carries no session with your platform yet. An anonymous endpoint at the edge of a zero-trust system deserves suspicion, and the answer is not to skip the policy layer but to encode the exception precisely: the policy that governs public paths allows this endpoint by exact match only — not by prefix — with a regression test asserting that its sub-paths stay denied. The endpoint itself answers anything malformed with a terse failure, never a helpful redirect.
What the pattern buys¶
The per-customer console task is gone; the provider-side list stops growing; the length cap stops mattering. And because every piece of the relay is explicit — a sealed envelope, an exact-match policy entry, a configuration-fixed forward host — the design reviews well: each rule maps to a specific attack it forecloses.
The takeaway
When a provider makes you register callback addresses one at a time, don't scale the list — collapse it. One fixed relay address per region, a sealed state envelope that selects the realm, a forward host fixed by configuration, and an exact-match policy exception. Registration stops being part of onboarding, and every security property you gave up by sharing an address comes back as an explicit, testable rule.