W-21432256: Few follow up fixes to address Basket V2-V1 gaps and content security policy headers#3728
Conversation
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
| 'google.com/pay', | ||
| 'google.com/pay/', | ||
| 'www.google.com/pay', | ||
| 'www.google.com/pay/' |
There was a problem hiding this comment.
I guess same question. Do we need www. and google.com? Just want to confirm.
There was a problem hiding this comment.
I added them based on what I saw in the browser for CSP errors. It would help if someone else can run the checks during our testing phase or locally. We initially had *.google.com which is not safe but google pay seems to be depending on several url patterns
| 'google.com', | ||
| 'www.google.com' | ||
| 'google.com/pay', | ||
| 'google.com/pay/', |
There was a problem hiding this comment.
I added them based on what I saw in the browser for CSP errors
There was a problem hiding this comment.
When specifying a path for the CSP header, a trailing slash is significant. It means like matching the any requests that start with this path.
Paths that end in / match any path they are a prefix of. For example:
example.com/api/ will permit resources from example.com/api/users/new.Paths that do not end in / are matched exactly. For example:
https://example.com/file.js permits resources from https://example.com/file.js but not https://example.com/file.js/file2.js.
So I'm guessing google.com/pay/ is sufficient, unless there's a request specifically for exactly google.com/pay.
joeluong-sfcc
left a comment
There was a problem hiding this comment.
Thanks for updating the Shopper Baskets V2 hooks, the changes LGTM, did basic smoke testing and confirmed the following:
- new
baskets/v2cache key is being used instead of old cache keys - guest checkout works
- registered checkout works
vcua-mobify
left a comment
There was a problem hiding this comment.
Thanks for updating the comments in default.js around using a vanity domain / ecom domain.
The changes in ssr.js seem fine to me also aside from what @sf-mkosak called out with with the google.com/pay csp entries.
| '/organizations/', | ||
| string | undefined, | ||
| '/baskets/', | ||
| '/baskets/v2', |
There was a problem hiding this comment.
@joeluong-sfcc do we need the slash '/' at the end or not? Wondering why previously it had the slash at the end
There was a problem hiding this comment.
@amittapalli please add the trailing slash to all the query keys for consistency sake. Yes, functionally, it doesn't matter because query key is just a string (not url). But we have an existing pattern/convention, which only this file does not follow. It may be confusing later in the future for us and the end users.
The Convention in This Codebase
Looking at both files, there's a clear and deliberate pattern for trailing slashes:
- Trailing slash → a dynamic ID segment follows immediately after
- No trailing slash → it's a terminal static segment
In ShopperBaskets:
'/baskets/', <-- trailing slash: basketId follows
basketId,
'/shipments/', <-- trailing slash: shipmentId follows
shipmentId,
'/payment-methods' <-- no slash: terminal
In ShopperBasketsV2:
'/baskets/v2', <-- NO trailing slash, but basketId still follows ← inconsistent
basketId,
So yes, /baskets/v2 should be /baskets/v2/ to be consistent with the established convention.
TanStack Query Best Practices (from tkdodo.eu)
TanStack Query docs don't prescribe a specific string format — keys are opaque array tuples. The
community best practices focus on:
1. Hierarchy from generic → specific (which this codebase does well)
2. Consistency within a project (which is the issue here)
The URL-path-like format in this codebase is a local convention, not a TanStack recommendation. Since
the strings are purely used as cache key identifiers (not as actual URLs), trailing slash consistency
is entirely a project-style concern — but it matters because path() returns a prefix used for cache
invalidation. An inconsistent format could cause confusion about what's intentional.
Recommendation
Fix the inconsistency in ShopperBasketsV2/queryKeyHelpers.ts: change /baskets/v2 → /baskets/v2/ (in
both the QueryKeys type and all path() implementations). This aligns with the codebase's own convention
that trailing slashes signal "a dynamic ID follows."
There was a problem hiding this comment.
Might be good to consider a lint rule for this, if that's possible. Not for this case but for future development.
| 'google.com', | ||
| 'www.google.com' | ||
| 'google.com/pay', | ||
| 'google.com/pay/', |
There was a problem hiding this comment.
When specifying a path for the CSP header, a trailing slash is significant. It means like matching the any requests that start with this path.
Paths that end in / match any path they are a prefix of. For example:
example.com/api/ will permit resources from example.com/api/users/new.Paths that do not end in / are matched exactly. For example:
https://example.com/file.js permits resources from https://example.com/file.js but not https://example.com/file.js/file2.js.
So I'm guessing google.com/pay/ is sufficient, unless there's a request specifically for exactly google.com/pay.
W-21432256: Few follow up fixes to address Basket V2-V1 gaps and content security policy headers
Description
Types of Changes
Changes
How to Test-Drive This PR
Checklists
General
Accessibility Compliance
You must check off all items in one of the follow two lists:
or...
Localization