Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@


// Query-string keys that must never be used as an object key, because writing
// through them mutates Object.prototype for the whole process.
const FORBIDDEN_KEYS = ['__proto__', 'constructor', 'prototype'];

const builtInCasters = {
boolean: (val) => val === 'true',
date: (val) => new Date(val),
Expand Down Expand Up @@ -214,6 +218,11 @@ const getFilter = (filter, params, options) => {
})
.filter(
({ key }) =>
// Keys that would walk into Object.prototype are always rejected:
// `result['__proto__'][op] = value` writes onto the prototype of every
// object in the process (prototype pollution), and neither name is a
// usable Mongo field anyway.
!FORBIDDEN_KEYS.includes(key) &&
!options.blacklist.includes(key) &&
(!options.whitelist || options.whitelist.includes(key))
)
Expand Down