Check for duplicate `from` fields in DocumentSourceGraphLookup::createFromBson()

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Fixed
    • Priority: Major - P3
    • 9.0.0-rc0, 8.2.12, 8.0.28, 7.0.39, 8.3.7
    • Affects Version/s: 8.0.27
    • Component/s: None
    • None
    • Query Integration
    • Fully Compatible
    • ALL
    • v8.3, v8.2, v8.0, v7.0
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      `$graphLookup`'s full parser (`createFromBson`) uses a hand-written loop that unconditionally overwrites local variables on each matching field name. With duplicate BSON keys - eg `{ from: "A", ..., from: "B" }` - the last value wins at execution time. The lite parser reads the first matching element via `BSONObj::operator[]`, so auth sees a different namespace than the one execution actually queries. This is the root cause of CVE-381.

      The fix adds a `StringDataSet seenFields` before the loop and asserts that each field name appears at most once, matching the behavior of IDL-generated parsers with `strict: true`. Two alternatives were considered:

      1) Migrate `createFromBson` to call `DocumentSourceGraphLookUpSpec::parse()` on master and add `seenFields` only on older branches. The IDL spec exists on master but hasn't been backported, so this would mean two different fix strategies across versions.

      2) Apply `seenFields` uniformly to all versions. This is what we're doing here.

      I think option 2 is preferable - it keeps the backport mechanical and identical across all branches, and the `seenFields` check is straightforward to review in isolation without needing to understand the IDL refactor. The IDL exists for the extensions hybrid search project SPM-4532 and should be guarded behind a feature flag.

            Assignee:
            Finley Lau
            Reporter:
            Finley Lau
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: