Skip to content

Commit 4e234d1

Browse files
committed
docs: add proxy endpoint security section to first-party guide
Documents HMAC URL signing, page tokens, the generate-secret CLI, dev auto-generation, and production setup requirements.
1 parent 48c0865 commit 4e234d1

1 file changed

Lines changed: 54 additions & 0 deletions

File tree

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

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,60 @@ The same pattern applies to [Netlify](https://netlify.com) (`[[redirects]]` with
200200
Platform-level rewrites bypass the privacy anonymisation layer. The proxy handler only runs in a Nitro server runtime.
201201
::
202202

203+
## Proxy Endpoint Security
204+
205+
Several proxy endpoints (Google Static Maps, Geocode, Gravatar, embed image proxies) inject server-side API keys or forward requests to third-party services. Without protection, anyone who discovers these endpoints could call them directly and consume your API quota.
206+
207+
### HMAC URL Signing
208+
209+
The module provides optional HMAC signing to lock down proxy endpoints. When enabled, only URLs generated server-side (during SSR or prerender) or accompanied by a valid page token are accepted. Unsigned requests receive a `403`.
210+
211+
#### Setup
212+
213+
Generate a signing secret:
214+
215+
```bash
216+
npx @nuxt/scripts generate-secret
217+
```
218+
219+
Then set it as an environment variable:
220+
221+
```bash
222+
NUXT_SCRIPTS_PROXY_SECRET=<your-secret>
223+
```
224+
225+
Or configure it directly:
226+
227+
```ts [nuxt.config.ts]
228+
export default defineNuxtConfig({
229+
scripts: {
230+
security: {
231+
secret: process.env.NUXT_SCRIPTS_PROXY_SECRET,
232+
}
233+
}
234+
})
235+
```
236+
237+
#### How It Works
238+
239+
The module uses two verification modes:
240+
241+
1. **URL signatures** for server-rendered content. During SSR/prerender, proxy URLs include a `sig` parameter: an HMAC of the path and query params. The proxy endpoint verifies the signature before forwarding.
242+
243+
2. **Page tokens** for client-side reactive updates. Some components recompute their proxy URL after mount (e.g. measuring element dimensions). The server embeds a short-lived token (`_pt` + `_ts` params) in the SSR payload. The token is valid for any params on any proxy path and expires after 1 hour.
244+
245+
#### Development
246+
247+
In development, the module auto-generates a secret and writes it to your `.env` file on first run. You don't need to configure anything for local dev.
248+
249+
#### Production
250+
251+
Set `NUXT_SCRIPTS_PROXY_SECRET` in your deployment environment. The secret must be the same across all replicas and across build/runtime so that URLs signed at prerender time remain valid.
252+
253+
::callout{type="warning"}
254+
Without a secret, proxy endpoints remain functional but unprotected. The module logs a warning at startup when it detects signed endpoints without a secret.
255+
::
256+
203257
## Supported Scripts
204258

205259
### Full First-Party (Bundled + Proxied)

0 commit comments

Comments
 (0)