Skip to content

Commit

Permalink
Merge pull request #12465 from zrosenbauer/chore/add-sanitizeFilter-t…
Browse files Browse the repository at this point in the history
…o-types

chore: Add `sanitizeFilter` to types
  • Loading branch information
vkarpov15 committed Sep 25, 2022
2 parents 8a63b6a + 3437840 commit e6ac7e8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
7 changes: 7 additions & 0 deletions test/types/sanitizeFilter.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { FilterQuery, sanitizeFilter } from 'mongoose';
import { expectType } from 'tsd';

const data = { username: 'val', pwd: { $ne: null } };
type Data = typeof data;

expectType<FilterQuery<Data>>(sanitizeFilter<typeof data>(data));
6 changes: 6 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ declare module 'mongoose' {
*/
export function deleteModel(name: string | RegExp): Mongoose;

/**
* Sanitizes query filters against query selector injection attacks by wrapping
* any nested objects that have a property whose name starts with `$` in a `$eq`.
*/
export function sanitizeFilter<T>(filter: FilterQuery<T>): FilterQuery<T>;

/** Gets mongoose options */
export function get<K extends keyof MongooseOptions>(key: K): MongooseOptions[K];

Expand Down

0 comments on commit e6ac7e8

Please sign in to comment.