next.js: Error 403 "forbidden" when running 'next dev' through stunnel - Next.js ver. 15.2.2

Link to the code that reproduces this issue

https://github.com/designly1/nextjs-15-2-2-stunnel-issue

To Reproduce

1 . Clone repo 2. cd repo 3. pnpm i 4. Setup a stunnnel reverse proxy:

[dev server]
accept = 443
connect = 3000
cert = /path/to/cert.pem
key = /path/to/key.pem
  1. Run the dev server pnpm dev
  2. Connect via valid SSL domain name
  3. Check dev tools console

Current vs. Expected behavior

Expect no errors but get 403 forbidden errors loading resources from /_next

Image

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 24.3.0: Thu Jan  2 20:23:36 PST 2025; root:xnu-11215.81.4~3/RELEASE_ARM64_T8112
  Available memory (MB): 24576
  Available CPU cores: 8
Binaries:
  Node: 20.18.3
  npm: 11.1.0
  Yarn: 1.22.22
  pnpm: 10.5.2
Relevant Packages:
  next: 15.2.2 // Latest available version is detected (15.2.2).
  eslint-config-next: 15.2.2
  react: 19.0.0
  react-dom: 19.0.0
  typescript: 5.8.2
Next.js Config:
  output: N/A

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

Turbopack, CSS, Font (next/font), Instrumentation, Runtime

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

next dev (local)

Additional context

I tested against different canary versions. Issue was introduced in v15.2.2-canary.3. Reverting to v15.2.2-canary.2 fixes the problem. I also tried running next dev without --turbopack and that did not fix the issue.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 10
  • Comments: 29 (1 by maintainers)

Most upvoted comments

Same here, I’m facing this problem only when accessing through the Cloudflare tunnel, but not on localhost.

Same here via Docker; just upgraded this morning and noticed my fonts were broken because of a 403.

Adding allowedDevOrigins fixes my issue with WebSocket connection and also an issue where fonts were not loading due to a 403 error. Thank you!

The 15.3 canary release seems to have better error logging when this happens:

08:22:44 │    _stripped-project-name_ │  ⚠ Blocked cross-origin request from _stripped_.trycloudflare.com. To allow this, configure "allowedDevOrigins" in next.config
08:22:44 │    _stripped-project-name_ │ Read more: https://nextjs.org/docs/app/api-reference/config/next-config-js/allowedDevOrigins

Adding this to my next.config.ts seems to fix the problem with the fonts not loading:

import type { NextConfig } from "next";

const nextConfig: NextConfig = {
  allowedDevOrigins: ["_stripped_.trycloudflare.com"],
};

export default nextConfig;

But I still get this problem in my console: EDIT: I just had to restart the dev server to fix this problem.

use-websocket.ts:16 WebSocket connection to 'wss://_stripped_.trycloudflare.com/_next/webpack-hmr' failed: 

FYI: as of Next.js 15.2.3, allowedDevOrigins was added to root config (was in experimental).

import type { NextConfig } from "next";

const nextConfig: NextConfig = {
  experimental: {
    allowedDevOrigins: ["d.designly.biz"],
  },
};

export default nextConfig;

Confirmed working for me in 15.2.2.

Can confirm this works on 15.2.2:

import type { NextConfig } from "next";

const nextConfig: NextConfig = {
  experimental: {
    allowedDevOrigins: ["dev.sameeranand.com"],
  },
};

export default nextConfig;

And this does not:

import type { NextConfig } from "next";

const nextConfig: NextConfig = {
  experimental: {
    allowedDevOrigins: ["*.sameeranand.com"],
  },
};

export default nextConfig;

And there I was going crazy with this issue, wildcards are not supported although it does mention in docs. hardcoding fqdn works.

Should this be able to support *.localhost?

As of 15.3.0-canary.17, it doesn’t work (still get the warning that it’s being blocked, but if I explicitly add whatever.localhost it works).

Why do we even need “allowedDevOrigins” what’s the security concern it’s trying to solve.

we have a multi tenant app that uses subdomains for the tenant that broke in dev since 15.2.2. I can confirm that the following fixes it:

import type { NextConfig } from "next";

const nextConfig: NextConfig = {
  experimental: {
      allowedDevOrigins: ["tenant.localhost"],
  },
};

export default nextConfig;

But it would be really nice to support wildcards.

Using subdomains worked before (<= 15.2.1) without issue, so either it was always broke, or it is actually a breaking change.

https://github.com/vercel/next.js/pull/77053 adds wildcard support.

Thanks, can confirm that adding the subdomain.localhost in experimental allowedDevOrigins without the port has resolved the problem. Would be good if wildcards were allowed

This also happens when working on website with subdomains: opening subdomain.localhost:3000 will not load any fonts, other static loads fine