reject unsafe mongo query operators#7695
Merged
Merged
Conversation
Validate user-supplied Mongo queries at the API boundary and reject those containing $where/$function/$accumulator instead of stripping them in place. $expr is allowed. Queries are validated as decoded objects (keys only) and either run exactly as submitted or are rejected with 400 - they are never modified. Adds common.parseUserQuery / common.findUnsafeMongoOperator and applies validation at the endpoints that accept a query. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the contributor/agent guidance in CLAUDE.md to standardize how Countly should handle user-supplied MongoDB queries at API boundaries—explicitly rejecting queries containing server-side JS execution operators instead of mutating (stripping) them.
Changes:
- Adds a new “Critical Security Rule” documenting a reject-only policy for user-supplied Mongo queries/filters.
- Provides example usage for
common.parseUserQueryandcommon.findUnsafeMongoOperator, including logging guidance (common.reqInfo(params)). - Clarifies operator policy: allow
$expr, reject$where/$function/$accumulatorat any depth.
Cookiezaurs
approved these changes
Jun 9, 2026
…mple (review) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…p sentinel to a clear message via common.unsafeQueryError Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Validate user-supplied Mongo queries at the API boundary and reject those containing $where/$function/$accumulator instead of stripping them in place. $expr is allowed. Queries are validated as decoded objects (keys only) and either run exactly as submitted or are rejected with 400 - they are never modified. Adds common.parseUserQuery / common.findUnsafeMongoOperator and applies validation at the endpoints that accept a query.