Skip to content

Commit 16b69ee

Browse files
committed
fixes
1 parent b477d34 commit 16b69ee

2 files changed

Lines changed: 28 additions & 3 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@hyperbrowser/sdk",
3-
"version": "0.89.4",
3+
"version": "0.90.0",
44
"description": "Node SDK for Hyperbrowser API",
55
"author": "",
66
"repository": {

src/control-auth-helpers.ts

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,33 @@ export function normalizeProfile(value?: string | null): string {
4444
}
4545

4646
export function normalizeControlPlaneBaseUrl(value?: string | null): string {
47-
const normalized = normalizeText(value);
48-
return normalized.replace(/\/+$/, "").replace(/\/api$/, "");
47+
const normalized = normalizeText(value).replace(/\/+$/, "").replace(/\/api$/, "");
48+
if (!normalized) {
49+
return normalized;
50+
}
51+
52+
let parsed: URL;
53+
try {
54+
parsed = new URL(normalized);
55+
} catch (cause) {
56+
throw new ControlAuthError(`Invalid control-plane base URL: ${normalized}`, {
57+
code: "invalid_base_url",
58+
retryable: false,
59+
cause,
60+
});
61+
}
62+
63+
if ((parsed.pathname && parsed.pathname !== "/") || parsed.search || parsed.hash) {
64+
throw new ControlAuthError(
65+
`Control-plane base URL must be an origin (scheme + host [+ port]) with no path, query, or fragment: ${normalized}`,
66+
{
67+
code: "invalid_base_url",
68+
retryable: false,
69+
}
70+
);
71+
}
72+
73+
return normalized;
4974
}
5075

5176
export function normalizeText(value?: string | null): string {

0 commit comments

Comments
 (0)