Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lock down server IPC address #51378

Merged
merged 2 commits into from
Jun 16, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/next/src/server/lib/render-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,6 @@ export async function initialize(opts: {
return reject(err)
}
})
server.listen(await getFreePort(), opts.hostname)
server.listen(await getFreePort(), '0.0.0.0')
})
}
2 changes: 1 addition & 1 deletion packages/next/src/server/lib/server-ipc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export async function createIpcServer(
)

const ipcPort = await new Promise<number>((resolveIpc) => {
ipcServer.listen(0, server.hostname, () => {
ipcServer.listen(0, '0.0.0.0', () => {
const addr = ipcServer.address()

if (addr && typeof addr === 'object') {
Expand Down
7 changes: 6 additions & 1 deletion packages/next/src/server/lib/server-ipc/invoke-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,13 @@ export const invokeRequest = async (
const http = require('http') as typeof import('http')

try {
// force to 127.0.0.1 as IPC always runs on this hostname
// to avoid localhost issues
const parsedTargetUrl = new URL(targetUrl)
parsedTargetUrl.hostname = '127.0.0.1'

const invokeReq = http.request(
targetUrl,
parsedTargetUrl.toString(),
{
headers: invokeHeaders,
method: requestInit.method,
Expand Down