Repository navigation
Conversation
damieng
marked this pull request as ready for review
October 27, 2026 15:32
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The validator accepts root keys that collide with internal path markers, causing filter and update expressions to target root fields instead of the intended subdocument fields.
1 open issue
What changed in this PR
Ports the LINQ field-path validation fix from v3.x to main, preventing application-supplied names from being reinterpreted as nested paths or operators in filters and updates.
Changes:
- Adds shared field-segment validation and array-filter identifier checks.
- Rejects constant null field names in aggregation translators.
- Adds regression tests and documents validation and fallback behavior.
| File | Description |
|---|---|
tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/FilterFieldNameInjectionTests.cs |
Tests unsafe-name rejection and preservation of safe paths. |
src/MongoDB.Driver/Linq/Linq3Implementation/Translators/ExpressionToFilterTranslators/ToFilterFieldTranslators/GetItemMethodToFilterFieldTranslator.cs |
Validates dictionary and BSON indexer keys. |
src/MongoDB.Driver/Linq/Linq3Implementation/Translators/ExpressionToFilterTranslators/ToFilterFieldTranslators/FilterFieldNameValidator.cs |
Adds shared validation and a non-fallback exception. |
src/MongoDB.Driver/Linq/Linq3Implementation/Translators/ExpressionToFilterTranslators/ToFilterFieldTranslators/FieldMethodToFilterFieldTranslator.cs |
Validates Mql.Field names. |
src/MongoDB.Driver/Linq/Linq3Implementation/Translators/ExpressionToFilterTranslators/ToFilterFieldTranslators/AllMatchingElementsMethodToFilterFieldTranslator.cs |
Rejects unsafe array-filter identifiers. |
src/MongoDB.Driver/Linq/Linq3Implementation/Translators/ExpressionToFilterTranslators/MethodTranslators/ContainsKeyMethodToFilterTranslator.cs |
Validates document-represented dictionary keys. |
src/MongoDB.Driver/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/GetItemMethodToAggregationExpressionTranslator.cs |
Rejects constant null BSON indexer keys. |
src/MongoDB.Driver/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/FieldMethodToAggregationExpressionTranslator.cs |
Rejects null aggregation field names. |
src/MongoDB.Driver/Linq/Linq3Implementation/Ast/Filters/AstFilterField.cs |
Identifies implied document paths for validation. |
src/MongoDB.Driver/Linq/Linq3Implementation/Ast/AstFieldName.cs |
Adds array-filter identifier validation. |
src/MongoDB.Driver/Linq/AGENTS.md |
Documents segment validation and rejection without fallback. |
Review effort: Balanced
…llide with path markers
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The test fixture fails before assertions on supported MongoDB 4.4 servers without a version guard, and the validator rejects valid literal marker keys inside $elemMatch.
2 open issues
1 resolved since last review
Review effort: Balanced
adelinowona
requested changes
Nov 7, 2026
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This branch has not been deployed
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 CSHARP-6181 / CSHARP-6183 on main.
A filter or update field path is joined with "." and emitted verbatim as an element name, so a segment taken from application data could be reinterpreted by the server or by the translator: a dotted name became a nested path, a
$-prefixed name became an operator (including$whereviaMql.Field), a null or malformed array filter identifier turned$[i]into$[](every element), and a name equal to one of the translator's own path markers (@<current>,@<elem>) silently targeted the root field instead of the one the expression names.Each segment is now validated at the translator that takes it from a folded constant (dictionary and
BsonValueindexers,ContainsKey,Mql.Field,AllMatchingElements) through a sharedFilterFieldNameValidator. Unsafe names throw rather than falling back to$getField.The path markers are also reachable from the aggregation side:
AstSimplifierturns$anyElementTrue/$mapover a constant array into a filter on the field path, where a leading@<elem>.would be stripped when the filter is rendered. It now declines to do that when the path starts with a marker, so the query stays an$exprthat treats the name as a literal field name.Notes:
AstFieldName.csalready had the null check from CSHARP-6209 on main; the newIsSafeArrayFilterIdentifieris added on top.src/MongoDB.Driver/Linq/AGENTS.mddocuments the segment validation, the marker rule and the simplifier guard.FilterFieldNameInjectionTestsand the fullMongoDB.Driver.Tests.Linqnamespace pass on net10.0.