Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]" ||
Expand Down
19 changes: 18 additions & 1 deletion tests/http.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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) => {
Expand Down