fix(vtex,blocks): prevent caching authenticated proxy responses (cross-user data leak) - #413
Open
JonasJesus42 wants to merge 1 commit into
Open
fix(vtex,blocks): prevent caching authenticated proxy responses (cross-user data leak)#413JonasJesus42 wants to merge 1 commit into
JonasJesus42 wants to merge 1 commit into
Conversation
…s-user leak) Authenticated VTEX proxy responses (/account, /api/sessions, /api/oms/user/orders) could be served with `Cache-Control: public` and cached at shared edge layers, leaking one user's orders/data to another. Root cause was threefold (see #412): - apps-vtex/utils/proxy.ts: neither proxyToVtex nor createVtexCheckoutProxy normalized Cache-Control, so the raw origin directive (or a public listing profile) passed through. Now force `private, no-store` + `CDN-Cache-Control: no-store` on authenticated proxy responses by default (opt-out via hardenAuthenticatedCache), exempting static assets. - apps-vtex/utils/vtexId.ts: extractVtexAuthCookie ignored the account-suffixed cookie variant, and parseVtexAuthToken treated opaque (non-JWT) tokens as logged-out — so isLoggedIn was false for real sessions and any logged-in cache bypass never fired. Match the suffixed variant and treat a present opaque token as logged-in. - blocks/sdk/cacheHeaders.ts: PRIVATE_PREFIX_RE missed `myaccount` and pt-BR account routes, letting them fall through to the cacheable `listing` default. Cover them. Refs #412 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes/refs #412.
Problem
Authenticated VTEX responses routed through the proxy (
/account,/api/sessions,/api/oms/user/orders) could be served withCache-Control: publicand cached at shared edge layers (Cloudflare/CloudFront), leaking one user's orders/data to another. Confirmed in production on a proxied storefront.Fixes
utils/proxy.ts:proxyToVtexandcreateVtexCheckoutProxynow forceCache-Control: private, no-store, no-cache, must-revalidate+CDN-Cache-Control: no-storeon authenticated proxy responses by default (opt-out viahardenAuthenticatedCache: false), exempting genuinely public static assets (/files,/arquivos,/assets/vtex,/XMLData).utils/vtexId.ts:extractVtexAuthCookienow also matches the account-suffixed cookieVtexIdclientAutCookie_{account}, andparseVtexAuthTokentreats a present opaque (non-JWT) token as logged-in. PreviouslyisLoggedInwasfalsefor real sessions, so any logged-in cache bypass never fired.sdk/cacheHeaders.ts:PRIVATE_PREFIX_REnow coversmyaccountand pt-BR account routes (minha-conta,meus-pedidos,pedidos) so they don't fall through to the cacheablelistingdefault.Notes
Cache hardening is on by default — this changes behavior for existing proxy consumers, which is the intended safe default for authenticated endpoints. Static assets remain cacheable. Site-side workaround already deployed at deco-sites/bagaggio-tanstack#278.
Summary by cubic
Prevents caching of authenticated VTEX proxy responses to stop cross-user data leaks. Forces private/no-store headers by default, fixes auth detection, and expands private route patterns.
Bug Fixes
apps-vtex: Inutils/proxy.ts,proxyToVtexandcreateVtexCheckoutProxynow setCache-Control: private, no-store, no-cache, must-revalidateandCDN-Cache-Control: no-storefor non-static responses; static asset prefixes/files,/arquivos,/assets/vtex,/XMLDataare exempt.apps-vtex: Inutils/vtexId.ts,extractVtexAuthCookiematches the account-suffixed cookie;parseVtexAuthTokentreats opaque (non-JWT) tokens as logged in to ensure cache bypass works.blocks: Insdk/cacheHeaders.ts,PRIVATE_PREFIX_REnow coversmyaccount,minha-conta,meus-pedidos, andpedidosto prevent account pages from being edge-cached.Migration
hardenAuthenticatedCache: falsetoproxyToVtexorcreateVtexCheckoutProxy.Written for commit a98acd0. Summary will update on new commits.