TLDR
- In Remix and React Router, every loader and action is its own endpoint, so a root loader redirect cannot protect child routes.
- Gate private paths at the request perimeter, then check again inside loaders and actions that touch customer data.
- Being signed in is not permission: tie record IDs in URLs to the current user's session and return 404 on a mismatch.
- Test with no cookie: request each private route as a page, as a data request and as a POST.
- Anything a loader returns reaches the browser, so return only what the page needs.
If you build on Remix or React Router framework mode (which includes Shopify Hydrogen), every route loader and every action is its own server endpoint. A login redirect in the root loader protects the page a person sees in the browser. It does not protect the data behind that page. Put your auth check at the request perimeter, check again inside loaders and actions that touch sensitive data, and then confirm the specific record belongs to the person asking.
We learned this on our own code in October 2026, during a security review of an internal sales tool we built on Hydrogen. The fix was planned and committed the same day, built around one shared helper. The lesson applies to any team building a private app on a framework that started life as a storefront.
Why a root loader check leaves data exposed
A full page load in Remix runs the root loader and the loaders for every matched route. If the root loader redirects an anonymous visitor to the login page, the browser never renders the product, cart or account screen. That looks like protection, and in a manual click-through it behaves like protection.
Client-side navigation works differently. Remix v2 fetches data for each route separately, using a URL with a ?_data= parameter that names one route. That request runs only the named route's loader. The root loader never runs, so its redirect never fires. The Remix FAQ is blunt about it: you cannot have a parent loader protect its child routes, because loaders run in parallel in separate requests, and each one needs its own check. React Router's current docs say the same thing for its .data requests.
In our case the pattern was easy to reproduce. A product URL redirected an anonymous browser to the login page. The same URL with the product route named in ?_data= returned the loader's JSON with a 200 status. Product data was the least sensitive part. The same root-only pattern covered routes that returned customer details, open draft orders used as quotes, cart contents and checkout state.
Actions have the same gap
Form actions are endpoints too. A few actions in the app created or updated customers, returned a stored signature image, or emailed a checkout link, and they trusted that the page around them had already checked the user. One action checked the session on its text message branch and skipped the check on its email branch. Nobody wrote that on purpose. It is what happens when auth lives in one place by habit instead of by design.
Why this happens on storefront-based apps
Hydrogen's starter code is built for a public store. Catalog and cart loaders are meant to answer anyone, so they ship without auth checks. When a team uses that same foundation for a private tool, such as a sales-rep app, a wholesale portal or a staff dashboard, the public assumptions come along. The developer adds a login gate in the root loader, sees the redirect work, and moves on.
In our opinion this is the most common way private Hydrogen and Remix apps leak data. Nothing in the code looks wrong. The gap only shows up when someone asks what a single loader returns when it is called on its own.
The fix: five layers, one helper
The developer handoff plan was written on October 28, 2026, and the fix was committed the same day. It touched the server entry, the root loader, a new shared helper and 15 route modules. Here is the structure, which works for any Remix or React Router app with private routes.
1. One shared guard that returns a clear answer
We wrapped the existing location check and session check in one function. It returns either "ok, here is the session" or "stop, send this response." Callers never have to guess whether the auth library returned a user, returned a redirect or threw one.
export async function requireSignedInRequest(context, request) {
if (!isProtectedPath(request.url)) {
return {ok: true, skipped: true};
}
const locationRedirect = await checkLocationCookie(context, request);
if (locationRedirect) return {ok: false, response: locationRedirect};
try {
const session = await checkSession(context, request);
if (session instanceof Response) return {ok: false, response: session};
return {ok: true, session};
} catch (error) {
// Expired sessions throw a redirect that also clears the cookie.
// Forward it as-is so the Set-Cookie header is not lost.
if (error instanceof Response) return {ok: false, response: error};
throw error;
}
}The code above is simplified from the real helper, with names changed. The detail worth copying is the catch block. If your auth library destroys an expired session and throws a redirect, that response carries a Set-Cookie header. Swallow it and users get stuck in a loop with a dead cookie.
2. A perimeter gate before the framework runs
In the Hydrogen server entry, we call the guard before handing the request to Remix. Every request to a protected path, whether it is a document, a ?_data= request or a form POST, has to pass. The allowlist is short and lives in one function: the login page, the store location picker, password reset and the dev server's ping route.
const loadContext = {session, waitUntil, storefront, env};
const access = await requireSignedInRequest(loadContext, request);
if (!access.ok) return access.response;
const handleRequest = createRequestHandler({
build: remixBuild,
mode: process.env.NODE_ENV,
getLoadContext: () => loadContext,
});This one change closes the ?_data= gap. We accepted one tradeoff on purpose: resource routes such as the sitemap also require a login now. For an internal tool that is correct. For a public site it would not be.
3. Checks inside the sensitive loaders and actions
The perimeter gate depends on an allowlist, and allowlists get edited. So we also call the same guard at the top of each loader and action that returns or changes customer data: draft order lists and search, cart, checkout, quotes, customer create and update, the signature image lookup, the checkout-link sender and the routes that change discounts or line items. If someone later widens the allowlist by mistake, those routes still refuse anonymous callers.
This also makes each sensitive file readable on its own. A reviewer opening the checkout route can see its protection on the first lines instead of tracing it back to the server entry.
4. Check the record, not only the person
Being signed in does not mean you may open every record. The quote routes loaded a draft order by the ID in the URL, so any signed-in rep could open any quote by changing the number. We now require the ID in the URL to match the quote stored in that user's session cookie. On a mismatch the route returns a plain 404, so it does not confirm that the other record exists. The one exception is the confirmation page shown right after a quote is created, which is allowed through by a one-time session flash set by the action that created it.
5. Strip private data from the root loader on public pages
The root loader still runs on the login and location pages, and it can also be called directly with ?_data=root. Before the fix, it could return customer and draft order details tied to a leftover cookie, even on those pages. Now, on any path that skips auth, the root loader returns only what those pages need to render and leaves the customer, quote and session fields empty.
How to test for this gap in your own app
You do not need a scanner. Open a private browser window, or use curl with no session cookie, and try these against your private routes:
The normal page URL. It should redirect to login.
The same URL as a data request. On Remix v2 add
?_data=with the route ID. On React Router 7 or later, request the.dataversion of the URL. It should also redirect or return 401 or 403, never JSON.A POST to each action that changes data or sends messages. It should be refused.
?_data=root, or the root data request, on your login page. It should contain nothing private.
Then sign in and repeat the risky cases with a real session. Change record IDs in URLs to ones that belong to someone else, and make sure they return 404. Finally, click around the signed-in app to confirm normal client-side navigation still works and you have not created a redirect loop.
A related habit: loader data is public
A few weeks later, in November 2026, we shipped a one-line hotfix on two Hydrogen storefronts that had a console.log of the full root loader data left in the root component. Anyone with the browser console open could read everything the root loader returned on every page. The data was already in the page for the app to use, so the log did not create a new leak. It did make it obvious how much the root loader was sending.
The general rule: anything a loader returns ends up in the browser. Treat every loader as a public API response, and return only what the page needs.
If you are on React Router 7 or upgrading
Hydrogen moved from Remix to React Router 7 in 2025, and Remix v2 reached end of life when React Router v8 shipped on June 17, 2026. If your app is still on Remix v2, the upgrade is worth planning for security patches alone.
React Router middleware gives you a cleaner home for the perimeter check, and you still need the other layers. Server middleware on the root route or a shared parent route runs before loaders and actions for both document requests and .data requests, so it can replace a hand-written perimeter gate in the server entry. The React Router docs are clear that middleware handles shared checks, while any permission it does not enforce still has to be checked in the individual loader or action. Our record-level quote check would stay in the route either way.
When this is more than you need
A public storefront does not need auth on product, collection or search loaders. That data is meant for everyone. The layers above matter once any route returns customer data, staff data, pricing that should stay private, or anything that changes state. Most real stores have at least a few of those, such as account pages, B2B pricing or internal tools sharing the same codebase.
How we know and limits
How we know: This post is based on a security review of a Hydrogen sales-rep app we built and maintain for a multi-location retailer (client anonymized), the developer handoff plan for the fix, and the fix itself, all committed on October 28, 2026, plus a November 2026 hotfix on two Hydrogen storefronts. Framework behavior is from the current Remix v2 FAQ and React Router documentation, checked on November 23, 2026.
Limits: The app runs Remix v2 with the older ?_data= data requests, deployed on Shopify Oxygen. Apps on React Router single fetch use .data URLs and can use middleware, so the code looks different. This post covers the design flaw and the fix. It makes no claim either way about whether anyone used the gap. We describe one app and one fix, not an audit of other teams' code. Last reviewed November 23, 2026.
Sources
Remix v2 FAQ: How can I have a parent route loader validate the user and protect all child routes? (Remix, accessed November 23, 2026)
React Router: Data Loading, Authentication and Authorization (React Router docs, accessed November 23, 2026)
React Router: Middleware (React Router docs, accessed November 23, 2026)
React Router v8 announcement (Remix blog, June 17, 2026)
Hydrogen May 2025 Release: upgrade from Remix 2 to React Router 7 (Shopify, May 21, 2025)
If you run a private app or a B2B portal on Hydrogen and want a second set of eyes on how it handles auth, our Shopify Hydrogen development team can review it with you.
