* Recursively checks an object for dangerous MongoDB operators * @param obj - The object to check * @param dangerousOperators - Array of operator names to block * @returns true if a dangerous operator is found
(obj: unknown, dangerousOperators: string[])
| 47 | * @returns true if a dangerous operator is found |
| 48 | */ |
| 49 | function containsDangerousOperator(obj: unknown, dangerousOperators: string[]): boolean { |
| 50 | if (typeof obj !== 'object' || obj === null) return false |
| 51 | |
| 52 | for (const key of Object.keys(obj as Record<string, unknown>)) { |
| 53 | if (dangerousOperators.includes(key)) return true |
| 54 | if ( |
| 55 | typeof (obj as Record<string, unknown>)[key] === 'object' && |
| 56 | containsDangerousOperator((obj as Record<string, unknown>)[key], dangerousOperators) |
| 57 | ) { |
| 58 | return true |
| 59 | } |
| 60 | } |
| 61 | return false |
| 62 | } |
| 63 | |
| 64 | export function validateFilter(filter: string): { isValid: boolean; error?: string } { |
| 65 | try { |
no outgoing calls
no test coverage detected