Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HMR and some /_next/static/ requests fail through a proxy #77073

Closed
PodkopovP opened this issue Mar 13, 2025 · 9 comments · Fixed by #77395
Closed

HMR and some /_next/static/ requests fail through a proxy #77073

PodkopovP opened this issue Mar 13, 2025 · 9 comments · Fixed by #77395
Labels
Font (next/font) Related to Next.js Font Optimization.

Comments

@PodkopovP
Copy link

PodkopovP commented Mar 13, 2025

Link to the code that reproduces this issue

https://codesandbox.io/p/sandbox/admin-dashboard-ppp3f8

To Reproduce

  1. Start the application in development
  2. Import some Google Next/Font packages
  3. Hit through a proxy (i.e. nginx)

Current vs. Expected behavior

When I hit my Next server through a proxy, my browser should be able to make requests to https://local.test.com/_next/static/media/S6u8w4BMUTPHh30AXC_qNiXg7Q-s.p.01183af7.woff2 for example, and recieve the resource - since 15.2.2, I receieve a 403 Unauthorized error. There are no console errors, and logging in middleware reveals that those errors don't actually even reach the middleware stage.

Using the --hostname flag to replicate my proxy domain, this does work as expected, however this will not work with a multi-tenant system where the proxy domain can be dynamic.

This can be tested quite easily on any Next app by testing using the following request headers in an API agent like Postman:

SUCCESS:

"Origin": "http://localhost:3025"

this is the port it's actually running on, so if I query the page directly without nginx, this is the origin that would be attached

SUCCESS:

"Origin": "http://localhost:1283189273981273981728397123"

just put a random port to see what would happen, and it works

FAILURE:

"Origin": "https://local.hello.com/"

Using a proxy, this is the origin that gets attached, and it fails

I also noticed that since 15.2.2, I have to explicitly set Origin to "" in my Nginx proxy when hitting /_next/webpack-hmr, or else my HMR also fails.

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 23.6.0: Mon Jul 29 21:14:30 PDT 2024; root:xnu-10063.141.2~1/RELEASE_ARM64_T6030
  Available memory (MB): 18432
  Available CPU cores: 11
Binaries:
  Node: 22.9.0
  npm: 10.8.3
  Yarn: 4.1.1
  pnpm: 10.6.2
Relevant Packages:
  next: 15.2.2 // Latest available version is detected (15.2.2).
  eslint-config-next: 15.2.0
  react: 19.0.0
  react-dom: 19.0.0
  typescript: 5.7.3
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Font (next/font)

Which stage(s) are affected? (Select all that apply)

next dev (local)

Additional context

I tested on 15.2.1, and it does work as expected without making any changes. Everything since, and including, 15.2.2, including canary versions, give said errors.

@github-actions github-actions bot added the Font (next/font) Related to Next.js Font Optimization. label Mar 13, 2025
@PodkopovP
Copy link
Author

After some digging, looks like this is the cause: #76880

@cemreinanc
Copy link

We're experiencing this issue as well.

We aren't using a proxy; instead, we resolve all *.localhost DNS queries to 127.0.0.1 to test tenant subdomains such as test.localhost, demo.localhost, etc.

Perhaps if allowedDevOrigins could accept wildcard domains, patterns, or regex, it would simplify configuration.

@tangye1234
Copy link
Contributor

tangye1234 commented Mar 14, 2025

I use frpc to make my dev env to the public ssl nginx env, this issue is truely frustrating me.

@max-degterev
Copy link

max-degterev commented Mar 16, 2025

We aren't using a proxy; instead, we resolve all *.localhost DNS queries to 127.0.0.1

this. bet multitenant demo is broken as well now. what was the last working version? will pin until this is maybe resolved

pin 15.2.1, regression was pushed with 15.2.2

@HenkVanMaanen
Copy link

can confirm. 15.2.1 works. 15.2.2 doesn't work.

@EgorKrasno
Copy link

Seems to still be broken in 15.2.3 for me even with the wildcard fix.

@max-degterev
Copy link

yes it's still broken, not sure why we'd want to block cross origin in dev environment at all actually

@cheeselemon
Copy link

cheeselemon commented Mar 20, 2025

Faced same issue, just tested 15.2.3.

Adding:

const config: NextConfig = {
  allowedDevOrigins: [
    "whatver.i.want"
  ],` 

at next.config.ts fixed the issue.

It seems still wildcard isn't allowed.

Note that experimental.allowedDevOrigins doesn't work.

@max-degterev
Copy link

neither option works, either pin the old version or don't use next/font

ijjk pushed a commit that referenced this issue Mar 24, 2025
…ut (#77395)

To avoid breaking local development proxies and more complex setups,
this ensures that we only block cross-origin development requests when
opting into the configuration. In a future major release, this will not
be opt-in, and will require explicitly providing the allowed origins
that can access the special `/_next` endpoints.

This adds a warning when a cross origin request is detected that would
be blocked without explicit configuration.

Fixes #77073
Fixes #77253
Fixes #77344
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Font (next/font) Related to Next.js Font Optimization.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants