Skip to content

Commit 4e0ca52

Browse files
mariusvniekerkcodex
andcommitted
Validate loopback proxy hosts as IP literals
The loopback-only proxy guard should not treat arbitrary DNS names that start with 127. as loopback. Validate hostnames with node:net isIP before accepting the 127.0.0.0/8 range, while continuing to support localhost and IPv6 loopback.\n\nValidation: npm run check; npm test -- src/lib/icons.test.ts src/lib/stores/starred.test.ts; npm run build; npm ci --dry-run; git diff --check; verified proxy rewrites 127.0.0.1 but preserves LAN, foreign, empty, and 127.example.test-style origins. Generated with Codex Co-authored-by: Codex <noreply@openai.com>
1 parent 0758b0d commit 4e0ca52

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

frontend/vite.config.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { execSync } from "node:child_process";
2+
import { isIP } from "node:net";
23
import { defineConfig } from "vite";
34
import { svelte } from "@sveltejs/vite-plugin-svelte";
45

@@ -17,10 +18,12 @@ const apiTargetOrigin = new URL(apiTarget).origin;
1718

1819
function isLoopbackHostname(hostname: string): boolean {
1920
const lower = hostname.toLowerCase();
21+
const unbracketed = lower.startsWith("[") && lower.endsWith("]")
22+
? lower.slice(1, -1)
23+
: lower;
2024
return lower === "localhost" ||
21-
lower === "127.0.0.1" ||
22-
lower.startsWith("127.") ||
23-
lower === "[::1]";
25+
(isIP(unbracketed) === 4 && unbracketed.split(".")[0] === "127") ||
26+
unbracketed === "::1";
2427
}
2528

2629
function requestOriginMatchesLoopbackDevServer(

0 commit comments

Comments
 (0)