Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Add sanitizeFilter to types #12465

Merged
merged 5 commits into from Sep 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions test/types/sanitizeFilter.test.ts
@@ -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
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