Skip to content

Commit dc11ae0

Browse files
authored
fix(security): allow disabling proxy signing with security: false (#790)
1 parent 4738a27 commit dc11ae0

2 files changed

Lines changed: 32 additions & 27 deletions

File tree

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

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -280,16 +280,25 @@ 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,
288283
}
289284
}
290285
})
291286
```
292287

288+
To disable proxy security entirely, set `security` to `false`:
289+
290+
```ts [nuxt.config.ts]
291+
exportdefaultdefineNuxtConfig({
292+
scripts: {
293+
// No secret is resolved or auto-generated, no page token is added to the
294+
// SSR payload, and proxy endpoints pass requests through unverified.
295+
security: false,
296+
}
297+
})
298+
```
299+
300+
This is useful when you need a deterministic SSR payload (e.g. to compute a stable response `etag`), since the per-request page token otherwise changes the payload on every request. Proxy endpoints stay functional but unprotected against quota abuse.
301+
293302
#### Troubleshooting
294303

295304
**Signed URLs return 403 after deploy**
@@ -310,7 +319,7 @@ Page tokens are valid for 1 hour. If a user leaves a tab open longer than that,
310319

311320
**Proxy token changes the response payload on every request**
312321

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.
322+
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: false` to disable proxy security entirely. Proxy endpoints then pass requests through without signature verification, so only do this if quota abuse on those endpoints is not a concern.
314323

315324
#### Static Generation and SPA Mode
316325

‎packages/script/src/module.ts‎

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -373,8 +373,12 @@ export interface ModuleOptions {
373373
*
374374
* The secret must be deterministic across deployments so that prerendered URLs
375375
* remain valid. Set it via `NUXT_SCRIPTS_PROXY_SECRET` or `security.secret`.
376+
*
377+
* Set to `false` to disable proxy security entirely: no secret is resolved or
378+
* auto-generated, no page token is injected into the SSR payload, and proxy
379+
* endpoints pass requests through without signature verification.
376380
*/
377-
security?: {
381+
security?: false|{
378382
/**
379383
* HMAC secret used to sign proxy URLs.
380384
*
@@ -408,17 +412,6 @@ export interface ModuleOptions {
408412
* @default 3600
409413
*/
410414
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
422415
}
423416
/**
424417
* Google Static Maps proxy configuration.
@@ -1040,7 +1033,14 @@ export default defineNuxtModule<ModuleOptions>({
10401033
constisStaticTarget=staticPresets.includes(nitroPreset)
10411034
constisSpa=nuxt.options.ssr===false
10421035

1043-
if(anyHandlerRequiresSigning&&(isSpa||isStaticTarget)){
1036+
// Proxy security explicitly disabled: skip secret resolution and the page
1037+
// token plugin. `withSigning` passes requests through unverified.
1038+
if(config.security===false){
1039+
if(anyHandlerRequiresSigning&&!nuxt.options.dev){
1040+
logger.info('[security] Proxy security disabled via `security: false`. Proxy endpoints will pass requests through without signature verification.')
1041+
}
1042+
}
1043+
elseif(anyHandlerRequiresSigning&&(isSpa||isStaticTarget)){
10441044
logger.warn(
10451045
`[security] URL signing requires a server runtime${isStaticTarget ? ` (detected preset: ${nitroPreset})` : ' (ssr: false)'}.\n`
10461046
+' Proxy endpoints will work without signature verification.\n'
@@ -1069,14 +1069,10 @@ export default defineNuxtModule<ModuleOptions>({
10691069
// Emit a per-request page token during SSR so client-driven proxy
10701070
// calls (reactive fetches, dynamic image helpers) authenticate via
10711071
// `_pt` + `_ts` without needing each URL to be HMAC-signed up front.
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-
}
1072+
addPlugin({
1073+
src: awaitresolvePath('./runtime/plugins/proxy-token.server'),
1074+
mode: 'server',
1075+
})
10801076
}
10811077
elseif(!nuxt.options.dev){
10821078
logger.warn(

0 commit comments

Comments
 (0)