T-9: Multi-host MongoDB URI bypasses the dev QA-Mongo guard

This commit is contained in:
Studio 2026-11-27 11:17:59 -05:00
parent 677658a32f
commit 4b46e809be
5 changed files with 134 additions and 7 deletions

View file

@ -35,15 +35,33 @@ export type ContainerRegistrar = (
) => void;
function extractMongoDatabaseFromUri(uri?: string): string | undefined {
if (!uri) {
const trimmed = uri?.trim();
if (!trimmed) {
return undefined;
}
try {
const db = new URL(uri).pathname.replace(/^\/+/, '').split('/')[0];
return db || undefined;
} catch {
const schemeMatch = /^mongodb(?:\+srv)?:\/\/(.*)$/i.exec(trimmed);
const rest = schemeMatch?.[1];
if (!rest) {
return undefined;
}
const delimiterMatch = /[/?#]/.exec(rest);
if (!delimiterMatch || delimiterMatch[0] !== '/') {
return undefined;
}
const pathPart = rest.slice(delimiterMatch.index).split(/[?#]/, 1)[0] ?? '';
const rawDb = pathPart.replace(/^\/+/, '').split('/')[0];
if (!rawDb) {
return undefined;
}
try {
return decodeURIComponent(rawDb);
} catch {
return rawDb;
}
}
function getInfluxPort(config: { influxPort?: number; ilpPort?: number }): number {