[SERVER-9309] Database name restrictions should be imposed only on the server, not in the mongo shell Created: 10/Apr/13  Updated: 26/Oct/21  Resolved: 26/Oct/21

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

Type: Bug Priority: Minor - P4
Reporter: Gregor Macadam Assignee: Geert Bosch
Resolution: Won't Fix Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
Duplicate
is duplicated by SERVER-7195 Error accessing a database on unix ho... Closed
Related
is related to SERVER-4584 mongod crashes when trying to create ... Closed
is related to SERVER-6729 restrict database names only on Windo... Closed
Participants:

 Description   

It should be possible to access a database with characters in it's name that are forbidden in windows - when using a windows shell to access a linux server.



 Comments   
Comment by Tad Marshall [ 11/Apr/13 ]

I verified that this is a problem. The JavaScript "DB" constructor calls validDBName() to make sure that the name is valid, but this validates differently on Windows than it does on other platforms:

    static bool validDBName( const string& db ) {
        if ( db.size() == 0 || db.size() > 64 )
            return false;
#ifdef _WIN32
        // We prohibit all FAT32-disallowed characters on Windows
        size_t good = strcspn( db.c_str() , "/\\. \"*<>:|?" );
#else
        // For non-Windows platforms we are much more lenient
        size_t good = strcspn( db.c_str() , "/\\. \"" );
#endif
        return good == db.size();
    }

This is the wrong thing to do whenever a Windows client is connected to a non-Windows server or a non-Windows client is connected to a Windows server. A Windows client will incorrectly reject database names that are valid on the non-Windows server, and a non-Windows client will permit database names that will potentially cause problems on the Windows server.

The DB constructor (db_constructor() in src/mongo/scripting/sm_db.cpp line 765 for SpiderMonkey, or dbInit() in src/mongo/scripting/v8_db.cpp line 388 for V8) should apply rules based on the type of the server on which it will create the database.

Comment by Holger Morch [ 10/Apr/13 ]

We are using a prefix to distinguish between dbs of different type or environment. This prefix is separated by a colon ':' e.g. dev:mytests, tst:nightlyTests. That works on Linux but not on Windows.
Also we may have hashes '#' in the name. I'm not sure if this would work on Windows. On Linux it does.

Comment by Tad Marshall [ 10/Apr/13 ]

Can you give some examples of database names that are being rejected by the shell?

These are rejected by a Windows shell but accepted by a Linux shell?

Generated at Thu Feb 08 03:20:01 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.