Engineering, AI & Security

Why Image Optimization Endpoints Become Security Boundaries: SVG Bypasses, SSRF, and Path Traversal

An image optimization endpoint does more than shrink photos. It fetches URLs, reads local disk, and runs native decoders on untrusted input. Here is how those failures work and how to lock them down.

By Josué Trindade Engineering & AI ~10 min

Most developers think of /_next/image or /_image as a harmless performance helper. You pass an image path and a width to a framework component, and smaller WebP or AVIF bytes come back over HTTP.

In self-hosted production, that route does far more than shrink photos. Accepting query parameters from unauthenticated visitors turns /_next/image or /_image into four sensitive primitives inside one public endpoint: an outbound HTTP client, a local filesystem reader, a native C or C++ decoder inside your Node process, and a persistent disk cache. When any of those primitives trusts attacker-controlled input, a convenience feature becomes an operational security boundary.

Security advisories published in 2026 for Next.js and Astro show how these failures happen in practice. Tracing the mechanics answers three essential engineering questions: where does the validation rule actually run, what fails when a request steps off the happy path, and who repairs the host when disk, parser, or origin assumptions break?

What Happens Inside /_next/image and /_image

On a static build, resizing runs once in CI and only flat files land on disk. On an on-demand server (such as self-hosted next start or Astro SSR with @astrojs/node), every image request triggers a multi-step runtime pipeline:

GET /_next/image?url=...&w=1200&q=75
  -> 1. Parse source URL or local path plus width and quality
  -> 2. Check domain allowlist or local directory boundary
  -> 3. Fetch bytes via HTTP(S) or read file from local disk
  -> 4. Sniff MIME/format and decode via native pipeline (sharp / libvips)
  -> 5. Write resized variant to disk cache and return HTTP response

Each arrow crosses a trust boundary. If step 2 compares paths differently from Linux, step 3 reads outside the public directory or fetches an untrusted host. If step 4 lets XML slip past a MIME gate, an attacker reaches native decoders you thought were off. If step 5 caches arbitrary width and quality combinations without a ceiling, an automated client fills the disk while receiving valid 200 OK responses.

SVG Is Executable XML, and Rejection Filters Have Edge Cases

JPEG, PNG, and WebP encode pixel grids. SVG does not. An SVG file is an XML document capable of carrying <script> tags, event handlers, <foreignObject> HTML payloads, and external references. Serving an unsanitized SVG inline on your primary origin gives a browser script-execution context close to serving HTML, while parsing an untrusted SVG triggers complex XML and vector rasterization paths in native C/C++ libraries.

Next.js disables SVG processing by default via dangerouslyAllowSVG: false. Many teams assume that setting guarantees untrusted SVGs never reach the image parser. In November 2026, GHSA-7qx7-33qx-rqx2 (CVE-2026-119347, CVSS 6.9) proved otherwise. On self-hosted Next.js deployments (next >= 16.0.0 <= 16.4.4 and >= 15.0.0 <= 15.5.28), /_next/image could be made to process an attacker-supplied SVG even with dangerouslyAllowSVG: false. Bypassing the rejection gate routed the payload into an SVG parser intended to stay disabled, raising exposure to denial of service and decoder bugs until patched in 15.5.29 and 16.4.5.

Weeks earlier, GHSA-2464-fhr4-w9xw (CVE-2026-96889, published October 14, 2026, CVSS 9.5 Critical) showed what happens when an attacker reaches that native stack. That advisory documented unauthenticated Remote Code Execution (RCE) in the Next.js Image Optimization API when SVG files are processed on glibc-based Linux (next >= 10.0.0 <= 15.5.27 and > 16.0.0 <= 16.4.0, patched in 15.5.28 and 16.4.1). The vulnerability lived in the upstream sharp library prior to 0.35.5.

Together, those two advisories clarify the risk chain:

  1. With an unpatched native decoder (sharp < 0.35.5), SVG rasterization is a native memory-safety boundary on Linux.
  2. Even with dangerouslyAllowSVG: false, a validation bypass (CVE-2026-119347) can still push attacker bytes into that parser if your framework build is outdated.
  3. On the client side, returning SVG bytes on the same origin without sandboxing headers exposes user sessions to script execution, the same browser boundary explored in our articles on Content Security Policy nonces against XSS and DOMPurify HTML sanitization.

Outbound Fetching, Host Headers, and Silent SSRF

Image endpoints also fetch remote assets or resolve origin-relative paths into full URLs. Whenever a server builds an outbound request from incoming HTTP metadata, Server-Side Request Forgery (SSRF, CWE-918) becomes a direct concern.

Consider GHSA-m8p5-r7qv-cx4c, published on October 12, 2026 for @astrojs/node (<= 11.1.6, patched in 11.1.7), addressing full-read SSRF in the default /_image endpoint via the HTTP Host header. Inside astro/app/node, two request builders held opposite postures:

  • createRequest() validated the Host header against security.allowedDomains and fell back to localhost on mismatch to block SSRF.
  • createRequestFromNodeRequest() skipped Host validation, assuming FetchState.#applyForwardedHeaders() would inspect x-forwarded-proto, x-forwarded-host, and x-forwarded-port later.
  • @astrojs/node called createRequestFromNodeRequest() on every request in serve-app.ts and serve-static.ts. Without x-forwarded-* headers, FetchState returned early and left Astro.url anchored to the raw Host header.

Operators configured security.allowedDomains, saw X-Forwarded-Host protection in the docs, and assumed origins were safe. Yet sending Host: attacker.example.net poisoned Astro.url.origin, enabling SSRF through /_image alongside poisoned canonical tags, email links, and shared caches. Behind Nginx, Caddy, or Cloudflare, never rely on application code alone to sanitize Host: reject unknown virtual hosts at the reverse proxy before requests reach Node.

Path Containment and Case-Sensitivity Traps on Linux

For local images, the core defense against arbitrary file read (CWE-22) is checking that the resolved target stays inside the public output directory.

On November 9, 2026, Astro disclosed GHSA-r3h5-4585-7x3w (CVE-2026-126364, affecting astro >= 5.14.3 <= 7.4.6 with @astrojs/node <= 11.1.11, patched in astro 7.4.7). The /_image endpoint checked that a local href sat inside the client output directory, but compared the path prefix case-insensitively.

On case-sensitive Linux filesystems, that created a mismatch (CWE-178). With public output at /srv/app/dist/client/ and a sibling folder at /srv/app/DIST/client/, a request such as:

/_image?href=/../../DIST/client/secret.png&w=32&f=png

passed the case-insensitive check while Linux resolved DIST outside dist/client/.

Two operational caveats stand out in the advisory: exploitation required on-demand @astrojs/node rendering, a case-sensitive filesystem, a pre-existing case-variant sibling directory, and an image-service-accepted format (rasters resized, SVGs returned unchanged, non-images rejected; plain traversal like /../../secret.png was already blocked). Crucially, the vulnerable check lived in astro, not @astrojs/node. Upgrading @astrojs/node alone left hosts vulnerable until astro reached 7.4.7, where POSIX comparisons became exact.

Unbounded Variant Caching and Disk Exhaustion

Even valid URLs can break a self-hosted node if output caching has no ceiling. In March 2026, Next.js disclosed GHSA-3x4c-7xq6-9pq8 (CVE-2026-27980, CVSS 6.9, CWE-400) for next >= 10.0.0. On self-hosted deployments, /_next/image stored variants in .next/cache/images without a configurable upper bound. Cycling valid source URLs across distinct width and quality parameters allowed an unauthenticated attacker to exhaust disk space.

Next.js fixed this in 15.5.14 and 16.1.7 by adding an LRU-backed disk cache controlled via images.maximumDiskCacheSize (or 0 to disable disk caching), alongside workarounds to clean .next/cache/images and tighten images.localPatterns, images.remotePatterns, and images.qualities.

Summary of 2026 Image Endpoint Failure Modes

Failure Pattern Primary Advisory Affected Surface Root Cause Fix / Mitigation
SVG filter bypass GHSA-7qx7-33qx-rqx2 (CVE-2026-119347) Self-hosted Next.js (15.x, 16.x) Attacker SVG reaches disabled parser despite dangerouslyAllowSVG: false Upgrade next to 15.5.29 or 16.4.5
Native SVG RCE GHSA-2464-fhr4-w9xw (CVE-2026-96889) Next.js on glibc Linux (sharp < 0.35.5) Upstream memory bug in native SVG decoding Upgrade next (15.5.28 / 16.4.1) and ensure sharp >= 0.35.5
Host header SSRF GHSA-m8p5-r7qv-cx4c @astrojs/node <= 11.1.6 /_image Raw Host accepted without allowedDomains check Upgrade @astrojs/node >= 11.1.7 and canonicalize Host at proxy
Case-variant read GHSA-r3h5-4585-7x3w (CVE-2026-126364) astro <= 7.4.6 with @astrojs/node on Linux Case-insensitive prefix check on case-sensitive filesystem Upgrade astro >= 7.4.7; remove case-variant sibling directories
Disk cache DoS GHSA-3x4c-7xq6-9pq8 (CVE-2026-27980) Self-hosted Next.js >= 10.0.0 Unbounded .next/cache/images storage Upgrade (15.5.14 / 16.1.7), set maximumDiskCacheSize, bound variants

Conditional Engineering Controls: Static Builds vs. Hardened Workers

The simplest way to secure an image optimization endpoint is not to expose one in production unless you genuinely need runtime resizing.

For corporate sites, documentation hubs, and fixed catalogs whose assets change only during deploys, pre-generating AVIF and WebP variants at build time (Astro static assets or images: { unoptimized: true } with a build pipeline) eliminates the attack surface completely. Flat files served by Nginx, Apache, or a CDN leave no outbound fetcher, no dynamic local path reader, no unauthenticated sharp trigger, and no growing .next/cache/images directory.

User-generated platforms, multi-tenant web apps, and external CMS workflows with unpredictable media uploads genuinely need dynamic resizing. When you keep a runtime endpoint active, lock down every boundary:

  1. Enforce strict allowlists: Pin exact HTTPS hostnames and path prefixes in remotePatterns and localPatterns, plus explicit deviceSizes, imageSizes, and qualities. Never leave wildcard hosts (**) open.
  2. Isolate SVG delivery: Keep dangerouslyAllowSVG: false when runtime SVG transforms are unnecessary. If untrusted SVGs must be served, host them on a separate cookieless origin or return both Content-Disposition: attachment and Content-Security-Policy: sandbox (script-src 'none').
  3. Check canonical filesystem paths: Keep sensitive files outside sibling folders of dist/client/, run Node with read-only permissions on build artifacts, and resolve symlinks with fs.realpathSync before case-sensitive path.relative boundary checks on Linux.
  4. Bound disk caches and proxy headers: Set images.maximumDiskCacheSize explicitly on self-hosted Next.js (or 0 behind an edge CDN), and reject mismatched Host headers at Nginx or your load balancer.
  5. Move heavy transforms to an isolated worker: For higher-risk workloads, run media resizing in a separate stateless container (such as imgproxy) with egress firewall rules blocking RFC 1918 private networks, loopback, and cloud metadata IPs (169.254.169.254).
// Next.js hardening baseline for self-hosted deployments
/** @type {import('next').NextConfig} */
const nextConfig = {
  images: {
    dangerouslyAllowSVG: false,
    contentDispositionType: 'attachment',
    contentSecurityPolicy: "default-src 'self'; script-src 'none'; sandbox;",
    maximumDiskCacheSize: 50 * 1024 * 1024, // 50 MB LRU cap (Next.js >= 15.5.14 / 16.1.7)
    qualities: [60, 75],
    deviceSizes: [640, 1080, 1920],
    remotePatterns: [
      {
        protocol: 'https',
        hostname: 'media.example.com',
        pathname: '/public/**',
      },
    ],
  },
};

export default nextConfig;

Automated Negative Checks Before You Ship

Lockfile resolution, not package.json ranges, determines which version of next, astro, or sharp runs inside your container. Before promoting a release, inspect the built dependency tree (npm ls next astro sharp) and verify four negative tests in CI or staging:

  • Request an SVG URL and an SVG payload disguised with a .png extension and assert 400 or 403 rejection when SVG support is disabled.
  • Send Host: attacker.example.net without X-Forwarded-Host and confirm neither /_image nor generated absolute URLs reflect that host.
  • Request an unconfigured width (w=1337), an unapproved domain, and a ../ path traversal payload, confirming non-200 rejection across all three.
  • Alert on cache volume usage on self-hosted hosts before disk pressure degrades neighboring services.

Treating /_next/image and /_image as network, filesystem, and native-parser boundaries, and removing them whenever static builds suffice, prevents a performance feature from turning into your next incident response ticket.

[+] On this page 16 topics ▼
FAQ · Common Questions

Frequently Asked Questions

Why does disabling dangerouslyAllowSVG in Next.js not eliminate all SVG exposure?

Configuration flags only help if the validation layer intercepts every malformed request before parsing begins. In CVE-2026-119347 (GHSA-7qx7-33qx-rqx2), self-hosted Next.js deployments could still be forced to route an attacker-supplied SVG into the SVG parser even with dangerouslyAllowSVG set to false, requiring framework upgrades to 15.5.29 or 16.4.5.

Can an Astro /_image vulnerability be fixed by updating @astrojs/node alone?

Not always. In CVE-2026-126364 (GHSA-r3h5-4585-7x3w), the vulnerable case-insensitive path boundary check lived inside the core astro package rather than @astrojs/node, so patching required upgrading astro to 7.4.7 or later. By contrast, the Host header SSRF bug in GHSA-m8p5-r7qv-cx4c was patched in @astrojs/node 11.1.7.

When should a team disable runtime image optimization completely?

If your site publishes marketing pages, documentation, or fixed catalogs that only change during builds, pre-generating responsive AVIF and WebP variants at build time removes the public /_image or /_next/image attack surface altogether without hurting Core Web Vitals.

How should dynamic SVGs be served if users or CMS editors genuinely upload them?

Treat untrusted SVGs as executable XML, never as harmless raster graphics. Serve them from a separate isolated domain or apply both Content-Disposition: attachment and Content-Security-Policy: sandbox so browsers cannot run inline scripts against your main application origin.

Start your project

Need a website that earns trust, ranks in search, and gives your business a stronger digital presence? Start the conversation here.

Official sources used on this page