Understand any codebase instantly. System intelligence for codebases, built for humans and AI.
TypeScript aiai-memoryclaude-codeclicode-analysiscode-mappingcode-memorycodebase-understandingcodexdeveloper-toolsllmopenclawpersistent-memoryprogram-analysissoftware-architecturesystem-intelligencesystem-mapping
fix(view): proxy only /v1 paths, after resolving dot segments
KageBinary426bcedd7504
diff --git a/ix-cli/src/cli/__tests__/view-server.test.ts b/ix-cli/src/cli/__tests__/view-server.test.tsindex 300d9510..1155accd 100644--- a/ix-cli/src/cli/__tests__/view-server.test.ts+++ b/ix-cli/src/cli/__tests__/view-server.test.ts@@ -383,6 +383,17 @@ describe("view server (/__ix/remap)", () => {});});+ it("proxies only /v1 paths, after resolving dot segments", async () => {+ await withBackend({ IX_VIEW_BACKEND_TOKEN: "tok-123" }, async (seen) => {+ for (const path of ["/v1/../admin", "/v1/%2e%2e/admin", "/v1/%2E%2E/admin", "/v1x", "/v1.."]) {+ expect(await rawStatus("GET", path, { host: `127.0.0.1:${port}` })).toBe(404);+ }+ expect(seen).toHaveLength(0);+ expect(await rawStatus("GET", "/v1/a/../health?x=1", { host: `127.0.0.1:${port}` })).toBe(200);+ expect(seen).toHaveLength(1);+ });+ });+it("forwards no Authorization at all while there is no token", async () => {await withBackend({ IX_VIEW_BACKEND_TOKEN: "" }, async (seen) => {const res = await fetch(`http://127.0.0.1:${port}/v1/health`, { headers: { authorization: "Bearer caller" } });diff --git a/ix-cli/src/cli/commands/view.ts b/ix-cli/src/cli/commands/view.tsindex 8e8e3875..86d07556 100644--- a/ix-cli/src/cli/commands/view.ts+++ b/ix-cli/src/cli/commands/view.ts@@ -413,7 +413,18 @@ const server = http.createServer((req, res) => {// Proxy /v1 requests to backendif (pathname.startsWith("/v1")) {- const backendUrl = BACKEND + pathname + (parsed.search || "");+ // The path the backend will actually be asked for: the URL API resolves+ // dot segments, encoded ones included, exactly as the request will. Only+ // /v1 is proxied, so /v1/../x or /v1x never reaches another backend route+ // carrying this server's token.+ const target = new URL(pathname + (parsed.search || ""), BACKEND);+ if (target.pathname !== "/v1" && !target.pathname.startsWith("/v1/")) {+ req.resume();+ res.writeHead(404, { "Content-Type": "application/json", "Cache-Control": "no-store" });+ res.end(JSON.stringify({ ok: false, error: "not found: " + pathname }));+ return;+ }+ const backendUrl = target.href;const proxyHeaders = { ...req.headers, host: "localhost:8090" };// The backend authenticates this server, not the browser: never forward a// caller's own credentials or origin, and add the token when there is one.