8000 fix(mongodb): Block arbitrary update operators in _patch data (CWE-943) by marshallswain · Pull Request #3665 · feathersjs/feathers · GitHub
[go: up one dir, main page]

Skip to content

fix(mongodb): Block arbitrary update operators in _patch data (CWE-943)#3665

Merged
daffl merged 2 commits intodovefrom
fix/mongodb-operator-injection
Mar 5, 2026
Merged

fix(mongodb): Block arbitrary update operators in _patch data (CWE-943)#3665
daffl merged 2 commits intodovefrom
fix/mongodb-operator-injection

Conversation

@marshallswain
Copy link
Member
@marshallswain marshallswain commented Mar 4, 2026

Summary

Addresses NoSQL operator injection in _patch() where arbitrary MongoDB update operators pass through directly to findOneAndUpdate().

Approach

Adds a disabledOperators option (defaults to ['$rename']) that drops specified MongoDB update operators from patch data.

$rename is blocked by default since it can expose internal fields. Other operators like $push and $inc remain allowed — the dangerous scenarios they enable (e.g. unsetting passwords, pushing roles) should be caught by schema validation in a properly configured app.

Customizing the denylist

Per-service:

new MongoDBService({
  Model: db.collection('users'),
  disabledOperators: ['$rename', '$unset', '$inc']
})

Per-call:

service.patch(id, data, {
  adapter: { disabledOperators: ['$rename', '$inc'] }
})

Related

@daffl
Copy link
Member
daffl commented Mar 4, 2026

Wasn't it always intended for the operators to be supported?

@marshallswain marshallswain force-pushed the fix/mongodb-operator-injection branch from 71ba234 to 439a146 Compare March 4, 2026 22:43
Add a disabledOperators option (defaults to ['$rename']) that drops
specified MongoDB update operators from patch data before passing
to findOneAndUpdate().

$rename is blocked by default since it can expose internal fields.
Other operators like $push and $inc remain allowed since the dangerous
scenarios they enable (e.g. unsetting passwords, pushing roles) should
be caught by schema validation in a properly configured app.

Apps can customize the denylist via the disabledOperators service option
or per-call via params.adapter.disabledOperators.
@marshallswain marshallswain force-pushed the fix/mongodb-operator-injection branch from 439a146 to 72400a7 Compare March 4, 2026 22:44
@dorakemon
Copy link
dorakemon commented Mar 5, 2026

Thank you so much for fixing

@daffl daffl merged commit 0526ffd into dove Mar 5, 2026
4 checks passed
@daffl daffl deleted the fix/mongodb-operator-injection branch March 5, 2026 17:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

0