You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/content/docs/1.guides/2.first-party.md
+54Lines changed: 54 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -200,6 +200,60 @@ The same pattern applies to [Netlify](https://netlify.com) (`[[redirects]]` with
200
200
Platform-level rewrites bypass the privacy anonymisation layer. The proxy handler only runs in a Nitro server runtime.
201
201
::
202
202
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
+
exportdefaultdefineNuxtConfig({
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.
0 commit comments