Skip to content

Commit 4738a27

Browse files
authored
fix(security): allow opting out of proxy page token in SSR payload (#789)
1 parent f46ccb6 commit 4738a27

2 files changed

Lines changed: 28 additions & 4 deletions

File tree

‎docs/content/docs/1.guides/2.first-party.md‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,11 @@ export default defineNuxtConfig({
280280
// Auto-generate and persist a secret to .env in dev mode.
281281
// Set to false to disable.
282282
autoGenerateSecret: true,
283+
// Emit a per-request proxy page token into the SSR payload so
284+
// client-driven proxy calls authenticate without pre-signed URLs.
285+
// Set to false to keep the token out of the payload (e.g. for a
286+
// stable response etag); client-side calls then need signed URLs.
287+
pageToken: true,
283288
}
284289
}
285290
})
@@ -303,6 +308,10 @@ The module only writes this when running `nuxt dev` with a signed endpoint enabl
303308

304309
Page tokens are valid for 1 hour. If a user leaves a tab open longer than that, client-side proxy requests will start returning 403. The page will recover on next navigation or refresh.
305310

311+
**Proxy token changes the response payload on every request**
312+
313+
The module injects a per-request page token into the SSR payload, so the response hash differs each request. If you compute a stable `etag`, set `security.pageToken: false` to keep the token out of the payload. Client-side proxy calls will then need explicitly signed URLs.
314+
306315
#### Static Generation and SPA Mode
307316

308317
URL signing requires a server runtime to verify HMAC signatures. Two deployment modes cannot support signing:

‎packages/script/src/module.ts‎

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,17 @@ export interface ModuleOptions {
408408
* @default 3600
409409
*/
410410
pageTokenMaxAge?: number
411+
/**
412+
* Emit a per-request proxy page token into the SSR payload so client-driven
413+
* proxy calls authenticate without each URL being HMAC-signed up front.
414+
*
415+
* Set to `false` to keep the token out of the payload (e.g. when computing a
416+
* stable response `etag`). Client-side proxy requests that rely on the token
417+
* will then need explicitly signed URLs.
418+
*
419+
* @default true
420+
*/
421+
pageToken?: boolean
411422
}
412423
/**
413424
* Google Static Maps proxy configuration.
@@ -1058,10 +1069,14 @@ export default defineNuxtModule<ModuleOptions>({
10581069
// Emit a per-request page token during SSR so client-driven proxy
10591070
// calls (reactive fetches, dynamic image helpers) authenticate via
10601071
// `_pt` + `_ts` without needing each URL to be HMAC-signed up front.
1061-
addPlugin({
1062-
src: awaitresolvePath('./runtime/plugins/proxy-token.server'),
1063-
mode: 'server',
1064-
})
1072+
// Opt out via `security.pageToken: false` to keep the token out of the
1073+
// SSR payload (e.g. for a stable response etag).
1074+
if(config.security?.pageToken!==false){
1075+
addPlugin({
1076+
src: awaitresolvePath('./runtime/plugins/proxy-token.server'),
1077+
mode: 'server',
1078+
})
1079+
}
10651080
}
10661081
elseif(!nuxt.options.dev){
10671082
logger.warn(

0 commit comments

Comments
 (0)