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
docs: rewrite security guide with defaults-first framing
Remove GHSA references, SSRF details, social media crawler section,
and relative path section. Lead with secure defaults messaging and
only detail configurable options.
Copy file name to clipboardExpand all lines: docs/content/3.guides/13.security.md
+9-36Lines changed: 9 additions & 36 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,13 +1,11 @@
1
1
---
2
2
title: Security
3
-
description: Protect your OG image endpoint from abuse and server-side request forgery.
3
+
description: Learn about the security defaults and how to further harden your OG image endpoint.
4
4
---
5
5
6
-
Nuxt OG Image generates images on the server. Without proper limits, the `/_og` endpoint can be exploited to exhaust memory, trigger long renders, or fetch internal resources.
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.
7
7
8
-
## Quick Start
9
-
10
-
If you need runtime OG images and want to lock things down quickly, add this to your config:
8
+
If you want to lock things down further, the `security` config key gives you additional controls.
This ensures only requests to your configured hostname are served and rejects oversized query strings. Read on for full details on each option.
24
-
25
21
## Prerender Your Images
26
22
27
-
The single 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, bypassing all runtime rendering code.
23
+
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.
28
24
29
25
```ts [nuxt.config.ts]
30
26
exportdefaultdefineNuxtConfig({
@@ -38,18 +34,19 @@ When zero runtime is enabled:
38
34
- No server-side rendering code is included in your production build
39
35
- Images are generated once at build time and served as static assets
40
36
- The `/_og` endpoint is not available at runtime
41
-
- There is no attack surface for DOS, SSRF, or origin abuse
42
37
43
38
If your OG images don't need to change dynamically after deployment, this is the recommended approach.
44
39
45
40
For sites that need a mix of static and dynamic images, you can prerender specific routes while keeping runtime generation available for others. See the [Zero Runtime guide](/docs/og-image/guides/zero-runtime) for configuration details.
46
41
47
42
## Dimension and Render Limits
48
43
49
-
Every request has its `width` and `height` clamped to `maxDimension` (default `2048` pixels) after all option sources merge. The Takumi renderer's `devicePixelRatio` is capped to `maxDpr` (default `2`).
44
+
Every request has its `width` and `height` clamped to `maxDimension` (default `2048` pixels). The Takumi renderer's `devicePixelRatio` is capped to `maxDpr` (default `2`).
50
45
51
46
If a render exceeds `renderTimeout` (default `10000ms`), it is aborted and the server returns a `408` status.
52
47
48
+
These are all enabled by default. You only need to configure them if you want different limits.
These defaults protect against the denial of service vector described in [GHSA-c7xp-q6q8-hg76](https://github.com/nuxt-modules/og-image/security/advisories/GHSA-c7xp-q6q8-hg76), where requests like `/_og/d/og.png?width=20000&height=20000` could exhaust server memory.
66
-
67
62
## Query String Size Limit
68
63
69
64
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.
@@ -82,20 +77,6 @@ Requests exceeding this limit receive a `400` response.
82
77
83
78
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.
84
79
85
-
## SSRF Protection
86
-
87
-
OG image templates can reference external images via `<img src>`{lang="html"} or CSS `background-image`. Outside of dev mode, the module blocks fetches to private and loopback addresses to prevent server-side request forgery (SSRF).
- Alternative IP encodings (hex `0x7f000001`, decimal `2130706433`, IPv6-mapped `::ffff:127.0.0.1`)
95
-
- Non-HTTP protocols (`file://`, `ftp://`, etc.)
96
-
97
-
This runs automatically in production. No configuration is required.
98
-
99
80
## Restrict Runtime Images to Origin
100
81
101
82
When runtime image generation is enabled, anyone who knows the `/_og` endpoint pattern can request an image directly. The `restrictRuntimeImagesToOrigin` option limits runtime generation to requests whose `Host` header matches your configured site URL.
Social media crawlers (Twitter/X, Facebook, LinkedIn, Discord) always send the `Host` header when fetching your `og:image` URL, so this check works transparently with them. No special configuration is needed.
136
-
137
-
This option is still **disabled by default** to avoid surprises for sites behind non-standard proxy setups. If your reverse proxy forwards the correct `Host` or `X-Forwarded-Host` header, you can safely enable it.
138
-
139
-
### Relative OG Image Paths
140
-
141
-
Using a relative path in your `og:image` meta tag (e.g. `/_og/d/og.png` instead of `https://example.com/_og/d/og.png`) does not affect this check. Social media crawlers resolve relative paths against the page URL before making the request, and the resulting HTTP request will include the correct `Host` header for your domain.
114
+
This option is **disabled by default** to avoid surprises for sites behind non-standard proxy setups. If your reverse proxy forwards the correct `Host` or `X-Forwarded-Host` header, you can safely enable it.
142
115
143
116
::note
144
117
Prerendering and dev mode bypass the host check entirely.
145
118
::
146
119
147
120
## Debug Mode Warning
148
121
149
-
Enabling `ogImage.debug` in production exposes the `/_og/debug.json` endpoint and disables some security restrictions. The module will log a warning at build time if debug is enabled outside of dev mode. Make sure to disable it before deploying.
122
+
Enabling `ogImage.debug` in production exposes the `/_og/debug.json` endpoint. The module will log a warning at build time if debug is enabled outside of dev mode. Make sure to disable it before deploying.
0 commit comments