summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBernard Gorman <bernard.gorman@gmail.com>2018-04-02 06:18:06 +0100
committerBernard Gorman <bernard.gorman@gmail.com>2018-04-04 17:00:32 +0100
commit718c71966f7a9350cd747604409cd0adb913fb5e (patch)
treeb2b26a2d91de68867e623ab6c3e04136d4049f11 /src
parent7e01d162e7d7dec44dfeca42d5e986bd241b2444 (diff)
downloadmongo-718c71966f7a9350cd747604409cd0adb913fb5e.tar.gz
SERVER-34040 Disallow $changeStream on internal databases and system collections
Diffstat (limited to 'src')
-rw-r--r--src/mongo/db/namespace_string.h3
-rw-r--r--src/mongo/db/pipeline/document_source_change_stream.cpp13
2 files changed, 16 insertions, 0 deletions
diff --git a/src/mongo/db/namespace_string.h b/src/mongo/db/namespace_string.h
index a8fac0a2a58..3e5a0d07793 100644
--- a/src/mongo/db/namespace_string.h
+++ b/src/mongo/db/namespace_string.h
@@ -212,6 +212,9 @@ public:
bool isSystem() const {
return coll().startsWith("system.");
}
+ bool isAdminDB() const {
+ return db() == kAdminDb;
+ }
bool isLocal() const {
return db() == kLocalDb;
}
diff --git a/src/mongo/db/pipeline/document_source_change_stream.cpp b/src/mongo/db/pipeline/document_source_change_stream.cpp
index 6ce6740cc4d..b13ce05cd2d 100644
--- a/src/mongo/db/pipeline/document_source_change_stream.cpp
+++ b/src/mongo/db/pipeline/document_source_change_stream.cpp
@@ -334,6 +334,19 @@ list<intrusive_ptr<DocumentSource>> DocumentSourceChangeStream::createFromBson(
intrusive_ptr<DocumentSource> resumeStage = nullptr;
auto spec = DocumentSourceChangeStreamSpec::parse(IDLParserErrorContext("$changeStream"),
elem.embeddedObject());
+
+ // TODO SERVER-34086: $changeStream may run against the 'admin' database iff
+ // 'allChangesForCluster' is true.
+ uassert(ErrorCodes::InvalidNamespace,
+ str::stream() << "$changeStream may not be opened on the internal " << expCtx->ns.db()
+ << " database",
+ !(expCtx->ns.isAdminDB() || expCtx->ns.isLocal() || expCtx->ns.isConfigDB()));
+
+ uassert(ErrorCodes::InvalidNamespace,
+ str::stream() << "$changeStream may not be opened on the internal " << expCtx->ns.ns()
+ << " collection",
+ !expCtx->ns.isSystem());
+
if (auto resumeAfter = spec.getResumeAfter()) {
ResumeToken token = resumeAfter.get();
ResumeTokenData tokenData = token.getData();