Details
Recommended Fix
Strip $-prefixed keys from any object that originates from user-controlled parameters before it reaches collection.find/updateOne/deleteOne. A single guard in createObjectIds covers the read, update, and delete paths:
// packages/server/src/integrations/mongodb.ts:394 (createObjectIds)
const DANGEROUS = new Set([
"$where", "$function", "$accumulator",
"$expr", "$regex", "$ne", "$nin", "$gt", "$gte", "$lt", "$lte",
"$or", "$and", "$nor", "$not", "$exists", "$type", "$mod",
"$text", "$comment",
])
function stripOperators(obj: any): any {
if (obj === null || typeof obj !== "object") return obj
if (Array.isArray(obj)) return obj.map(stripOperators)
const cleaned: Record<string, any> = {}
for (const [k, v] of Object.entries(obj)) {
if (DANGEROUS.has(k)) continue
cleaned[k] = stripOperators(v)
}
return cleaned
}
A safer fix mirrors the SQL path: introduce a MongoDB-aware enrichment that binds parameters as values instead of string-substituting them into the query JSON. That eliminates the whole class.
---
*Found by aisafe.io*