Skip to content

reject unsafe mongo query operators#7695

Merged
ar2rsawseen merged 4 commits into
masterfrom
fix/reject-unsafe-query-operators
Jun 10, 2026
Merged

reject unsafe mongo query operators#7695
ar2rsawseen merged 4 commits into
masterfrom
fix/reject-unsafe-query-operators

Conversation

@ar2rsawseen

Copy link
Copy Markdown
Member

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.

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>
Copilot AI review requested due to automatic review settings June 9, 2026 21:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.parseUserQuery and common.findUnsafeMongoOperator, including logging guidance (common.reqInfo(params)).
  • Clarifies operator policy: allow $expr, reject $where/$function/$accumulator at any depth.

Comment thread CLAUDE.md Outdated
…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>
@ar2rsawseen ar2rsawseen merged commit 697f2fe into master Jun 10, 2026
11 of 16 checks passed
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