From a80d05a1efbb2c17cbdc6cbbf1933c2849d48180 Mon Sep 17 00:00:00 2001 From: Focas TCHANHOUN Date: Wed, 2 Dec 2026 15:59:43 +0000 Subject: [PATCH] fix: refuse a base URL with whitespace or control characters URL parsing strips surrounding whitespace and deletes tabs and newlines, so " https://proofline.sh", "https://proofline.sh\n" or a host containing a tab were accepted and silently rewritten. Refuse any character at or below U+0020, as the Python SDK does, naming baseUrl or PROOFLINE_BASE_URL without echoing the value. Co-Authored-By: Claude Opus 5.5 --- src/transport.ts | 11 ++++++----- tests/http.test.mjs | 19 ++++++++++++++++++- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/transport.ts b/src/transport.ts index 1ef377f..243c2b3 100644 --- a/src/transport.ts +++ b/src/transport.ts @@ -135,14 +135,15 @@ function environmentBaseUrl(): string | undefined { } function origin(value: string, name: string): URL { - let url: URL; - try { - url = new URL(value); - } catch { + // Parsing would strip surrounding whitespace and delete tabs and newlines. + if ( + Array.from(value).some((char) => char.charCodeAt(0) <= 32) || + !URL.canParse(value) + ) throw new TypeError( `${name} must be an absolute HTTPS URL or loopback HTTP URL`, ); - } + const url = new URL(value); const loopback = url.hostname === "localhost" || url.hostname === "[::1]" || diff --git a/tests/http.test.mjs b/tests/http.test.mjs index 0a189be..1b3aefb 100644 --- a/tests/http.test.mjs +++ b/tests/http.test.mjs @@ -1736,13 +1736,21 @@ test("without a baseUrl or a non-empty PROOFLINE_BASE_URL the client uses https: ]); }); -test("an unusable PROOFLINE_BASE_URL is refused by name without echoing its value", (t) => { +test("an unusable baseUrl or PROOFLINE_BASE_URL is refused by name without echoing its value", (t) => { const set = withEnvironment(t, "PROOFLINE_BASE_URL", undefined); + // URL parsing strips surrounding whitespace and deletes tabs and newlines. + const rewritten = [ + " https://customer.example", + "https://customer.example ", + "https://customer.example\n", + "https://custo\tmer.example", + ]; for (const value of [ "http://customer.example", "https://user:password-canary@customer.example", "https://customer.example/path", "not a url", + ...rewritten, ]) { set(value); assert.throws( @@ -1758,6 +1766,15 @@ test("an unusable PROOFLINE_BASE_URL is refused by name without echoing its valu () => new ProoflineClient({ baseUrl: "http://customer.example", token }), (error) => error.message.startsWith("baseUrl must be"), ); + for (const baseUrl of rewritten) { + assert.throws( + () => new ProoflineClient({ baseUrl, token }), + (error) => + error instanceof TypeError && + error.message.startsWith("baseUrl must be") && + !error.message.includes(baseUrl), + ); + } }); test("exports preserve CSV cells, opaque cursors and tenant authorization failures", async (t) => {