Repository navigation
fix(core): bypass refresh-token flow on WebOps preview hosts - #3533
Conversation
WebOps previews (`*.preview.vtex.app`) do not proxy VTEX ID, so
`/api/vtexid/refreshtoken/webstore` answers 405 there. With
`experimental.refreshToken` on, the first ValidateSession after pasting a
`VtexIdclientAutCookie_<account>` forced a refresh, the refresh failed and
`logoutAndClearSession` wiped the pasted cookie.
Add `shouldBypassRefreshToken` (plus a browser variant) that matches
localhost/127.0.0.1 and `*.preview.vtex.app`, and use it wherever the
refresh flow was skipped only for localhost: the ValidateSession guard in
`/api/graphql`, both refresh paths in `validateSession`, `useRefreshToken`
and the 403 page. `{account}.vtex.app` stays out of the bypass because it is
a production default domain.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. |
DK Review — Audit SummaryVerdict: ❌ BLOCKED
Only BLOCK and RESTRICT findings anchored to a changed line are commented inline on the diff. The other finding below opens no review thread. Scenarios evaluated: feature-flags, general-review, quality-ratchet
📋 Findings (3)BLOCK
RESTRICT
SUGGEST
DK Review v1.0.0 | To dismiss a finding: reply |
…Session Sonar flagged the cognitive complexity of the `/api/graphql` handler (26) and `validateSession` (20). Move the ValidateSession refresh-token guard and the success cache-control into their own functions in the handler, and the refresh-token condition and deliveryPromise postal-code sync into their own functions in the session SDK. The guard now checks the operation and the flag before parsing the hostname. Also read `globalThis.window` in the browser bypass helper, normalize the hostname once, and drop `isLocalHostBrowser`, which has no callers left. Add tests for the success cache-control paths that moved. Co-Authored-By: Claude Opus 5.5 <[email protected]>
@faststore/api
@faststore/cli
@faststore/components
@faststore/core
@faststore/diagnostics
@faststore/lighthouse
@faststore/sdk
@faststore/ui
commit: |
…helper Co-Authored-By: Claude Opus 5.5 <[email protected]>
Behind the WebOps preview ingress the browser host arrives in `x-forwarded-host`, not `Host`, so the server-side checks in `/api/graphql` and the account 403 page could miss a preview and still force the refresh. `shouldBypassRefreshTokenForRequest` checks both headers (a multi-value `x-forwarded-host` is ignored). The hostname check now reuses `isHostAllowed` and ignores a trailing dot. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Each beforeEach waited for a request call that only earlier tests or the module load had made. A top-level beforeAll now waits for the initial validation once, and each test resets the request mock explicitly. Co-Authored-By: Claude Opus 5.5 <[email protected]>
#3525 adds `isB2BSession` to `src/sdk/account/refreshToken`, which the #3533 tests mock without it. Whichever of the two merges second needs the same mock change. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|

0 New Issues
0 Fixed Issues
0 Accepted Issues
What's the purpose of this pull request?
Pasting a
VtexIdclientAutCookie_<account>into a WebOps preview to test logged-in areas should work with just the paste.Right now, with
experimental.refreshTokenon, the firstValidateSessionafter the paste fails: there is a JWT and norefreshAfter, so/api/graphqlanswers 401. The client then calls/api/vtexid/refreshtoken/webstore. Previews do not proxy VTEX ID, so that call answers 405, the refresh fails, andlogoutAndClearSessioncalls/api/fs/logout, which deletes the pasted cookie. The current workarounds are settingrefreshAfterby hand in IndexedDB or blocking/api/fs/logoutin devtools.Localhost already skips this flow (#3325). This PR extends the same bypass to
*.preview.vtex.app.How it works?
src/utils/shouldBypassRefreshToken.tswithshouldBypassRefreshToken(hostname)andshouldBypassRefreshTokenBrowser(). They return true forlocalhost/127.0.0.1(viaisLocalHost) and for hosts ending in.preview.vtex.app.shouldBypassRefreshTokenForRequest(headers)checks theHostheader and a singlex-forwarded-host, because the preview ingress sends the browser host inx-forwarded-host.{account}.vtex.appdoes not match. It is a production default domain and keeps the refresh flow.isLocalHost/isLocalHostBrowserat the five places that skip the refresh flow:src/pages/api/graphql.ts: forced 401 onValidateSessionsrc/sdk/session/index.ts: refresh whenrefreshAfterexpired, and refresh after a 401src/sdk/account/useRefreshToken.tssrc/pages/pvt/account/403.tsx:needsRefreshTokenisLocalHoststays as it is for other uses.Security notes
Hostheader or a singlex-forwarded-host, and a client controls both. SendingHost: x.preview.vtex.app(or thatx-forwarded-host) to a production store only skips the forced 401 onValidateSession. That is already possible today withHost: localhost, and it grants nothing: the JWT is still validated upstream.How to test it?
experimental.refreshToken: true.VtexIdclientAutCookie_<account>and reload./api/vtexid/refreshtoken/webstoreand no/api/fs/logout.{account}.vtex.app) the refresh flow behaves as before.Unit tests:
test/utils/shouldBypassRefreshToken{,.browser}.test.ts: localhost, 127.0.0.1, preview host,{account}.vtex.app→ false, custom domain → false, lookalike suffixes → falsetest/pages/api/graphql.test.ts:ValidateSessionis not forced to 401 on local/preview hosts and still is on production hoststest/sdk/session/validateSession.browser.test.ts: both refresh paths skip on local/preview hosts and still run on production hoststest/sdk/account/useRefreshToken.browser.test.ts(new): no refresh or logout on local/preview hoststest/pages/pvt/account/403.test.ts(new):needsRefreshTokenis false on local/preview hostsApproval
This touches the authentication flow. Per AGENTS.md (Security & Data Handling), this change was explicitly approved by Larícia Mota on 2026-10-21.
🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
Tests