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/3.guides/13.security.md
+54-5Lines changed: 54 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,21 +3,66 @@ title: Security
3
3
description: Learn about the security defaults and how to further harden your OG image endpoint.
4
4
---
5
5
6
-
Nuxt OG Image ships with secure defaults by default. Image dimensions are clamped, renders are time limited, internal network requests are blocked, and user provided props are sanitized. No configuration is needed for these protections.
6
+
Nuxt OG Image ships with secure defaults. Image dimensions are clamped, renders are time limited, internal network requests are blocked, and user provided props are sanitized. No configuration is needed for these protections.
7
7
8
-
If you want to lock things down further, the `security` config key gives you additional controls.
8
+
The primary security concern with runtime OG image generation is **denial of service**: without protection, anyone can craft arbitrary image generation requests to your `/_og/d/` endpoint, consuming server CPU and memory. URL signing prevents this by ensuring only your application can generate valid image URLs.
9
+
10
+
For full protection, we recommend combining URL signing with a **web application firewall** (WAF) or rate limiting on the `/_og/` path prefix. Services like [Cloudflare](https://cloudflare.com), AWS WAF, or your hosting provider's built-in rate limiting can add an additional layer of defense.
9
11
10
12
```ts [nuxt.config.ts]
11
13
exportdefaultdefineNuxtConfig({
12
14
ogImage: {
13
15
security: {
14
-
restrictRuntimeImagesToOrigin: true,
15
-
maxQueryParamSize: 2048,
16
+
secret: process.env.OG_IMAGE_SECRET,
16
17
}
17
18
}
18
19
})
19
20
```
20
21
22
+
## URL Signing
23
+
24
+
When a signing secret is configured, every OG image URL includes a cryptographic signature in the path. The server verifies this signature before rendering, rejecting any URL that has been tampered with or crafted manually.
25
+
26
+
This prevents unauthorized image generation requests that would otherwise consume server resources.
27
+
28
+
### Setup
29
+
30
+
1. Generate a secret:
31
+
32
+
```bash
33
+
npx nuxt-og-image generate-secret
34
+
```
35
+
36
+
2. Set the environment variable and reference it in your config:
37
+
38
+
```ts [nuxt.config.ts]
39
+
exportdefaultdefineNuxtConfig({
40
+
ogImage: {
41
+
security: {
42
+
secret: process.env.OG_IMAGE_SECRET,
43
+
}
44
+
}
45
+
})
46
+
```
47
+
48
+
### How It Works
49
+
50
+
When a secret is configured:
51
+
-`defineOgImage()`{lang="ts"} appends a signature to the URL path: `/_og/d/w_1200,h_600,s_abc123def456.png`
52
+
- The server extracts and verifies the signature before processing the request
53
+
- Requests with missing or invalid signatures receive a `403` response
54
+
- All query parameter overrides are ignored (the signed path is the single source of truth)
55
+
56
+
The signature is deterministic: the same options with the same secret always produce the same URL. This means URLs are stable across server restarts and deployments as long as the secret does not change.
57
+
58
+
### Defense in Depth
59
+
60
+
URL signing works alongside the other security options (`maxDimension`, `maxQueryParamSize`, `renderTimeout`, `restrictRuntimeImagesToOrigin`) which continue to apply as defense-in-depth. When signing is active, query parameter overrides are ignored but the query string size limit still applies to reduce parsing overhead.
61
+
62
+
::note
63
+
Dev mode and prerendering bypass signature verification. Signing only applies to runtime requests in production.
64
+
::
65
+
21
66
## Prerender Your Images
22
67
23
68
The most effective security measure is to **prerender your OG images at build time** using [Zero Runtime mode](/docs/og-image/guides/zero-runtime). Prerendered images are served as static files with no runtime rendering code in your production build.
OG image options can be passed via query parameters. By default there is no size limit on the query string, but you can set `maxQueryParamSize` to reject requests with oversized query strings.
109
+
OG image options can be passed via query parameters when URL signing is not enabled. You can set `maxQueryParamSize` to reject requests with oversized query strings.
Requests exceeding this limit receive a `400` response.
77
122
123
+
::note
124
+
When URL signing is active, query parameter overrides are ignored, but this size limit still applies to reduce request parsing overhead.
125
+
::
126
+
78
127
If you find yourself passing large amounts of data through query parameters (titles, descriptions, full text), consider loading that data inside your OG image component instead. See the [Performance guide](/docs/og-image/guides/performance#reduce-url-size) for the recommended pattern.
Copy file name to clipboardExpand all lines: docs/content/4.api/3.config.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -180,6 +180,7 @@ See the [Browser Renderer](/docs/og-image/renderers/browser) guide for more deta
180
180
181
181
Security limits for image generation. See the [Security Guide](/docs/og-image/guides/security) for full details.
182
182
183
+
-**`secret`**: Signing secret for URL tamper protection. When set, all runtime OG image URLs are signed and unsigned requests are rejected with `403`. Generate one with `npx nuxt-og-image generate-secret`. See the [Security Guide](/docs/og-image/guides/security#url-signing) for details.
183
184
-**`maxDimension`**: Maximum width or height in pixels. Default `2048`.
184
185
-**`maxDpr`**: Maximum device pixel ratio (Takumi renderer). Default `2`.
185
186
-**`renderTimeout`**: Milliseconds before the render is aborted with a `408` response. Default `15000`.
@@ -190,6 +191,7 @@ Security limits for image generation. See the [Security Guide](/docs/og-image/gu
logger.warn('`ogImage.debug` is enabled in production. This exposes the `/_og/debug.json` endpoint and should not be enabled in production. Disable it before deploying.')
0 commit comments