From fd6768a60aeb41beab650c29fd25fec306a25a66 Mon Sep 17 00:00:00 2001 From: Drewry Pope Date: Sun, 1 Nov 2026 23:22:18 -0600 Subject: [PATCH] fix(codedb-bridge): reject query/fragment/userinfo in CODEDB_DAEMON_URL (#4198) --- bin/codedb-bridge.mjs | 15 +++++++++++++++ bin/codedb-bridge.test.mjs | 8 ++++++++ 2 files changed, 23 insertions(+) diff --git a/bin/codedb-bridge.mjs b/bin/codedb-bridge.mjs index 457b62b475..6efcc01ac4 100644 --- a/bin/codedb-bridge.mjs +++ b/bin/codedb-bridge.mjs @@ -47,6 +47,21 @@ export const parseDaemonUrl = (raw) => { `CODEDB_DAEMON_URL="${value}" must be an http:// origin with no path (the bridge appends /explore/* routes itself)` ); } + 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` + ); + } + 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` + ); + } + 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` + ); + } return url.origin; }; diff --git a/bin/codedb-bridge.test.mjs b/bin/codedb-bridge.test.mjs index 57b8cd891f..cbe381c5bc 100644 --- a/bin/codedb-bridge.test.mjs +++ b/bin/codedb-bridge.test.mjs @@ -19,6 +19,14 @@ test('daemon URL defaults to the codedb serve origin and rejects non-origins', ( assert.throws(() => parseDaemonUrl('http://127.0.0.1:7719/explore'), /CODEDB_DAEMON_URL/); }); +test('daemon URL rejects query, fragment and userinfo by name instead of silently stripping them (#4198)', () => { + assert.throws(() => parseDaemonUrl('http://127.0.0.1:7719/?token=secret'), /CODEDB_DAEMON_URL.*query/); + assert.throws(() => parseDaemonUrl('http://127.0.0.1:7719/?next=/explore/tree'), /CODEDB_DAEMON_URL.*query/); + assert.throws(() => parseDaemonUrl('http://127.0.0.1:7719/#frag'), /CODEDB_DAEMON_URL.*fragment/); + assert.throws(() => parseDaemonUrl('http://user:pass@127.0.0.1:7719/'), /CODEDB_DAEMON_URL.*userinfo/); + assert.throws(() => parseDaemonUrl('http://user@127.0.0.1:7719'), /CODEDB_DAEMON_URL.*userinfo/); +}); + test('every advertised tool maps to a verified daemon route', () => { const args = { codedb_tree: {},