Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ To configure a Next.js application to allow requests from origins other than the

```js filename="next.config.js"
module.exports = {
allowedDevOrigins: ['local-origin.dev'],
allowedDevOrigins: ['local-origin.dev', '*.local-origin.dev'],
}
```

Expand Down
7 changes: 3 additions & 4 deletions packages/next/src/server/lib/router-utils/block-cross-site.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { IncomingMessage, ServerResponse } from 'webpack-dev-server'
import { parseUrl } from '../../../lib/url'
import net from 'net'
import { warnOnce } from '../../../build/output/log'
import { isCsrfOriginAllowed } from '../../app-render/csrf-protection'

export const blockCrossSite = (
req: IncomingMessage,
Expand All @@ -25,7 +26,7 @@ export const blockCrossSite = (
}
res.end('Unauthorized')
warnOnce(
`Blocked cross-origin request to /_next/*. To allow this, configure "allowedDevOrigins" in next.config\nRead more: https://nextjs.org/docs/app/api-reference/config/next-config-js/allowedDevOrigins`
`Blocked cross-origin request to /_next/*. Cross-site requests are blocked in "no-cors" mode.`
Copy link
Member Author

@ztanner ztanner Mar 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tweaked this since I'm realizing it's the sec-fetch-mode: no-cors case, which doesn't care about the allowedDevOrigins configuration.

)
return true
}
Expand All @@ -46,9 +47,7 @@ export const blockCrossSite = (
// allow requests if direct IP and matching port and
// allow if any of the allowed origins match
!(isIpRequest && isMatchingPort) &&
!allowedOrigins.some(
(allowedOrigin) => allowedOrigin === originLowerCase
)
!isCsrfOriginAllowed(originLowerCase, allowedOrigins)
) {
if ('statusCode' in res) {
res.statusCode = 403
Expand Down
Loading