Repository navigation
CSHARP-6181: Reject @<current> and @<elem> filter field names that collide with path markers - #2195
Merged
Merged
Conversation
…llide with path markers
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The field-name validation rejects valid array-element predicates for both marker keys; it should restrict rejection to an @<current> parent and add regression tests inside Any.
1 open issue
What changed in this PR
This follow-up to CSHARP-6181 protects LINQ filter and update paths from field names that collide with internal markers, aligning the v3.x fix with the main-branch work in #2167.
Changes:
- Adds shared marker checks and rejects marker-named fields under implied-document parents.
- Prevents an aggregation rewrite from silently retargeting marker-prefixed field paths.
- Adds regression tests and documents the validation rules.
| File | Description |
|---|---|
tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/FilterFieldNameInjectionTests.cs |
Tests marker rejection and aggregation rewrite behavior. |
src/MongoDB.Driver/Linq/Linq3Implementation/Translators/ExpressionToFilterTranslators/ToFilterFieldTranslators/FilterFieldNameValidator.cs |
Adds validation for internal marker collisions. |
src/MongoDB.Driver/Linq/Linq3Implementation/Ast/Optimizers/AstSimplifier.cs |
Guards the constant-array Any rewrite against marker-prefixed paths. |
src/MongoDB.Driver/Linq/Linq3Implementation/Ast/Filters/AstFilterField.cs |
Centralizes marker recognition helpers. |
src/MongoDB.Driver/Linq/AGENTS.md |
Documents marker validation and the simplifier guard. |
Review effort: Balanced
| throw new UnsafeFilterFieldNameException(expression, $"the name \"{segment}\" contains \".\", which the server would read as a path to a nested field; access each level separately instead, for example x[\"a\"][\"b\"]"); | ||
| } | ||
|
|
||
| if (parent.Ast.IsImpliedDocument && AstFilterField.IsImpliedDocumentMarker(segment)) |
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.

Follow-up to the CSHARP-6181 / CSHARP-6183 fix on v3.x, mirroring the review fix on the main port (#2167).
@<current>and@<elem>are the markers the filter AST uses for the implied document and element. As the first path component they are absorbed byAstFilterField.SubFieldandAstFieldOperationFilter.Render, so a root-level key with either name silently retargeted the root field that followed it. For a rootBsonDocument,x => x[key]["Ssn"] == "v"rendered{ Ssn : "v" }instead of{ "<key>.Ssn" : "v" }.FilterFieldNameValidatornow rejects both names when the parent is the implied document.AstSimplifierdeclines the$anyElementTrue/$maprewrite when the field path starts with a marker, which closes the same retargeting from the aggregation side.Linq/AGENTS.mdnote are updated.The
MongoDB.Driver.Tests.Linqnamespace passes on net10.0.