Skip to content

Stop /_next/image from fetching any remote host #641

Closed

Description

@HMarzban

Summary

The Next.js image optimizer accepts any remote https host, but no product code uses it. Stop it from fetching remote hosts, so /_next/image cannot fetch and resize arbitrary images at our cost. Local images keep using /_next/image.

Benchmark

Field Value
Metric Remote probe hosts for which /_next/image returns image bytes (count of 3). Also: entries in production images.remotePatterns (count).
Before 2 of 2 probe hosts returned 200 image/png (638 B and 2,499 B), read 2026-11-11 on 0b302b222 in the v2.3.6 milestone review. Its 2 URLs are not in this issue, so the after uses the 3 fixed URLs below. Production images.remotePatterns: 3 entries (https **, two http loopback). On deploy day, before the push, the maintainer probes the 3 fixed URLs in How to run. The maintainer posts them in a Measured comment.
After not measured yet
Condition Production https://docs.plus, after the deploy. Same 3 remote URLs before and after. One machine, curl. Record the date, the deploy hash and who ran each probe.
How to run Remote: curl -s -o /dev/null -w '%{http_code} %{content_type} %{size_download}\n' 'https://docs.plus/_next/image?url=<URL>&w=64&q=75', once for each fixed <URL>: https%3A%2F%2Fupload.wikimedia.org%2Fwikipedia%2Fcommons%2F4%2F47%2FPNG_transparency_demonstration_1.png, https%3A%2F%2Fwww.google.com%2Fimages%2Fbranding%2Fgooglelogo%2F2x%2Fgooglelogo_color_272x92dp.png and https%3A%2F%2Favatars.githubusercontent.com%2Fu%2F9919%3Fv%3D4. None of them is a docs.plus server. Local: the same with url=%2Fdemo-assets%2Fd0-intro.png&w=640&q=75. Code: grep -rln "next/image" apps/webapp/src | wc -l.
Pass rule Remote probe: 400 for 3 of 3 hosts, 0 image bytes. Local probe: 200. Production remotePatterns: 0 entries. next/image imports under apps/webapp/src: 0. Revert if any page in the Guard row loses an image.
Guard Home, /demo, a profile with an avatar, the chat image preview and /privacy show every image, in light and dark, at 390 px and 1280 px.
Owner Agent in the repo: the edit and build:ci. Maintainer: the (build): front push, the probes and the Measured comment.
Claim None for marketing; this is a security fix. Verification line: "/_next/image fetches 0 of 3 remote probe hosts (before: 2 of 2)."

Facts (read from code, not measured)

  • apps/webapp/next.config.js:174-179 sets the first images.remotePatterns entry to protocol: 'https', hostname: '**', pathname: '/**'.
  • apps/webapp/next.config.js:180-191 adds two http loopback entries (*.localhost and the loopback address). Production keeps them today.
  • No file under apps/webapp/src imports next/image (grep at 0b302b222: 0 files).
  • The service worker keeps a same-origin next-image cache rule. It stays harmless once the route serves nothing remote.

Change

  1. Agent in the repo. Remove the '**' entry at apps/webapp/next.config.js:174-179.
  2. Agent in the repo. Keep the two http loopback entries only when process.env.NODE_ENV !== 'production'. Production remotePatterns is then empty.
  3. Agent in the repo. CSP img-src stays as is. Pads load remote images as plain <img>, not through /_next/image.

If a later feature needs next/image for a remote host, add that one host then.

Decision

Ruled 2026-11-10: remove the '**' entry. Do not set images.unoptimized: true. See the maintainer ruling comment of 2026-11-10.

Acceptance

  • Remote probe: 400 on 3 of 3 hosts, 0 image bytes.
  • Local probe: 200.
  • Production remotePatterns: 0 entries (agent reads the built config).
  • next/image imports under apps/webapp/src: 0.
  • These pages show every image: Home, /demo, a profile with an avatar, the chat image preview and /privacy. Check light and dark, at 390 px and 1280 px.
    • Signed-in hand check (profile avatar, chat image preview): not needed (review, 2026-11-16). No file under apps/webapp/src imports next/image or names /_next/image (grep: 0 files), so neither can use the route.
  • build:ci passes before the push.
  • A Measured comment posts the before and after probes, the date, the deploy hash and who ran them.

Rollback

Maintainer: restore the entry and push a (build): front tip.

Found by the proxy and cache map in the #242 architecture review (2026-10-26). Maintainer ruling, 2026-10-26: file it; do not build it in the #242 push.

Activity

  1. added this to the v2.4.0 milestone on Oct 26, 2026
  2. added
    Security
    on Oct 26, 2026
  3. modified the milestones: v2.4.0, v2.3.6 on Nov 9, 2026
  4. HMarzban commented on Nov 10, 2026

    @HMarzban
    CollaboratorAuthor

    Maintainer ruling, 2026-11-10

    Q1: remove the '**' entry from images.remotePatterns. Answer: "agree".

    Do not set images.unoptimized: true. Local images keep working through /_next/image. If a later feature needs next/image for a remote host, add that one host then.

  5. changed the title [-]Turn off the Next.js image optimizer for remote hosts[/-] [+]Stop /_next/image from fetching any remote host[/+] on Nov 11, 2026
  6. HMarzban commented on Nov 14, 2026

    @HMarzban
    CollaboratorAuthor

    Moved to v2.3.7 at the v2.3.6 release audit. The change has not shipped, and the before and after probes are not posted in a Measured comment.

  7. modified the milestones: v2.3.6, v2.3.7 on Nov 14, 2026
  8. HMarzban commented on Nov 16, 2026

    @HMarzban
    CollaboratorAuthor

    Measured, 2026-11-16: production before and after

    Commit 2033adf67: production images.remotePatterns is now empty; the two loopback hosts stay for local runs. Deployed with (build): front back (06f61ee44, run 43876524495, 2026-11-16 13:31Z).

    All probes: one laptop, curl, the 3 fixed URLs from How to run, run by the agent.

    Probe Before (2026-11-16 11:05Z, a3ef6e83f) After, local build (build:ci, next start) After (2026-11-16 13:47Z, 06f61ee44)
    wikimedia PNG, w=64 200 image/png 2,499 B 400, 30 B 400, 30 B
    google logo, w=64 200 image/png 965 B 400, 30 B 400, 30 B
    github avatar, w=64 200 image/png 847 B 400, 30 B 400, 30 B
    local /demo-assets/d0-intro.png, w=640 200 image/png 15,956 B 200 image/png 15,935 B 200 image/png 15,956 B
    Metric Before After
    Remote probe hosts that return image bytes 3 of 3 0 of 3 (none)
    Production remotePatterns entries 3 0 (read from .next/required-server-files.json of the local build)
    next/image imports and /_next/image strings under apps/webapp/src 0 0

    The before is 3 of 3, not the issue's 2 of 2: the issue's earlier 2 URLs were not recorded, so this before uses the 3 fixed URLs.

    Guard

    • /demo on production: 199 <img>, 63 loaded after a full scroll, the rest lazy and not failed. 1 broken: the link icon for github-login.example.net, a fake demo domain served by /api/metadata/icon, not the image route. 0 images use /_next/image.
    • Home and /privacy: 0 <img> in the server HTML; 0 use /_next/image.
    • No page in the app requests /_next/image, so the change cannot remove a picture. The light and dark, 390 px and 1280 px browser pass, the profile avatar and the chat image preview were not checked by hand.

    Gates

    build:ci passed. Prettier passed.

    All acceptance boxes are met except the hand browser pass named above.

  9. HMarzban commented on Nov 16, 2026

    @HMarzban
    CollaboratorAuthor

    Measured, 2026-11-16: the browser guard

    Production https://docs.plus/demo after the deploy (06f61ee44), in a visible browser tab, signed out. Each case loaded the page, scrolled it to the end, waited 4 s, and counted every non-data: <img>.

    Width Theme Images Loaded Pending Broken
    1280 px light (docsplus) 62 61 0 1
    1280 px dark (docsplus-dark, and prefers-color-scheme: dark) 62 61 0 1
    390 px light 62 61 0 1
    390 px dark 62 61 0 1
    • The one broken image is the same in every case: the link icon for github-login.example.net, a fake demo domain, served by /api/metadata/icon. It is not the image route, and it was broken before this change too.
    • 0 images on the page use /_next/image.
    • 390 px is a narrow desktop layout: the mobile shell needs a mobile user agent, so this case checks the narrow width, not the phone shell.
    • Not checked by hand: a profile avatar and the chat image preview, because both need a signed-in session. Neither can use /_next/image, because no file under apps/webapp/src imports next/image or names the route.

    With the production probes posted earlier, every acceptance box is met except that signed-in hand check.

  10. HMarzban commented on Nov 16, 2026

    @HMarzban
    CollaboratorAuthor

    Review, 2026-11-16 (maintainer approved).

    Closed: the fix is live and every check passed. Commit 2033adf67 shipped in (build): front back (06f61ee44, run 43876524495). The 2026-11-16 Measured comments show remote probes at 3 of 3 before and 0 of 3 after, with 400 and 30 B on each host. Production remotePatterns went from 3 entries to 0, and the local probe still answers 200. The browser guard on /demo passed at 390 px and 1280 px, in light and dark. The signed-in hand check is not needed: no file under apps/webapp/src imports next/image or names /_next/image (grep: 0 files). The body now says so. The #796 row stays as filed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    DevOpsSecurity

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions