You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
switch development origin verification to be opt-in rather than opt-out (#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#77073Fixes#77253Fixes#77344
Copy file name to clipboardExpand all lines: docs/01-app/04-api-reference/05-config/01-next-config-js/allowedDevOrigins.mdx
+2-2
Original file line number
Diff line number
Diff line change
@@ -5,6 +5,8 @@ description: Use `allowedDevOrigins` to configure additional origins that can re
5
5
6
6
{/* The content of this doc is shared between the app and pages router. You can use the `<PagesOnly>Content</PagesOnly>` component to add content that is specific to the Pages Router. Any shared content should not be wrapped in a component. */}
7
7
8
+
Next.js does not automatically block cross-origin requests during development, but will block by default in a future major version of Next.js to prevent unauthorized requesting of internal assets/endpoints that are available in development mode.
9
+
8
10
To configure a Next.js application to allow requests from origins other than the hostname the server was initialized with (`localhost` by default) you can use the `allowedDevOrigins` config option.
9
11
10
12
`allowedDevOrigins` allows you to set additional origins that can be used in development mode. For example, to use `local-origin.dev` instead of only `localhost`, open `next.config.js` and add the `allowedDevOrigins` config:
Cross-origin requests are blocked by default to prevent unauthorized requesting of internal assets/endpoints which are available in development mode. This behavior is similar to other dev servers like `webpack-dev-middleware` to ensure the same protection.
`Cross origin request detected ${originString} to /_next/* resource. In a future major version of Next.js, you will need to explicitly configure "allowedDevOrigins" in next.config to allow this.\nRead more: https://nextjs.org/docs/app/api-reference/config/next-config-js/allowedDevOrigins`
17
+
)
18
+
19
+
returnfalse
20
+
}
21
+
22
+
warnOnce(
23
+
`Blocked cross-origin request ${originString} to /_next/* resource. To allow this, configure "allowedDevOrigins" in next.config\nRead more: https://nextjs.org/docs/app/api-reference/config/next-config-js/allowedDevOrigins`
24
+
)
25
+
26
+
if('statusCode'inres){
27
+
res.statusCode=403
28
+
}
29
+
30
+
res.end('Unauthorized')
31
+
32
+
returntrue
33
+
}
34
+
8
35
exportconstblockCrossSite=(
9
36
req: IncomingMessage,
10
37
res: ServerResponse|Duplex,
11
-
allowedOrigins: string[],
38
+
allowedDevOrigins: string[]|undefined,
39
+
hostname: string|undefined,
12
40
activePort: string
13
41
): boolean=>{
14
-
// only process _next URLs
42
+
// in the future, these will be blocked by default when allowed origins aren't configured.
43
+
// for now, we warn when allowed origins aren't configured
`Blocked cross-origin request from ${originLowerCase}. To allow this, configure "allowedDevOrigins" in next.config\nRead more: https://nextjs.org/docs/app/api-reference/config/next-config-js/allowedDevOrigins`
0 commit comments