[SERVER-75942] Check that database name is valid UTF-8 when creating a new database Created: 11/Apr/23  Updated: 30/Jan/24

Status: Open
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Adi Agrawal Assignee: Backlog - Query Execution
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: File bad_dbname.cpp    
Issue Links:
Depends
is depended on by TOOLS-3286 Investigate changes in SERVER-75942: ... Waiting (Blocked)
Documented
is documented by DOCS-16030 Investigate changes in SERVER-75942: ... Backlog
Duplicate
is duplicated by SERVER-76793 Warn when database names are invalid ... Closed
Related
related to SERVER-80788 Prevent creation of databases with na... Backlog
related to SERVER-76793 Warn when database names are invalid ... Closed
related to SERVER-75659 Investigate why config.databases coll... Closed
related to SERVER-57026 Regular expression is invalid UTF-8 w... Closed
Assigned Teams:
Query Execution
Backwards Compatibility: Minor Change
Operating System: ALL
Steps To Reproduce:

Add bad_dbname.cpp to SConscript (in db_integration_test lib)

Compile

Run buildscripts/resmoke.py run --suite=integration_tests_sharded ./build/install/bin/db_integration_test

Participants:

 Description   
Objective

Have the server validate database names and prohibit invalid UTF-8 when creating a new database. In addition, add a special internal setParameter that disables this validation, so that a mongorestore/mongosync that must preserve these bad names has an escape valve to do so. Also, check if the name is valid during upgrade and block upgrade if the name is invalid (see comment on SERVER-76793).

Original Description

When running the attached bad_dbname.cppscript with mongod, we allow the database name to have an invalid utf-8 character (eg. "name\xbc").

When running with mongos, the sharding catalog manager checks if the dbName already exists. It also does a case insensitive match by filtering on the regex (https://github.com/10gen/mongo/blob/master/src/mongo/db/s/config/sharding_catalog_manager_database_operations.cpp/#L176-L180). In doing so, the regex fails with invalid utf-8 (https://github.com/10gen/mongo/blob/master/src/mongo/db/matcher/expression_leaf.cpp/#L245-L247).

We should not allow creating a database with an invalid utf-8 in any of the cases.

This was motivated by investigating  SERVER-57026 and HELP-43395. We should verify that after this change the invalid entries listed in the tickets cannot be created.



 Comments   
Comment by Kyle Suarez [ 09/Jun/23 ]

cailin.nelson@mongodb.com, I've updated the description.

Adding this to the next query execution quick win bucket.

Comment by Xiaochen Wu [ 06/Jun/23 ]

Considering SERVER-76793 (closed as dup with this ticket), we should check if the name is valid during upgrade and block upgrade if the name is invalid. 

Generated at Thu Feb 08 06:31:27 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.