Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
2d9f50a4
Unverified
Commit
2d9f50a4
authored
Sep 30, 2026
by
Sebastian "Sebbie" Silbermann
Committed by
GitHub
Sep 30, 2026
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[lts-active] Fix MCP middleware DNS rebinding (#213)
Co-authored-by:
Karim Rahal
<
karim.rahal@vercel.com
>
parent
bd9214f9
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
17 deletions
+18
-17
block-cross-site-dev.ts
.../next/src/server/lib/router-utils/block-cross-site-dev.ts
+14
-15
get-mcp-middleware.ts
packages/next/src/server/mcp/get-mcp-middleware.ts
+4
-2
No files found.
packages/next/src/server/lib/router-utils/block-cross-site-dev.ts
View file @
2d9f50a4
...
@@ -3,6 +3,7 @@ import type { IncomingMessage, ServerResponse } from 'node:http'
...
@@ -3,6 +3,7 @@ import type { IncomingMessage, ServerResponse } from 'node:http'
import
{
parseUrl
}
from
'../../../lib/url'
import
{
parseUrl
}
from
'../../../lib/url'
import
{
warnOnce
}
from
'../../../build/output/log'
import
{
warnOnce
}
from
'../../../build/output/log'
import
{
isCsrfOriginAllowed
}
from
'../../app-render/csrf-protection'
import
{
isCsrfOriginAllowed
}
from
'../../app-render/csrf-protection'
import
{
parsePath
}
from
'../../../shared/lib/router/utils/parse-path'
const
allowedDevOriginsDocs
=
const
allowedDevOriginsDocs
=
'https://nextjs.org/docs/app/api-reference/config/next-config-js/allowedDevOrigins'
'https://nextjs.org/docs/app/api-reference/config/next-config-js/allowedDevOrigins'
...
@@ -96,21 +97,19 @@ function parseHostnameFromHeader(
...
@@ -96,21 +97,19 @@ function parseHostnameFromHeader(
function
isInternalEndpoint
(
req
:
IncomingMessage
):
boolean
{
function
isInternalEndpoint
(
req
:
IncomingMessage
):
boolean
{
if
(
!
req
.
url
)
return
false
if
(
!
req
.
url
)
return
false
try
{
const
{
pathname
}
=
parsePath
(
req
.
url
)
// TODO: We should standardize on a single prefix for this
const
isMiddlewareRequest
=
req
.
url
.
includes
(
'/__nextjs'
)
// TODO: We should standardize on a single prefix for this
const
isInternalAsset
=
req
.
url
.
includes
(
'/_next'
)
const
isMiddlewareRequest
=
pathname
.
includes
(
'/__nextjs'
)
// Static media requests are excluded, as they might be loaded via CSS and would fail
const
isInternalAsset
=
pathname
.
includes
(
'/_next'
)
// CORS checks.
// Static media requests are excluded, as they might be loaded via CSS and would fail
const
isIgnoredRequest
=
// CORS checks.
req
.
url
.
includes
(
'/_next/image'
)
||
const
isIgnoredRequest
=
req
.
url
.
includes
(
'/_next/static/media'
)
||
pathname
.
includes
(
'/_next/image'
)
||
req
.
url
.
includes
(
'/_next/static/immutable/media'
)
pathname
.
includes
(
'/_next/static/media'
)
||
pathname
.
includes
(
'/_next/static/immutable/media'
)
return
!
isIgnoredRequest
&&
(
isInternalAsset
||
isMiddlewareRequest
)
}
catch
(
err
)
{
return
!
isIgnoredRequest
&&
(
isInternalAsset
||
isMiddlewareRequest
)
return
false
}
}
}
export
const
blockCrossSiteDEV
=
(
export
const
blockCrossSiteDEV
=
(
...
...
packages/next/src/server/mcp/get-mcp-middleware.ts
View file @
2d9f50a4
...
@@ -4,6 +4,8 @@ import {
...
@@ -4,6 +4,8 @@ import {
type
McpServerOptions
,
type
McpServerOptions
,
}
from
'./get-or-create-mcp-server'
}
from
'./get-or-create-mcp-server'
import
{
parseBody
}
from
'../api-utils/node/parse-body'
import
{
parseBody
}
from
'../api-utils/node/parse-body'
import
{
parsePath
}
from
'../../shared/lib/router/utils/parse-path'
import
{
removeTrailingSlash
}
from
'../../shared/lib/router/utils/remove-trailing-slash'
import
{
StreamableHTTPServerTransport
}
from
'next/dist/compiled/@modelcontextprotocol/sdk/server/streamableHttp'
import
{
StreamableHTTPServerTransport
}
from
'next/dist/compiled/@modelcontextprotocol/sdk/server/streamableHttp'
export
function
getMcpMiddleware
(
options
:
McpServerOptions
)
{
export
function
getMcpMiddleware
(
options
:
McpServerOptions
)
{
...
@@ -12,8 +14,8 @@ export function getMcpMiddleware(options: McpServerOptions) {
...
@@ -12,8 +14,8 @@ export function getMcpMiddleware(options: McpServerOptions) {
res
:
ServerResponse
,
res
:
ServerResponse
,
next
:
()
=>
void
next
:
()
=>
void
):
Promise
<
void
>
{
):
Promise
<
void
>
{
const
{
pathname
}
=
new
URL
(
req
.
url
||
''
,
'http://n
'
)
const
{
pathname
}
=
parsePath
(
req
.
url
||
'
'
)
if
(
!
pathname
.
startsWith
(
'/_next/mcp'
)
)
{
if
(
removeTrailingSlash
(
pathname
)
!==
'/_next/mcp'
)
{
return
next
()
return
next
()
}
}
const
mcpServer
=
getOrCreateMcpServer
(
options
)
const
mcpServer
=
getOrCreateMcpServer
(
options
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment