Repository navigation
PHPLIB-1927: Reject "." and NUL bytes in database and collection names - #1968
Merged
Merged
Conversation
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.
kevinAlbs
approved these changes
Aug 27, 2026
Contributor
There was a problem hiding this comment.
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 builddb.collectionnamespaces 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.
GromNaN
disabled auto-merge
August 27, 2026 14:39
GromNaN
enabled auto-merge (squash)
August 27, 2026 14:39
GromNaN
disabled auto-merge
August 27, 2026 14:39
Closed
This was referenced Aug 27, 2026
Closed
Merged
Merged
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.
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