Fix: Harden MongoDB query and options handling (fixes #58) - #59
Merged
Conversation
taylortom
force-pushed
the
fix/harden-query-options
branch
from
March 24, 2026 21:48
fc123aa to
e1007c4
Compare
There was a problem hiding this comment.
Pull request overview
This PR hardens MongoDBModule parameter handling by centralizing query/data/options processing into a new processParams utility, adding recursive detection of dangerous MongoDB operators, and tightening which driver options are permitted before calls reach the MongoDB driver.
Changes:
- Add
assertSafeQueryto block$where,$function, and$accumulatoranywhere in query objects. - Add
processParamsto validate/normalize query, data, and an allowlisted set of options, and refactorMongoDBModulemethods to use it. - Add/adjust test coverage for the new utilities and remove the old
parseOptionstests.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/utils-processParams.spec.js | New tests covering query/data/options processing and allowlist behavior. |
| tests/utils-assertSafeQuery.spec.js | New tests for recursive detection of blocked operators. |
| tests/MongoDBModule.spec.js | Removes obsolete parseOptions tests and updates module test description. |
| lib/utils/processParams.js | New shared utility for query/data/options processing and allowlist validation. |
| lib/utils/assertSafeQuery.js | New recursive query validator that blocks JS-execution operators. |
| lib/utils.js | Consolidates utility exports, including processParams/assertSafeQuery. |
| lib/MongoDBModule.js | Refactors CRUD methods to use processParams instead of inline processing. |
| errors/errors.json | Adds new MONGO_BLOCKED_OPERATOR error definition. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…on for limit/skip Co-Authored-By: Thomas Taylor <thomas.taylor@kineo.com>
…ances structuredClone strips the ObjectId prototype, breaking preserved _id values. deepClone recurses only into plain objects and arrays, passing class instances through.
|
🎉 This PR is included in version 3.3.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
taylortom
added a commit
that referenced
this pull request
Jun 6, 2026
|
🎉 This PR is included in version 3.3.2 🎉 The release is available on: Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #58
Fix
$where,$function,$accumulator) that allow arbitrary JS execution on the servercollation,includeResultMetadata,limit,projection,returnCursor,returnDocument,skip,sort,upsertare permittedUpdate
processParamsutility that consolidates query validation, ObjectId conversion,_idstripping, and options parsing into a single functionassertSafeQueryutility for recursive detection of blocked query operatorslib/utils.js) with all utility exportsMongoDBModulemethods by replacing scattered inline processing with singleprocessParamscallTesting
assertSafeQuery(safe operators, blocked operators, nesting, edge cases)processParams(query/data/options processing, immutability, allowlist, value validation)🤖 Generated with Claude Code