From ebbd50d4fb5eb5eff1c45237822fc4b612cf70f2 Mon Sep 17 00:00:00 2001 From: DongHyeonka Date: Thu, 24 Sep 2026 11:56:31 +0900 Subject: [PATCH] fix(http): reject "." and ".." path values in V3 and V2 (R-3.1) A path value of "." or ".." survives encodeURIComponent unchanged, and URL resolution (V3 `new URL`, V2 `pathname =` assignment) then collapses it into a parent path that still sits under the base URL, so `URL_ORIGIN_ESCAPED` never fired. `/members/{m}` with m=".." pointed at the project instead. The V3 bridge now returns PATH_VALUE_INVALID and the V2 request builder returns PATH_PARAMETER_INVALID for exactly those two values. RED before fix: tests/unit/http-contract-bridge.test.ts "rejects the dot segment ..." and tests/unit/request-builder.test.ts "rejects the dot segment ..." returned ok/success with a parent URL. Gates: check:architecture, check:types:app, check:types:test, lint, test:component pass. test:unit passes except removal-fixture.test.ts, which needs generated artifacts/ release evidence absent in a fresh worktree (unrelated to this change). Co-Authored-By: Claude Opus 5.5 --- src/adapters/http/http-contract-bridge.ts | 9 ++++++- src/adapters/http/request-builder.ts | 3 +++ tests/unit/http-contract-bridge.test.ts | 30 +++++++++++++++++++++++ tests/unit/request-builder.test.ts | 9 +++++++ 4 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 tests/unit/http-contract-bridge.test.ts diff --git a/src/adapters/http/http-contract-bridge.ts b/src/adapters/http/http-contract-bridge.ts index 4413782b..4dd62335 100644 --- a/src/adapters/http/http-contract-bridge.ts +++ b/src/adapters/http/http-contract-bridge.ts @@ -189,7 +189,14 @@ function projectRequestChecked( missing = true; return ""; } - if (value.includes("/") || value.includes("\\")) { + // A dot segment survives encodeURIComponent and URL resolution would + // move the request to a parent path that still passes the base check. + if ( + value.includes("/") || + value.includes("\\") || + value === "." || + value === ".." + ) { invalid = true; return ""; } diff --git a/src/adapters/http/request-builder.ts b/src/adapters/http/request-builder.ts index c213279f..6ead1d9f 100644 --- a/src/adapters/http/request-builder.ts +++ b/src/adapters/http/request-builder.ts @@ -73,6 +73,9 @@ export function buildRequestTarget( if ( serialized.length === 0 || serialized.length > 512 || + // Dot segments are not encoded and pathname assignment normalizes them. + serialized === "." || + serialized === ".." || [...serialized].some((character) => { const code = character.codePointAt(0) ?? 0; return code < 32 || code === 127; diff --git a/tests/unit/http-contract-bridge.test.ts b/tests/unit/http-contract-bridge.test.ts new file mode 100644 index 00000000..429008fd --- /dev/null +++ b/tests/unit/http-contract-bridge.test.ts @@ -0,0 +1,30 @@ +import { describe, expect, it } from "vitest"; + +import { projectRequest } from "../../src/adapters/http/http-contract-bridge.ts"; +import { TEST_DETAIL_HTTP_CONTRACT } from "../helpers/external-contract-fixture.ts"; + +describe("descriptor-driven path projection", () => { + it.each([".", ".."])( + "rejects the dot segment %j instead of letting URL resolution move the target", + (entityId) => { + expect( + projectRequest( + TEST_DETAIL_HTTP_CONTRACT, + { entityId }, + "https://api.test/base/", + ), + ).toEqual({ ok: false, failure: "PATH_VALUE_INVALID" }); + }, + ); + + it("still encodes an ordinary value containing dots", () => { + const outcome = projectRequest( + TEST_DETAIL_HTTP_CONTRACT, + { entityId: "..a." }, + "https://api.test/base/", + ); + expect(outcome.ok && outcome.request.url).toBe( + "https://api.test/base/api/test-entities/..a.", + ); + }); +}); diff --git a/tests/unit/request-builder.test.ts b/tests/unit/request-builder.test.ts index 84902cbe..9ff8e7c2 100644 --- a/tests/unit/request-builder.test.ts +++ b/tests/unit/request-builder.test.ts @@ -62,4 +62,13 @@ describe("deterministic HTTP request target", () => { buildRequestTarget("http://api.test", operation, { resourceId: "one" }), ).toEqual({ success: false, code: "BASE_URL_INVALID" }); }); + + it.each([".", ".."])( + "rejects the dot segment %j instead of letting pathname normalization move the target", + (resourceId) => { + expect( + buildRequestTarget("https://api.test/base/", operation, { resourceId }), + ).toEqual({ success: false, code: "PATH_PARAMETER_INVALID" }); + }, + ); });