Repository navigation
fix(core): let an empty api.subDomainPrefix replace the default - #3577
Conversation
deepmerge concatenates arrays, so the default ['www'] was always kept and a store setting api.subDomainPrefix: [] still ended up with ['www']. That made the commerce client strip "www." from X-FORWARDED-HOST, so Checkout cookies were set on the root domain and duplicated the ones set on www. Merge discovery configs through a helper that takes the store value for subDomainPrefix as is. Other arrays keep being concatenated. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
DK Review — Audit SummaryVerdict:
Only BLOCK and RESTRICT findings anchored to a changed line are commented inline on the diff. The other 3 findings below open no review thread. Scenarios evaluated: feature-flags, general-review, quality-ratchet 📋 Findings (4)RESTRICT
SUGGEST
DK Review v1.0.0 | To contest a finding, reply in its thread |
Addresses the Sonar finding on mergeDiscoveryConfig. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@faststore/api
@faststore/cli
@faststore/components
@faststore/core
@faststore/diagnostics
@faststore/lighthouse
@faststore/sdk
@faststore/ui
commit: |
| function mergeDiscoveryConfig(target, source) { | ||
| return deepmerge(target, source, { | ||
| customMerge: (key) => (OVERRIDE_KEYS.has(key) ? overwrite : undefined), | ||
| }) |
There was a problem hiding this comment.
[Functional.Logic] 🟡 RESTRICT
deepmerge's customMerge callback is invoked with only the bare key name, not the full path, so OVERRIDE_KEYS.has(key) matches ANY key named 'subDomainPrefix' anywhere in the merged tree, not just api.subDomainPrefix. If the discovery config schema ever gains another field with that same name nested elsewhere (e.g. under a future cdn or routes section), it would silently be replaced instead of merged, diverging from deepmerge's normal behavior without any indication at the call site.
Action: Scope the override to the intended path, e.g. by checking the full key path (some deepmerge versions/wrappers expose it) or by pre-merging only the api subtree with the override logic and deepmerge-ing the rest normally.
To contest this finding, reply in this thread
Overriding every subDomainPrefix value changed the behavior of stores that set a custom prefix (e.g. ['shop']) and still relied on 'www' being appended. Now only [] replaces the default; any other value is appended to ['www'] as before, so existing configs keep working. Also warn at build time when subDomainPrefix is [] and secureSubdomain is on another host, since Checkout cookies set on the storefront host are not sent to it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
| const mergeSubDomainPrefix = (target, source) => | ||
| Array.isArray(source) && source.length === 0 | ||
| ? source | ||
| : deepmerge(target, source) |
There was a problem hiding this comment.
[general.security-guidance] 🟡 RESTRICT
This PR is what actually enables api.subDomainPrefix: [] to take effect (previously deepmerge's array concatenation meant an empty array merged with the default ['www'] had no effect). Clearing this list changes where Checkout authentication cookies are scoped across subdomains — a security-sensitive, auth-cookie-adjacent change. Root AGENTS.md requires explicit human approval recorded in the PR description for modifications to authentication-related mechanisms; the only safeguard shipped here is a build-time console.warn.
Action: Confirm and note in the PR description that this change to cross-subdomain cookie scoping was reviewed/approved per the root AGENTS.md Security & Data Handling policy, or clarify why it falls outside that policy's scope.
To contest this finding, reply in this thread
| } | ||
|
|
||
| const getHostname = (url) => { | ||
| try { |
There was a problem hiding this comment.
[general.error-handling] 🟡 RESTRICT
getHostname swallows any URL parsing error silently (empty catch, no logging), so a malformed/missing storeUrl or secureSubdomain causes getSubDomainPrefixWarning to just return undefined with no signal that the config is actually broken. A store that typos secureSubdomain (e.g. omits the protocol) will get no cross-subdomain-cookie warning at all, even though the underlying misconfiguration is exactly the kind of thing this warning exists to catch.
Action: Log a distinct diagnostic (or include the parse failure in the returned warning) when storeUrl/secureSubdomain are present but fail to parse, instead of treating parse failure the same as "nothing to warn about".
To contest this finding, reply in this thread
…lid URLs Apply the empty-array override only to api.subDomainPrefix instead of any key with that name, and make the build warning report a storeUrl or secureSubdomain that cannot be parsed instead of silently skipping it. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Sonar was reporting 47.5% coverage on new code even though the unit tests cover mergeDiscoveryConfig.js fully: other test files load that module through discovery.config.js, and the coverage of the lines only exercised by its own test was lost when the reports were merged. Keep the warning in a module that only next.config.js and its own test load, so its coverage is reported correctly. Behavior is unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
| }) | ||
|
|
||
| it('only clears subDomainPrefix under api', () => { | ||
| const config = mergeDiscoveryConfig( |
There was a problem hiding this comment.
[Evolvability.SolutionApproach] 🟡 RESTRICT
The tests show mergeDiscoveryConfig hardcodes a domain-specific exception for the single path api.subDomainPrefix (empty array ⇒ clear, non-empty ⇒ append), while an identically-shaped other.subDomainPrefix field at a different path is merged by plain concatenation instead. A generic config-merging utility now carries field-path-specific knowledge, so every future field needing 'clear with empty array' semantics will require another hardcoded branch in the same generic utility, and the inconsistent array semantics (same value shape, different merge rule depending on key path) is easy to misuse by accident.
Action: Extract the 'clearable array' semantics into an explicit, reusable mechanism (e.g. a sentinel/wrapper value or a declared list of clearable paths) instead of special-casing api.subDomainPrefix by name inside the generic merge function.
To contest this finding, reply in this thread

0 New Issues
0 Fixed Issues
0 Accepted Issues
What's the purpose of this pull request?
A store that sets
api.subDomainPrefix: []indiscovery.config.jsstill ends up with['www'], so there is no way to stopwww.from being stripped from the host sent to Checkout.discovery.config.jsmerges the default config with the store config usingdeepmerge, which concatenates arrays. The default issubDomainPrefix: ['www'], so[]becomes['www'].The commerce client uses that array to remove the prefix from
x-forwarded-host. Withwwwalways present, Checkout receives the root domain and setscheckout.vtex.com,CheckoutOrderFormOwnership,CheckoutLocaleandCheckoutDataAccesson it. Calls made by the browser straight to/api/checkoutset the same cookies onwww.<domain>, so they are sent duplicated and theCookieheader can exceed the server header limit.How it works?
mergeDiscoveryConfighelper (src/utils/mergeDiscoveryConfig.js), used for every merge indiscovery.config.js. It works likedeepmerge, except that an emptysubDomainPrefixreplaces the default.subDomainPrefixis still appended to['www'], exactly as today. This keeps stores that set a custom prefix (e.g.['shop']) and rely onwwwbeing stripped too working unchanged.next.config.jsprints a warning at build/dev time whensubDomainPrefixis[]andsecureSubdomainis on another host, since Checkout cookies set on the storefront host are not sent to it.Behavior change
Only stores that set
api.subDomainPrefix: []are affected: today that value is ignored, and after this changewww.is no longer stripped, so Checkout cookies are set onwww.<domain>instead of<domain>. Stores that don't set the field, or set any non-empty value, keep the current behavior.Cookies already set on the root domain stay in the browser until they expire or are removed, so returning visitors keep sending both copies for a while.
How to test it?
cd packages/core && pnpm vitest run test/utils/mergeDiscoveryConfig.test.tsapi.subDomainPrefix: []in a store, call/api/graphql(e.g.ValidateCartMutation) withHost: www.<domain>and check that the Checkout cookies come withdomain=www.<domain>instead of<domain>. Without the field, or with['shop'], they stay on<domain>.api.subDomainPrefix: []withsecureSubdomainon another host (e.g.https://secure.<domain>) and check the warning onnext build/next dev.Starters Deploy Preview
References
X-FORWARDED-HOST(checked against the publicorderFormendpoint).Checklist
PR Title and Commit Messages
PR Description
bugDependencies
pnpm-lock.yamlDocumentation
🤖 Generated with Claude Code