Skip to content

PHPLIB-1927: Reject "." and NUL bytes in database and collection names - #1968

Merged
kevinAlbs merged 1 commit into
mongodb:v1.21from
GromNaN:PHPLIB-1927-v1.21
Aug 27, 2026
Merged

kevinAlbs merged 1 commit into
mongodb:v1.21from
GromNaN:PHPLIB-1927-v1.21

Conversation

@GromNaN

@GromNaN GromNaN commented Aug 27, 2026 •

Copy link
Copy Markdown
Member

Database and collection names were only checked for being non-empty. A "." in a database name, or a NUL byte in a database or collection name, shifts the namespace split performed by the server, so operations end up targeting a different database or collection than the caller intended.

Reject "." and NUL bytes in database names, and NUL bytes in collection names. Dots remain legal in collection names.

Add a create_namespace() helper that validates both names and returns the concatenated namespace, and use it in Collection, Database, and all Operation classes that build a namespace by concatenating database and collection names (BulkWrite, Delete, Find, InsertMany, InsertOne, RenameCollection, Update).

Move the shared invalid name data provider to the base TestCase, and add prose test 17 for database and collection name validation.

Same as #1967

Database and collection names were only checked for being non-empty. A "." in a database name, or a NUL byte in a database or collection name, shifts the namespace split performed by the server, so operations end up targeting a different database or collection than the caller intended.

Reject "." and NUL bytes in database names, and NUL bytes in collection names. Dots remain legal in collection names.

Add a create_namespace() helper that validates both names and returns the concatenated namespace, and use it in Collection, Database, and all Operation classes that build a namespace by concatenating database and collection names (BulkWrite, Delete, Find, InsertMany, InsertOne, RenameCollection, Update).

Move the shared invalid name data provider to the base TestCase, and add prose test 17 for database and collection name validation.
@GromNaN
GromNaN requested a review from a team as a code owner August 27, 2026 14:28
@GromNaN
GromNaN requested review from paulinevos and a lite review from Copilot August 27, 2026 14:28
@GromNaN
GromNaN enabled auto-merge (squash) August 27, 2026 14:29

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 strengthens namespace safety by validating database and collection names to prevent server-side namespace splitting from silently redirecting operations to unintended targets.

Changes:

  • Introduces an internal create_namespace() helper to validate names and build db.collection namespaces safely.
  • Updates core classes (Database, Collection) and several operations (e.g., Find, Update, BulkWrite, RenameCollection) to use the new validation/namespace construction.
  • Expands and reorganizes test coverage, including adding CRUD prose test 17 and shared invalid-name data providers.

Reviewed changes

Copilot reviewed 21 out of 21 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
tests/TestCase.php Adds a shared data provider for invalid database/collection name combinations.
tests/SpecTests/Crud/Prose17_DatabaseAndCollectionNameValidationTest.php Adds prose test 17 coverage for invalid database/collection names through public APIs.
tests/Operation/UpdateTest.php Adds constructor validation tests for invalid database/collection names.
tests/Operation/RenameCollectionTest.php Adds constructor validation tests for invalid “from/to” database/collection names.
tests/Operation/InsertOneTest.php Adds constructor validation tests for invalid database/collection names.
tests/Operation/InsertManyTest.php Adds constructor validation tests for invalid database/collection names.
tests/Operation/FindTest.php Adds constructor validation tests for invalid database/collection names.
tests/Operation/DeleteTest.php Adds constructor validation tests for invalid database/collection names.
tests/Operation/BulkWriteTest.php Adds constructor validation tests for invalid database/collection names.
tests/Database/DatabaseFunctionalTest.php Expands invalid database name cases to include . and NUL bytes.
tests/Collection/CollectionFunctionalTest.php Splits invalid-name providers, adds explicit test allowing . in collection names, and rejects NUL bytes.
src/Operation/Update.php Uses create_namespace() and stores validated namespace for bulk write execution.
src/Operation/RenameCollection.php Uses create_namespace() for both source and target namespaces.
src/Operation/InsertOne.php Uses create_namespace() and stores validated namespace for bulk write execution.
src/Operation/InsertMany.php Uses create_namespace() and stores validated namespace for bulk write execution.
src/Operation/Find.php Uses create_namespace() and stores validated namespace for query execution.
src/Operation/Delete.php Uses create_namespace() and stores validated namespace for bulk write execution.
src/Operation/BulkWrite.php Uses create_namespace() and stores validated namespace for bulk write execution.
src/functions.php Adds create_namespace() helper for centralized validation/namespace construction.
src/Database.php Extends database name validation to reject . and NUL bytes.
src/Collection.php Extends database name validation to reject . and NUL bytes; extends collection name validation to reject NUL bytes.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/functions.php Resolved
Comment thread src/Database.php Resolved
Comment thread src/Collection.php Resolved
Comment thread src/Collection.php Resolved
@GromNaN
GromNaN disabled auto-merge August 27, 2026 14:39
@GromNaN
GromNaN enabled auto-merge (squash) August 27, 2026 14:39
@GromNaN
GromNaN disabled auto-merge August 27, 2026 14:39
@kevinAlbs
kevinAlbs merged commit 9c3ab63 into mongodb:v1.21 Aug 27, 2026
14 of 15 checks passed
@GromNaN
GromNaN deleted the PHPLIB-1927-v1.21 branch August 27, 2026 14:43
This was referenced Aug 27, 2026
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