T-28: Dev QA-Mongo guard bypass: raw '#' or a second '@' in the host list (guard and driver split the URI authority differently)
This commit is contained in:
parent
34023ee88a
commit
2206515681
4 changed files with 300 additions and 24 deletions
|
|
@ -88,12 +88,22 @@ function isValidMongoHostSegment(segment: string, allowPort: boolean): boolean {
|
|||
return port >= 1 && port <= 65535;
|
||||
}
|
||||
|
||||
function hasControlOrWhitespace(value: string): boolean {
|
||||
for (let i = 0; i < value.length; i++) {
|
||||
const code = value.charCodeAt(i);
|
||||
if (code <= 0x20 || code === 0x7f) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return /\s/.test(value);
|
||||
}
|
||||
|
||||
function isValidMongoUri(uri: string): boolean {
|
||||
if (!uri || /\s/.test(uri)) {
|
||||
if (!uri || hasControlOrWhitespace(uri)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const schemeMatch = /^(mongodb(?:\+srv)?):\/\/(.*)$/i.exec(uri);
|
||||
const schemeMatch = /^(mongodb(?:\+srv)?):\/\/(.*)$/is.exec(uri);
|
||||
const rawScheme = schemeMatch?.[1];
|
||||
const rest = schemeMatch?.[2];
|
||||
if (!rawScheme || !rest) {
|
||||
|
|
@ -101,14 +111,22 @@ function isValidMongoUri(uri: string): boolean {
|
|||
}
|
||||
|
||||
const isSrv = rawScheme.toLowerCase() === 'mongodb+srv';
|
||||
const delimiterMatch = /[/?#]/.exec(rest);
|
||||
// Match mongodb-connection-string-url: authority ends at '/' or '?', never '#'
|
||||
const delimiterMatch = /[/?]/.exec(rest);
|
||||
const authority = delimiterMatch ? rest.slice(0, delimiterMatch.index) : rest;
|
||||
if (!authority) {
|
||||
if (!authority || authority.includes('#')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const atIndex = authority.lastIndexOf('@');
|
||||
const hostList = atIndex >= 0 ? authority.slice(atIndex + 1) : authority;
|
||||
const firstAtIndex = authority.indexOf('@');
|
||||
if (firstAtIndex === 0) {
|
||||
return false;
|
||||
}
|
||||
if (firstAtIndex !== -1 && authority.indexOf('@', firstAtIndex + 1) !== -1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const hostList = firstAtIndex >= 0 ? authority.slice(firstAtIndex + 1) : authority;
|
||||
if (!hostList) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue