Skip to content

Commit c34bf6c

Browse files
mariusvniekerkcodex
andcommitted
Keep loopback proxy host validation self-contained
Avoid relying on prefix checks or additional Node imports for the Vite dev proxy guard. Parse dotted IPv4 literals directly before accepting 127.0.0.0/8, so DNS names such as 127.example.test are not treated as 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 4e0ca52 commit c34bf6c

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

frontend/vite.config.ts

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

@@ -16,13 +15,23 @@ function gitCommit(): string {
1615
const apiTarget = process.env.VITE_API_TARGET ?? "http://127.0.0.1:8080";
1716
const apiTargetOrigin = new URL(apiTarget).origin;
1817

18+
function isIPv4LoopbackLiteral(hostname: string): boolean {
19+
const parts = hostname.split(".");
20+
if (parts.length !== 4 || parts[0] !== "127") return false;
21+
return parts.every((part) => {
22+
if (!/^\d+$/.test(part)) return false;
23+
const value = Number(part);
24+
return value >= 0 && value <= 255;
25+
});
26+
}
27+
1928
function isLoopbackHostname(hostname: string): boolean {
2029
const lower = hostname.toLowerCase();
2130
const unbracketed = lower.startsWith("[") && lower.endsWith("]")
2231
? lower.slice(1, -1)
2332
: lower;
2433
return lower === "localhost" ||
25-
(isIP(unbracketed) === 4 && unbracketed.split(".")[0] === "127") ||
34+
isIPv4LoopbackLiteral(unbracketed) ||
2635
unbracketed === "::1";
2736
}
2837

0 commit comments

Comments
 (0)