Skip to content
Merged
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
15 changes: 10 additions & 5 deletions bin/codedb-bridge.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -51,26 +51,31 @@ export const parseDaemonUrl = (raw) => {
try {
url = new URL(value);
} catch {
throw new Error(`CODEDB_DAEMON_URL="${value}" is not a valid URL`);
// No branch of this function interpolates the raw value or any part
// of the parsed URL into an error (#9829): the caller prints the
// message to stderr, and the value can carry userinfo credentials,
// a ?token= query, or a fragment -- all secrets in host logs. Errors
// name the rejected component only.
throw new Error('CODEDB_DAEMON_URL is not a valid URL (value withheld)');
}
if (url.protocol !== 'http:' || (url.pathname !== '/' && url.pathname !== '')) {
throw new Error(
`CODEDB_DAEMON_URL="${value}" must be an http:// origin with no path (the bridge appends /explore/* routes itself)`
'CODEDB_DAEMON_URL must be an http:// origin with no path (the bridge appends /explore/* routes itself; value withheld)'
);
}
if (url.search) {
throw new Error(
`CODEDB_DAEMON_URL="${value}" must not carry a query string (query "${url.search}") - a query has no meaning for a daemon origin and would be silently dropped`
'CODEDB_DAEMON_URL must not carry a query string - a query has no meaning for a daemon origin and would be silently dropped (query value withheld)'
);
}
if (url.hash) {
throw new Error(
`CODEDB_DAEMON_URL="${value}" must not carry a fragment (fragment "${url.hash}") - a fragment has no meaning for a daemon origin and would be silently dropped`
'CODEDB_DAEMON_URL must not carry a fragment - a fragment has no meaning for a daemon origin and would be silently dropped (fragment value withheld)'
);
}
if (url.username || url.password) {
throw new Error(
`CODEDB_DAEMON_URL="${value}" must not carry userinfo (embedded credentials) - the daemon has no authentication, so credentials would be silently dropped`
'CODEDB_DAEMON_URL must not carry userinfo (embedded credentials) - the daemon has no authentication, so credentials would be silently dropped (userinfo withheld)'
);
}
return url.origin;
Expand Down
33 changes: 33 additions & 0 deletions bin/codedb-bridge.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,39 @@ test('daemon URL rejects query, fragment and userinfo by name instead of silentl
assert.throws(() => parseDaemonUrl('http://user@127.0.0.1:7719'), /CODEDB_DAEMON_URL.*userinfo/);
});

test('daemon URL errors never echo credentials, query values or fragment values (#9829)', () => {
const messageOf = (fn) => {
try {
fn();
} catch (err) {
return err.message;
}
throw new Error('expected parseDaemonUrl to throw');
};
// userinfo branch: neither the username nor the password may appear
// (distinctive sentinels -- the word userinfo itself contains user).
const userinfo = messageOf(() => parseDaemonUrl('http://svcacct:hunterpass@127.0.0.1:7719/'));
assert.match(userinfo, /CODEDB_DAEMON_URL.*userinfo/);
assert.ok(!userinfo.includes('hunterpass'), userinfo);
assert.ok(!userinfo.includes('svcacct'), userinfo);
const userinfoPass = messageOf(() => parseDaemonUrl('http://user:pass@127.0.0.1:7719/'));
assert.ok(!userinfoPass.includes('pass'), userinfoPass);
// query branch: the token value may not appear.
const query = messageOf(() => parseDaemonUrl('http://127.0.0.1:7719/?token=secret'));
assert.match(query, /CODEDB_DAEMON_URL.*query/);
assert.ok(!query.includes('secret'), query);
// fragment branch: the fragment value may not appear.
const fragment = messageOf(() => parseDaemonUrl('http://127.0.0.1:7719/#secretfrag'));
assert.match(fragment, /CODEDB_DAEMON_URL.*fragment/);
assert.ok(!fragment.includes('secretfrag'), fragment);
// the pre-existing branches are covered too: a credentialed value that
// fails URL parsing or the origin check must not be echoed either.
const invalid = messageOf(() => parseDaemonUrl('http://user:pass@127.0.0.1:bad/'));
assert.ok(!invalid.includes('pass'), invalid);
const nonOrigin = messageOf(() => parseDaemonUrl('https://user:pass@127.0.0.1:7719'));
assert.ok(!nonOrigin.includes('pass'), nonOrigin);
});

test('daemon fetch timeout defaults to a named deadline and accepts a positive integer override', () => {
assert.equal(DEFAULT_DAEMON_FETCH_TIMEOUT_MS, 10_000);
assert.equal(parseDaemonFetchTimeoutMs(undefined), DEFAULT_DAEMON_FETCH_TIMEOUT_MS);
Expand Down