ExportXMLWordPrintableJSON

    • None
    • 0.1
    • Dotnet Drivers
    • Not Needed
    • None
    • None
    • None
    • None
    • None
    • None

      Summary

      An app user whose input becomes a field name in a LINQ query can inject aggregation operators or nested paths, silently changing what the query computes or writes.

      Impact

      Attacker-chosen field names are interpreted by the MongoDB server as aggregation operators or nested paths, silently rewriting query semantics and corrupting or misreporting data within the application's database scope, executed with the application's credentials.
      Severity: high
      Exploitability: exploitable — Trivial to trigger: the attacker supplies a string such as '$literal', '$getField', or 'a.b' anywhere the application uses their input as a document key in a LINQ projection; no timing, race, or special environment required.
      Customer data: customer_content (api_response)

      Location

      • src/MongoDB.Driver/Linq/Linq3Implementation/Ast/AstComputedField.cs:50 in RenderAsElement
      • src/MongoDB.Driver/Linq/Linq3Implementation/Ast/AstComputedField.cs:30 in AstComputedField..ctor
      • src/MongoDB.Driver/Linq/Linq3Implementation/Ast/Expressions/AstComputedDocumentExpression.cs:44 in Render
      • src/MongoDB.Driver/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/NewBsonDocumentExpressionToAggregationExpressionTranslator.cs:102 in CreateComputedField
      • src/MongoDB.Driver/Linq/Linq3Implementation/Ast/Optimizers/AstSimplifier.cs:693 in KeyValuePairDocumentToComputedField
      • src/MongoDB.Driver/Linq/Linq3Implementation/Ast/Expressions/AstExpression.cs:234 in ComputedField

      Reproduction / trigger path

      Analyzed trigger path from static analysis — not an executed PoC. Confirm with a concrete repro before handing off.

      Attacker controls: Full control of the field-name string (any non-NUL characters), typically via application input used as a document key in a LINQ projection or as a KeyValuePair/dictionary key; no control over the value expression.

      1. (source) src/MongoDB.Driver/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/NewBsonDocumentExpressionToAggregationExpressionTranslator.cs:102 in CreateComputedField — Any constant-evaluable runtime string (closure variable holding user input) in new BsonDocument(name, value) is extracted and used as the computed field name with no shape check.
      2. (hop) src/MongoDB.Driver/Linq/Linq3Implementation/Ast/Expressions/AstExpression.cs:234 in ComputedField — Shared factory constructs AstComputedField with no validation — the central choke point where a check is absent.
      3. (hop) src/MongoDB.Driver/Linq/Linq3Implementation/Ast/AstComputedField.cs:30 in AstComputedField..ctor — Constructor stores any non-null string; Ensure.IsNotNull is the only check.
      4. (hop) src/MongoDB.Driver/Linq/Linq3Implementation/Ast/AstComputedField.cs:50 in RenderAsElement — The stored path becomes the BsonElement name verbatim; BsonElement validation (BsonElement.cs:95) rejects only NUL characters.
      5. (hop) src/MongoDB.Driver/Linq/Linq3Implementation/Ast/Expressions/AstComputedDocumentExpression.cs:44 in Render — Computed document assembled directly from the unvalidated elements with no $literal wrapping or name sanitization.
      6. (sink) src/MongoDB.Driver/Linq/Linq3Implementation/Translators/ExpressionToExecutableQueryTranslators/ExecutableQuery.cs:113 in Execute — Rendered pipeline stages are sent as an aggregate command to the MongoDB server, whose parser dispatches on '$'-prefixed names as operators and dotted names as nested paths.

      Root cause

      • The AstComputedField constructor validates the path only for null (src/MongoDB.Driver/Linq/Linq3Implementation/Ast/AstComputedField.cs:30), and RenderAsElement emits it verbatim as the BSON element name (AstComputedField.cs:50); Render() at line 45 and AstComputedDocumentExpression.Render (AstComputedDocumentExpression.cs:44) wrap the same element with no sanitization or $literal escaping.
      • The only downstream check, BsonElement.ValidateElementName (src/MongoDB.Bson/ObjectModel/BsonElement.cs:93-99), rejects NUL characters only — '$' prefixes and '.' separators pass.
      • Producers feed arbitrary runtime strings in: NewBsonDocumentExpressionToAggregationExpressionTranslator.CreateComputedField extracts any constant-evaluable string from new BsonDocument(name, value)/Add(name, value) (NewBsonDocumentExpressionToAggregationExpressionTranslator.cs:102), and AstSimplifier's $arrayToObject rewrite lifts runtime KeyValuePair key strings into field-name position (AstSimplifier.cs:686-693). The shared factory AstExpression.ComputedField (AstExpression.cs:232-235) adds no validation.
      • The rendered pipeline is sent unmodified to the server as an aggregate command (ExecutableQuery.cs:158-161, 113-119), where '$'-prefixed element names are interpreted as aggregation operators and dotted names as nested field paths instead of literal keys.

      Ownership

      Assigned teams: @mongodb/dbx-csharp-dotnet


      Filed from Aegis finding 769e55b0bfac (scan scan-320b0a32a42c) · primitive: Attacker-controlled field-name string rendered verbatim into the aggregation pipeline, letting dollar-prefixed or dotted names invoke operators or nested paths server-side. · categories: NoSQL Injection, Data Corruption

      https://docs.google.com/document/d/1osPjSiI-pvMXtrI49QVqwrIK21_nU38fsp7tJlQpDlY/edit?tab=t.0#heading=h.biijq6ke6z0p

            Assignee:
            Adelin Mbida Owona
            Reporter:
            Oleksandr Poliakov
            None
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: