Skip to content

Consult server-side encryptedFields when dropping QE collections - #3099

Merged
comandeo-mongo merged 1 commit into
mongodb:masterfrom
comandeo-mongo:qe-drop-encrypted-fields-lookup
Jul 30, 2026
Merged

Consult server-side encryptedFields when dropping QE collections#3099
comandeo-mongo merged 1 commit into
mongodb:masterfrom
comandeo-mongo:qe-drop-encrypted-fields-lookup

Conversation

@comandeo-mongo

@comandeo-mongo comandeo-mongo commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

What changed

Dropping a queryable encryption collection through a client that has auto encryption configured but no encryptedFieldsMap left the enxcol_.<name>.esc/.ecoc metadata collections behind. The listCollections fallback in maybe_drop_emm_collections only ran when the map itself was present, while the client-side-encryption spec (GetEncryptedFields with askDb=true) and PyMongo perform the server lookup whenever auto encryption is configured.

The spec test suite does not catch this: the fle2v2-CreateCollection.yml "DropCollection from remote encryptedFields" test configures the client with encryptedFieldsMap: {}, which is present (and truthy), so only the map-absent case was broken.

Also adds the documentation note required by the spec: supplying an encrypted_fields_map protects against a malicious server advertising false encryptedFields.

Testing

New integration spec covers both the map-absent case (previously failing) and the present-but-empty map case, asserting the metadata collections exist after create and are gone after drop. Ran against a local 9.0.0-rc0 replica set together with explicit_queryable_encryption_spec.rb and queryable_encryption_examples_spec.rb: 8 examples, 0 failures. RuboCop clean on the changed files.

Dropping a queryable encryption collection through a client that has
auto encryption configured without an encryptedFieldsMap left the
enxcol_.<name>.esc/.ecoc metadata collections behind: the listCollections
fallback ran only when the map was present. Per the client-side-encryption
spec (GetEncryptedFields with askDb=true) and the reference implementation,
the server lookup must happen whenever auto encryption is configured.

Also add the spec-mandated documentation note that supplying an
encrypted_fields_map protects against a malicious server advertising
false encryptedFields.
Copilot AI review requested due to automatic review settings July 30, 2026 11:38
@comandeo-mongo
comandeo-mongo requested a review from a team as a code owner July 30, 2026 11:38
@comandeo-mongo
comandeo-mongo requested a review from jamis July 30, 2026 11:38

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 fixes queryable encryption (QE) collection drops when a client has auto encryption enabled but does not supply an encrypted_fields_map, ensuring the driver still consults server-advertised encryptedFields so the QE metadata collections are properly removed.

Changes:

  • Update QE drop logic to consult server-side encryptedFields whenever auto encryption is configured (not only when encrypted_fields_map is present).
  • Add an integration spec covering both the map-absent case and the present-but-empty map case.
  • Document the security implication of relying on server-provided encryptedFields vs providing an encrypted_fields_map.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
lib/mongo/collection/queryable_encryption.rb Adjusts QE metadata-drop behavior to fall back to server encryptedFields whenever auto encryption is enabled.
spec/integration/client_side_encryption/qe_drop_collection_spec.rb Adds an integration regression spec to verify QE metadata collections are removed on drop for both configuration variants.
lib/mongo/client.rb Adds a documentation note about the security benefit of providing encrypted_fields_map.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/mongo/client.rb
Comment on lines +516 to 521
# - Note: Supplying an encrypted_fields_map provides more security
# than relying on an encryptedFields obtained from the server. It
# protects against a malicious server advertising a false
# encryptedFields.
# - Note: If a collection is present on both the encryptedFieldsMap
# and schemaMap, an error will be raised.
@comandeo-mongo
comandeo-mongo merged commit 8d38901 into mongodb:master Jul 30, 2026
220 checks passed
@comandeo-mongo
comandeo-mongo deleted the qe-drop-encrypted-fields-lookup branch July 30, 2026 15:45
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