Skip to content

Commit deacf59

Browse files
committed
fix(security): pass through when no proxy secret is configured
withSigning now delegates to the inner handler without verification when NUXT_SCRIPTS_PROXY_SECRET is not set. This avoids breaking existing users who upgrade before components emit signed URLs. Signing enforcement activates automatically once a secret is set.
1 parent c3a6997 commit deacf59

1 file changed

Lines changed: 11 additions & 11 deletions

File tree

packages/script/src/runtime/server/utils/withSigning.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@
1010
*
1111
* Behavior:
1212
* - Reads `runtimeConfig.nuxt-scripts.proxySecret` (server-only).
13-
* - If no secret is configured: 500 (the module is misconfigured).
14-
* - If the request's `sig` param is missing, malformed, or doesn't match: 403.
13+
* - If no secret is configured: passes through (signing not yet enabled).
14+
* This allows shipping handler wiring before components emit signed URLs.
15+
* Once `NUXT_SCRIPTS_PROXY_SECRET` is set, verification is enforced.
16+
* - If a secret IS configured and the request's signature is invalid: 403.
1517
* - Otherwise, delegates to the wrapped handler.
1618
*
17-
* The outer wrapper runs before any handler logic, so misconfigured / unauthorized
18-
* requests never reach the upstream fetch and cannot consume API quota.
19+
* The outer wrapper runs before any handler logic, so unauthorized requests
20+
* never reach the upstream fetch and cannot consume API quota.
1921
*/
2022

2123
import type { EventHandler, EventHandlerRequest, EventHandlerResponse } from 'h3'
@@ -30,13 +32,11 @@ export function withSigning<Req extends EventHandlerRequest = EventHandlerReques
3032
const runtimeConfig = useRuntimeConfig(event)
3133
const secret = (runtimeConfig['nuxt-scripts'] as { proxySecret?: string } | undefined)?.proxySecret
3234

33-
if (!secret) {
34-
throw createError({
35-
statusCode: 500,
36-
statusMessage: 'Proxy secret not configured',
37-
message: 'NUXT_SCRIPTS_PROXY_SECRET is not set. Run `npx @nuxt/scripts generate-secret` and set the env var.',
38-
})
39-
}
35+
// No secret configured: pass through without verification. This lets the
36+
// handler wiring ship before components emit signed URLs. Users opt in to
37+
// enforcement by setting NUXT_SCRIPTS_PROXY_SECRET.
38+
if (!secret)
39+
return handler(event) as Res
4040

4141
if (!verifyProxyRequest(event, secret)) {
4242
throw createError({

0 commit comments

Comments
 (0)