Skip to content

Commit 021d237

Browse files
unandyalaclaude
andcommitted
Rename MRT_DISABLE_HTTPONLY_SESSION_COOKIES to MRT_ENABLE_HTTPONLY_SESSION_COOKIES
Remove the double-negative pattern. Rename the env var, config flag (disableHttpOnlySessionCookies → enableHttpOnlySessionCookies), and window global across all packages. Flip comparison logic accordingly. Also includes: rename functions for clarity (setScapiAuthRequestHeaders, setTokensInLogoutRequest, setHttpOnlySessionCookies), extract logout token injection, remove unused siteId fallback/trim, make slasLogoutEndpoint a non-overridable constant, guard proxy auth behind HttpOnly flag, and add x-site-id header for dynamic multisite siteId. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent a461501 commit 021d237

File tree

9 files changed

+25
-25
lines changed

9 files changed

+25
-25
lines changed

packages/pwa-kit-create-app/assets/bootstrap/js/config/default.js.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ module.exports = {
188188
ssrParameters: {
189189
ssrFunctionNodeVersion: '24.x',
190190
// Store the session cookies as HttpOnly for enhanced security.
191-
disableHttpOnlySessionCookies: false,
191+
enableHttpOnlySessionCookies: true,
192192
proxyConfigs: [
193193
{
194194
host: '{{answers.project.commerce.shortCode}}.api.commercecloud.salesforce.com',

packages/pwa-kit-create-app/assets/templates/@salesforce/retail-react-app/config/default.js.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ module.exports = {
184184
ssrParameters: {
185185
ssrFunctionNodeVersion: '24.x',
186186
// Store the session cookies as HttpOnly for enhanced security.
187-
disableHttpOnlySessionCookies: false,
187+
enableHttpOnlySessionCookies: true,
188188
proxyConfigs: [
189189
{
190190
host: '{{answers.project.commerce.shortCode}}.api.commercecloud.salesforce.com',

packages/pwa-kit-dev/bin/pwa-kit-dev.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -253,16 +253,16 @@ const main = async () => {
253253
error('Could not determine app entrypoint.')
254254
process.exit(1)
255255
}
256-
// Load config to get envBasePath and disableHttpOnlySessionCookies from ssrParameters for local development
256+
// Load config to get envBasePath and enableHttpOnlySessionCookies from ssrParameters for local development
257257
// This mimics how MRT sets the system environment variable
258258
const config = getConfig() || {}
259-
const disableHttpOnlySessionCookies =
260-
config.ssrParameters?.disableHttpOnlySessionCookies ?? true
259+
const enableHttpOnlySessionCookies =
260+
config.ssrParameters?.enableHttpOnlySessionCookies ?? false
261261
execSync(`${babelNode} ${inspect ? '--inspect' : ''} ${babelArgs} ${entrypoint}`, {
262262
env: {
263263
...process.env,
264264
...(noHMR ? {HMR: 'false'} : {}),
265-
MRT_DISABLE_HTTPONLY_SESSION_COOKIES: String(disableHttpOnlySessionCookies)
265+
MRT_ENABLE_HTTPONLY_SESSION_COOKIES: String(enableHttpOnlySessionCookies)
266266
}
267267
})
268268
})

packages/pwa-kit-react-sdk/src/ssr/server/react-rendering.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ const renderApp = (args) => {
365365
__CONFIG__: config,
366366
__PRELOADED_STATE__: appState,
367367
__ERROR__: error,
368-
__MRT_DISABLE_HTTPONLY_SESSION_COOKIES__: process.env.MRT_DISABLE_HTTPONLY_SESSION_COOKIES,
368+
__MRT_ENABLE_HTTPONLY_SESSION_COOKIES__: process.env.MRT_ENABLE_HTTPONLY_SESSION_COOKIES,
369369
// `window.Progressive` has a long history at Mobify and some
370370
// client-side code depends on it. Maintain its name out of tradition.
371371
Progressive: getWindowProgressive(req, res)

packages/pwa-kit-runtime/src/ssr/server/build-remote-server.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ export const RemoteServerFactory = {
219219

220220
// Custom callback to modify the SLAS private client proxy response. This callback is invoked
221221
// after the built-in proxy response handling (including HttpOnly session cookie handling when enabled).
222-
// When HttpOnly session cookies are enabled (MRT_DISABLE_HTTPONLY_SESSION_COOKIES=false), the callback
222+
// When HttpOnly session cookies are enabled (MRT_ENABLE_HTTPONLY_SESSION_COOKIES=true), the callback
223223
// receives the response with tokens already moved to HttpOnly cookies and stripped from the body.
224224
// Custom callbacks must not rely on token fields in the response body in that case; read from
225225
// response headers (e.g. Set-Cookie) if needed.
@@ -265,7 +265,7 @@ export const RemoteServerFactory = {
265265
`${options.slasApiPath.source}(${options.applySLASPrivateClientToEndpoints.source})`
266266
)
267267

268-
// Note: HttpOnly session cookies are controlled by the MRT_DISABLE_HTTPONLY_SESSION_COOKIES
268+
// Note: HttpOnly session cookies are controlled by the MRT_ENABLE_HTTPONLY_SESSION_COOKIES
269269
// env var (set by MRT in production, pwa-kit-dev locally). Read directly where needed.
270270

271271
return options
@@ -1002,7 +1002,7 @@ export const RemoteServerFactory = {
10021002
// purpose so we don't want to overwrite the header for those calls.
10031003
proxyRequest.setHeader('Authorization', `Basic ${encodedSlasCredentials}`)
10041004
} else if (
1005-
process.env.MRT_DISABLE_HTTPONLY_SESSION_COOKIES === 'false' &&
1005+
process.env.MRT_ENABLE_HTTPONLY_SESSION_COOKIES === 'true' &&
10061006
incomingRequest.path?.match(SLAS_LOGOUT_ENDPOINT)
10071007
) {
10081008
setTokensInLogoutRequest(proxyRequest, incomingRequest)
@@ -1030,7 +1030,7 @@ export const RemoteServerFactory = {
10301030
// Check against tokenResponseEndpoints regex (configurable in ssr.js)
10311031
const isTokenEndpoint = req.path?.match(options.tokenResponseEndpoints)
10321032
const httpOnlySessionCookiesEnabled =
1033-
process.env.MRT_DISABLE_HTTPONLY_SESSION_COOKIES === 'false'
1033+
process.env.MRT_ENABLE_HTTPONLY_SESSION_COOKIES === 'true'
10341034
if (
10351035
httpOnlySessionCookiesEnabled &&
10361036
proxyRes.statusCode === 200 &&

packages/pwa-kit-runtime/src/ssr/server/build-remote-server.test.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ describe('SLAS private proxy', () => {
192192
afterEach(() => {
193193
// Clean up environment variables
194194
delete process.env.PWA_KIT_SLAS_CLIENT_SECRET
195-
delete process.env.MRT_DISABLE_HTTPONLY_SESSION_COOKIES
195+
delete process.env.MRT_ENABLE_HTTPONLY_SESSION_COOKIES
196196
})
197197

198198
test('returns 404 when useSLASPrivateClient is false', async () => {
@@ -378,11 +378,11 @@ describe('HttpOnly session cookies', () => {
378378

379379
afterEach(() => {
380380
delete process.env.PWA_KIT_SLAS_CLIENT_SECRET
381-
delete process.env.MRT_DISABLE_HTTPONLY_SESSION_COOKIES
381+
delete process.env.MRT_ENABLE_HTTPONLY_SESSION_COOKIES
382382
})
383383

384-
test('does not process when MRT_DISABLE_HTTPONLY_SESSION_COOKIES is not set', async () => {
385-
delete process.env.MRT_DISABLE_HTTPONLY_SESSION_COOKIES
384+
test('does not process when MRT_ENABLE_HTTPONLY_SESSION_COOKIES is not enabled', async () => {
385+
delete process.env.MRT_ENABLE_HTTPONLY_SESSION_COOKIES
386386

387387
const mockSlasServer = mockExpress()
388388
mockSlasServer.post('/shopper/auth/v1/oauth2/token', (req, res) => {
@@ -434,7 +434,7 @@ describe('HttpOnly session cookies', () => {
434434
})
435435

436436
test('returns 500 when siteId is missing', async () => {
437-
process.env.MRT_DISABLE_HTTPONLY_SESSION_COOKIES = 'false'
437+
process.env.MRT_ENABLE_HTTPONLY_SESSION_COOKIES = 'true'
438438

439439
const mockSlasServer = mockExpress()
440440
mockSlasServer.post('/shopper/auth/v1/oauth2/token', (req, res) => {
@@ -484,7 +484,7 @@ describe('HttpOnly session cookies', () => {
484484
})
485485

486486
test('injects Bearer token and refresh token from HttpOnly cookies for logout endpoint', async () => {
487-
process.env.MRT_DISABLE_HTTPONLY_SESSION_COOKIES = 'false'
487+
process.env.MRT_ENABLE_HTTPONLY_SESSION_COOKIES = 'true'
488488

489489
let capturedAuthHeader
490490
let capturedRefreshToken
@@ -540,7 +540,7 @@ describe('HttpOnly session cookies', () => {
540540
})
541541

542542
test('x-site-id header takes precedence over static config siteId for logout endpoint', async () => {
543-
process.env.MRT_DISABLE_HTTPONLY_SESSION_COOKIES = 'false'
543+
process.env.MRT_ENABLE_HTTPONLY_SESSION_COOKIES = 'true'
544544

545545
let capturedAuthHeader
546546
let capturedRefreshToken
@@ -596,7 +596,7 @@ describe('HttpOnly session cookies', () => {
596596
})
597597

598598
test('sets HttpOnly cookies and strips tokens from response body', async () => {
599-
process.env.MRT_DISABLE_HTTPONLY_SESSION_COOKIES = 'false'
599+
process.env.MRT_ENABLE_HTTPONLY_SESSION_COOKIES = 'true'
600600

601601
const mockSlasServer = mockExpress()
602602
mockSlasServer.post('/shopper/auth/v1/oauth2/token', (req, res) => {
@@ -656,7 +656,7 @@ describe('HttpOnly session cookies', () => {
656656
})
657657

658658
test('returns 500 when JWT decode fails', async () => {
659-
process.env.MRT_DISABLE_HTTPONLY_SESSION_COOKIES = 'false'
659+
process.env.MRT_ENABLE_HTTPONLY_SESSION_COOKIES = 'true'
660660

661661
const mockSlasServer = mockExpress()
662662
mockSlasServer.post('/shopper/auth/v1/oauth2/token', (req, res) => {
@@ -706,7 +706,7 @@ describe('HttpOnly session cookies', () => {
706706
})
707707

708708
test('processes passwordless token endpoint', async () => {
709-
process.env.MRT_DISABLE_HTTPONLY_SESSION_COOKIES = 'false'
709+
process.env.MRT_ENABLE_HTTPONLY_SESSION_COOKIES = 'true'
710710

711711
const mockSlasServer = mockExpress()
712712
mockSlasServer.post('/shopper/auth/v1/oauth2/passwordless/token', (req, res) => {

packages/pwa-kit-runtime/src/utils/ssr-server/configure-proxy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ export const configureProxy = ({
261261
})
262262

263263
// Apply Authorization header with shopper's access token from HttpOnly cookie
264-
if (process.env.MRT_DISABLE_HTTPONLY_SESSION_COOKIES === 'false') {
264+
if (process.env.MRT_ENABLE_HTTPONLY_SESSION_COOKIES === 'true') {
265265
setScapiAuthRequestHeaders({
266266
proxyRequest,
267267
incomingRequest,

packages/template-retail-react-app/app/components/_app-config/index.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ const AppConfig = ({children, locals = {}}) => {
114114
// hybridAuthEnabled={true}
115115
useHttpOnlySessionCookies={
116116
typeof window !== 'undefined'
117-
? window.__MRT_DISABLE_HTTPONLY_SESSION_COOKIES__ === 'false'
118-
: process.env.MRT_DISABLE_HTTPONLY_SESSION_COOKIES === 'false'
117+
? window.__MRT_ENABLE_HTTPONLY_SESSION_COOKIES__ === 'true'
118+
: process.env.MRT_ENABLE_HTTPONLY_SESSION_COOKIES === 'true'
119119
}
120120
logger={createLogger({packageName: 'commerce-sdk-react'})}
121121
>

packages/template-retail-react-app/config/default.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ module.exports = {
107107
ssrParameters: {
108108
ssrFunctionNodeVersion: '24.x',
109109
// Store the session cookies as HttpOnly for enhanced security.
110-
disableHttpOnlySessionCookies: true,
110+
enableHttpOnlySessionCookies: false,
111111
proxyConfigs: [
112112
{
113113
host: 'kv7kzm78.api.commercecloud.salesforce.com',

0 commit comments

Comments
 (0)