[SERVER-4558] namespace validation on insert uses substring matching not prefix matching Created: 26/Dec/11  Updated: 06/Dec/22

Status: Backlog
Project: Core Server
Component/s: Internal Code
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Minor - P4
Reporter: Aaron Staple Assignee: Backlog - Query Optimization
Resolution: Unresolved Votes: 2
Labels: neweng, query-44-grooming
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
is duplicated by SERVER-12944 validateUpdate ns Closed
is duplicated by SERVER-16751 Use prefix matching to detect system ... Closed
is duplicated by SERVER-28074 Overly eager check for .system. in co... Closed
Assigned Teams:
Query Optimization
Operating System: ALL
Participants:

 Description   

> c = db.coll.system.namespaces
test.coll.system.namespaces
> c.save({})
> c.findOne()
null

Presumably db.system.namespaces should be protected, but not db.coll.system.namespaces?

I think there are some related validations that should be checked as well.



 Comments   
Comment by Steve Tarzia [ 15/Jul/22 ]

Marking this as minor because the effect is just that users cannot use certain unusual collection names.

Comment by Matt Kangas [ 08/Jan/15 ]

More detail from kevin.pulo@10gen.com, originally provided in SERVER-16751


There are places in the code where we do

if ( strstr(ns, ".system.") )

or

if ( ns.find(".system.") != string::npos )

to detect system namespaces. Such substring matching is incorrect, since it returns true for namespaces like "db.foo.system.bar", which are not usually considered system namespaces. Matching should be prefix-based, as is now done for writes, for example.

This is along the same lines as SERVER-4558 and SERVER-8814, which refer to specific instances of this.

The cases that seem to be present currently are:

$ ag 'strstr *\(.* *"\.system\."'
src/mongo/db/query/get_executor.cpp
571:            if (strstr(ns, ".system.")) {
 
$ ag '\.find *\( *"\.system\."'
src/mongo/db/query/get_executor.cpp
145:                          || (string::npos != ns.find(".system."))
 
src/mongo/db/ops/insert.cpp
188:        if ( coll.find( ".system." ) != string::npos ) {
 
src/mongo/s/commands_admin.cpp
526:                if ( ns.find( ".system." ) != string::npos ) {

This ticket is to request that these occurrences in the code be updated to use prefix matches, not substring matches. Specifically:

Probably somewhere there should be single isSystemNamespace()/isSystemCollection() function(s) for doing this detection consistently.

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