Skip to content

Commit fc37d26

Browse files
manish-bothraclaude
andcommitted
Normalise the collector override and keep its value out of errors
A bare trailing ? or # leaves URL.search and URL.hash empty, so the value passed validation and the appended endpoint became a query or fragment; return origin + pathname with no trailing separator instead. The override can also carry credentials and callers log the error, so the messages no longer echo the value. Jira: A11Y-13909 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent e7d01ac commit fc37d26

2 files changed

Lines changed: 17 additions & 4 deletions

File tree

‎bin/testObservability/helper/constants.js‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,21 @@ const httpsOverride = (name) => {
1212
const value = process.env[name];
1313
if (!value) return undefined;
1414
let parsed;
15+
// The value can carry credentials, and callers log the error, so never echo it back.
1516
try {
1617
parsed = new URL(value);
1718
} catch (err) {
18-
throw new Error(`${name} must be a valid https:// URL, got "${value}"`);
19+
throw new Error(`${name} must be a valid https:// URL`);
1920
}
2021
if (parsed.protocol !== 'https:' || !parsed.hostname) {
21-
throw new Error(`${name} must be an https:// URL, got "${value}"`);
22+
throw new Error(`${name} must be an https:// URL`);
2223
}
2324
if (parsed.search || parsed.hash) {
24-
throw new Error(`${name} must not contain a query or fragment, got "${value}"`);
25+
throw new Error(`${name} must not contain a query or fragment`);
2526
}
26-
return value.replace(/\/+$/, '');
27+
// Normalise to origin + path with no trailing separator: a stray `/`, `?` or `#` would otherwise
28+
// turn the appended endpoint into a query or fragment.
29+
return `${parsed.origin}${parsed.pathname}`.replace(/\/+$/, '');
2730
};
2831

2932
// Overridable so the remote reporter (own install of this package) can target the launching cli's collector

‎test/unit/bin/helpers/utils.js‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,6 +1029,16 @@ describe('utils', () => {
10291029
expect(() => utils.setSystemEnvs(bsConfig)).to.throw(/must not contain a query or fragment/);
10301030
});
10311031

1032+
it('normalises a bare query or fragment delimiter', () => {
1033+
process.env.BROWSERSTACK_TEST_OBSERVABILITY_REMOTE_API_URL = 'https://collector-public.bsstag.com?';
1034+
let bsConfig = { run_settings: { env: null } };
1035+
1036+
utils.setSystemEnvs(bsConfig);
1037+
expect(bsConfig.run_settings.system_env_vars)
1038+
.to.be.an('array')
1039+
.that.includes('BROWSERSTACK_TEST_OBSERVABILITY_API_URL=https://collector-public.bsstag.com');
1040+
});
1041+
10321042
it('trims a trailing slash so endpoint paths are not doubled', () => {
10331043
process.env.BROWSERSTACK_TEST_OBSERVABILITY_REMOTE_API_URL = 'https://collector-public.bsstag.com/';
10341044
let bsConfig = { run_settings: { env: null } };

0 commit comments

Comments
 (0)