Skip to content

Commit 0972cd7

Browse files
committed
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.
1 parent 4e09f08 commit 0972cd7

File tree

1 file changed

+9
-36
lines changed

1 file changed

+9
-36
lines changed

docs/content/3.guides/13.security.md

Lines changed: 9 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
---
22
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.
44
---
55

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.
77

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.
119

1210
```ts [nuxt.config.ts]
1311
export default defineNuxtConfig({
@@ -20,11 +18,9 @@ export default defineNuxtConfig({
2018
})
2119
```
2220

23-
This ensures only requests to your configured hostname are served and rejects oversized query strings. Read on for full details on each option.
24-
2521
## Prerender Your Images
2622

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.
2824

2925
```ts [nuxt.config.ts]
3026
export default defineNuxtConfig({
@@ -38,18 +34,19 @@ When zero runtime is enabled:
3834
- No server-side rendering code is included in your production build
3935
- Images are generated once at build time and served as static assets
4036
- The `/_og` endpoint is not available at runtime
41-
- There is no attack surface for DOS, SSRF, or origin abuse
4237

4338
If your OG images don't need to change dynamically after deployment, this is the recommended approach.
4439

4540
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.
4641

4742
## Dimension and Render Limits
4843

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`).
5045

5146
If a render exceeds `renderTimeout` (default `10000ms`), it is aborted and the server returns a `408` status.
5247

48+
These are all enabled by default. You only need to configure them if you want different limits.
49+
5350
```ts [nuxt.config.ts]
5451
export default defineNuxtConfig({
5552
ogImage: {
@@ -62,8 +59,6 @@ export default defineNuxtConfig({
6259
})
6360
```
6461

65-
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-
6762
## Query String Size Limit
6863

6964
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.
8277

8378
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.
8479

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).
88-
89-
Blocked targets include:
90-
- Loopback (`127.0.0.0/8`, `::1`, `localhost`)
91-
- Private networks (`10.0.0.0/8`, `172.16.0.0/12`, `192.168.0.0/16`)
92-
- Link-local (`169.254.0.0/16`, `fe80::`)
93-
- IPv6 unique local (`fc00::`, `fd00::`)
94-
- 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-
9980
## Restrict Runtime Images to Origin
10081

10182
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.
@@ -130,23 +111,15 @@ export default defineNuxtConfig({
130111
})
131112
```
132113

133-
### Social Media Crawlers
134-
135-
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.
142115

143116
::note
144117
Prerendering and dev mode bypass the host check entirely.
145118
::
146119

147120
## Debug Mode Warning
148121

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.
150123

151124
```ts [nuxt.config.ts]
152125
export default defineNuxtConfig({

0 commit comments

Comments
 (0)