summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKatherine Wu <katherine.wu@mongodb.com>2020-06-18 13:44:06 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-07-10 20:17:38 +0000
commit6c0ac0678f3c159c65c497acf155e964dec43f61 (patch)
treef434f761dbfe696d5ca5208a48a353bf89afc561
parent96cb86d41e4800b0f359a4d25dad2a6a94501e32 (diff)
downloadmongo-6c0ac0678f3c159c65c497acf155e964dec43f61.tar.gz
SERVER-48631 Do not allow renameCollection to create collection which begins with '.'
-rw-r--r--jstests/core/rename.js5
-rw-r--r--src/mongo/db/ops/insert.cpp4
2 files changed, 7 insertions, 2 deletions
diff --git a/jstests/core/rename.js b/jstests/core/rename.js
index 3d31a85d390..08d254bbe29 100644
--- a/jstests/core/rename.js
+++ b/jstests/core/rename.js
@@ -65,6 +65,11 @@ assert.throws(function() {
db.jstests_rename.renameCollection({fail: "fail fail fail"});
}, [], "renameCollection should fail when passed a garbage object");
+// Users should not be able to create a collection beginning with '.' through renameCollection.
+// Auth suites throw InvalidNamespace and others throw IllegalOperation error.
+assert.commandFailedWithCode(b.renameCollection(".foo"),
+ [ErrorCodes.InvalidNamespace, ErrorCodes.IllegalOperation]);
+
db.jstests_rename_d.drop();
db.jstests_rename_e.drop();
diff --git a/src/mongo/db/ops/insert.cpp b/src/mongo/db/ops/insert.cpp
index 207df06bca0..7f27be6d6bd 100644
--- a/src/mongo/db/ops/insert.cpp
+++ b/src/mongo/db/ops/insert.cpp
@@ -184,9 +184,9 @@ Status userAllowedCreateNS(const NamespaceString& ns) {
return Status(ErrorCodes::InvalidNamespace, str::stream() << "Invalid namespace: " << ns);
}
- if (ns.ns().find('$') != std::string::npos) {
+ if (!NamespaceString::validCollectionName(ns.coll())) {
return Status(ErrorCodes::InvalidNamespace,
- str::stream() << "Cannot create a namespace containing '$': " << ns);
+ str::stream() << "Invalid collection name: " << ns.coll());
}
if (serverGlobalParams.clusterRole == ClusterRole::ConfigServer && !ns.isOnInternalDb()) {