summaryrefslogtreecommitdiff
path: root/src/mongo/db
diff options
context:
space:
mode:
authorDaniel Gomez Ferro <daniel.gomezferro@mongodb.com>2021-11-17 16:00:22 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-11-17 17:42:04 +0000
commit3969d6d83bf0199a9a03215d24fe9d8ae585eff3 (patch)
treeb5589b5b67d107875690f86ac27f100cb270dd08 /src/mongo/db
parent1bdff76322b144ef27060fe79324fe3cce4bb17a (diff)
downloadmongo-3969d6d83bf0199a9a03215d24fe9d8ae585eff3.tar.gz
SERVER-60572 Validate collection name for system.buckets.* namespaces
Diffstat (limited to 'src/mongo/db')
-rw-r--r--src/mongo/db/namespace_string.cpp3
-rw-r--r--src/mongo/db/namespace_string_test.cpp9
2 files changed, 11 insertions, 1 deletions
diff --git a/src/mongo/db/namespace_string.cpp b/src/mongo/db/namespace_string.cpp
index e0d068ecf3e..5daec8c5310 100644
--- a/src/mongo/db/namespace_string.cpp
+++ b/src/mongo/db/namespace_string.cpp
@@ -188,7 +188,8 @@ bool NamespaceString::isLegalClientSystemNS(
if (isTemporaryReshardingCollection()) {
return true;
}
- if (isTimeseriesBucketsCollection()) {
+ if (isTimeseriesBucketsCollection() &&
+ validCollectionName(coll().substr(kTimeseriesBucketsCollectionPrefix.size()))) {
return true;
}
if (isChangeStreamPreImagesCollection()) {
diff --git a/src/mongo/db/namespace_string_test.cpp b/src/mongo/db/namespace_string_test.cpp
index bc8b68e2c64..1a81e856e5f 100644
--- a/src/mongo/db/namespace_string_test.cpp
+++ b/src/mongo/db/namespace_string_test.cpp
@@ -127,6 +127,15 @@ TEST(NamespaceStringTest, IsCollectionlessCursorNamespace) {
ASSERT_FALSE(NamespaceString{"$cmd.listCollections"}.isCollectionlessCursorNamespace());
}
+TEST(NamespaceStringTest, IsLegalClientSystemNamespace) {
+ const auto& currentFCV = serverGlobalParams.featureCompatibility;
+ ASSERT_TRUE(NamespaceString{"test.system.buckets.1234"}.isLegalClientSystemNS(currentFCV));
+ ASSERT_TRUE(NamespaceString{"test.system.buckets.abcde"}.isLegalClientSystemNS(currentFCV));
+ ASSERT_FALSE(NamespaceString{"test.system.buckets..1234"}.isLegalClientSystemNS(currentFCV));
+ ASSERT_FALSE(NamespaceString{"test.system.buckets.a234$"}.isLegalClientSystemNS(currentFCV));
+ ASSERT_FALSE(NamespaceString{"test.system.buckets."}.isLegalClientSystemNS(currentFCV));
+}
+
TEST(NamespaceStringTest, IsDropPendingNamespace) {
ASSERT_TRUE(NamespaceString{"test.system.drop.0i0t-1.foo"}.isDropPendingNamespace());
ASSERT_TRUE(NamespaceString{"test.system.drop.1234567i8t9.foo"}.isDropPendingNamespace());