Skip to content

Commit cd971d9

Browse files
NicolappsConvex, Inc.
authored andcommitted
cli: Only serve the anonymous dashboard on localhost URLs (#60059)
GitOrigin-RevId: b7a334db5a741f60c08a5649dc1f85c8232cdd11
1 parent 47e2b21 commit cd971d9

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

‎src/cli/lib/localDeployment/dashboard.ts‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ export async function handleDashboard(
5757
ctx,
5858
dashboardPort,
5959
async (request, response) => {
60+
if (!isLoopbackHost(request.headers.host, dashboardPort)) {
61+
response.statusCode = 403;
62+
response.end();
63+
return;
64+
}
65+
6066
const pathname = new URL(
6167
request.url ?? "/",
6268
// We only want to extract the pathname so the base doesn’t matter
@@ -96,6 +102,19 @@ export async function handleDashboard(
96102
};
97103
}
98104

105+
/**
106+
* The dashboard is only meant to be opened at the URL the CLI prints, so
107+
* requests addressed to any other hostname are not served, even if that
108+
* hostname resolves to 127.0.0.1.
109+
*/
110+
export function isLoopbackHost(host: string | undefined, port: number) {
111+
const normalizedHost = host?.toLowerCase();
112+
return (
113+
normalizedHost === `127.0.0.1:${port}` ||
114+
normalizedHost === `localhost:${port}`
115+
);
116+
}
117+
99118
async function reportSelfHostedEvent(
100119
ctx: Context,
101120
{

0 commit comments

Comments
 (0)