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'
import
{
parseUrl
}
from
'../../../lib/url'
import
{
warnOnce
}
from
'../../../build/output/log'
import
{
isCsrfOriginAllowed
}
from
'../../app-render/csrf-protection'
import
{
parsePath
}
from
'../../../shared/lib/router/utils/parse-path'
const
allowedDevOriginsDocs
=
'https://nextjs.org/docs/app/api-reference/config/next-config-js/allowedDevOrigins'
...
...
@@ -96,21 +97,19 @@ function parseHostnameFromHeader(
function
isInternalEndpoint
(
req
:
IncomingMessage
):
boolean
{
if
(
!
req
.
url
)
return
false
try
{
// TODO: We should standardize on a single prefix for this
const
isMiddlewareRequest
=
req
.
url
.
includes
(
'/__nextjs'
)
const
isInternalAsset
=
req
.
url
.
includes
(
'/_next'
)
// Static media requests are excluded, as they might be loaded via CSS and would fail
// CORS checks.
const
isIgnoredRequest
=
req
.
url
.
includes
(
'/_next/image'
)
||
req
.
url
.
includes
(
'/_next/static/media'
)
||
req
.
url
.
includes
(
'/_next/static/immutable/media'
)
return
!
isIgnoredRequest
&&
(
isInternalAsset
||
isMiddlewareRequest
)
}
catch
(
err
)
{
return
false
}
const
{
pathname
}
=
parsePath
(
req
.
url
)
// TODO: We should standardize on a single prefix for this
const
isMiddlewareRequest
=
pathname
.
includes
(
'/__nextjs'
)
const
isInternalAsset
=
pathname
.
includes
(
'/_next'
)
// Static media requests are excluded, as they might be loaded via CSS and would fail
// CORS checks.
const
isIgnoredRequest
=
pathname
.
includes
(
'/_next/image'
)
||
pathname
.
includes
(
'/_next/static/media'
)
||
pathname
.
includes
(
'/_next/static/immutable/media'
)
return
!
isIgnoredRequest
&&
(
isInternalAsset
||
isMiddlewareRequest
)
}
export
const
blockCrossSiteDEV
=
(
...
...
packages/next/src/server/mcp/get-mcp-middleware.ts
View file @
2d9f50a4
...
...
@@ -4,6 +4,8 @@ import {
type
McpServerOptions
,
}
from
'./get-or-create-mcp-server'
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'
export
function
getMcpMiddleware
(
options
:
McpServerOptions
)
{
...
...
@@ -12,8 +14,8 @@ export function getMcpMiddleware(options: McpServerOptions) {
res
:
ServerResponse
,
next
:
()
=>
void
):
Promise
<
void
>
{
const
{
pathname
}
=
new
URL
(
req
.
url
||
''
,
'http://n
'
)
if
(
!
pathname
.
startsWith
(
'/_next/mcp'
)
)
{
const
{
pathname
}
=
parsePath
(
req
.
url
||
'
'
)
if
(
removeTrailingSlash
(
pathname
)
!==
'/_next/mcp'
)
{
return
next
()
}
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