summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mongo/SConscript1
-rw-r--r--src/mongo/bson/bsonelement.cpp26
-rw-r--r--src/mongo/bson/bsonelement.h1
-rw-r--r--src/mongo/bson/bsonobj.cpp9
-rw-r--r--src/mongo/bson/bsonobj.h8
-rw-r--r--src/mongo/logger/SConscript7
-rw-r--r--src/mongo/logger/component_message_log_domain.cpp4
-rw-r--r--src/mongo/logger/component_message_log_domain.h13
-rw-r--r--src/mongo/logger/redaction.cpp85
-rw-r--r--src/mongo/logger/redaction.h77
-rw-r--r--src/mongo/logger/redaction_test.cpp130
-rw-r--r--src/mongo/util/log.h1
12 files changed, 14 insertions, 348 deletions
diff --git a/src/mongo/SConscript b/src/mongo/SConscript
index 3308fc8db98..bcb05ec6a65 100644
--- a/src/mongo/SConscript
+++ b/src/mongo/SConscript
@@ -88,7 +88,6 @@ baseSource=[
'logger/message_event_utf8_encoder.cpp',
'logger/message_log_domain.cpp',
'logger/ramlog.cpp',
- 'logger/redaction.cpp',
'logger/rotatable_file_manager.cpp',
'logger/rotatable_file_writer.cpp',
'platform/decimal128.cpp',
diff --git a/src/mongo/bson/bsonelement.cpp b/src/mongo/bson/bsonelement.cpp
index fa8e7ff73cd..cea897f74eb 100644
--- a/src/mongo/bson/bsonelement.cpp
+++ b/src/mongo/bson/bsonelement.cpp
@@ -624,12 +624,11 @@ int BSONElement::size() const {
std::string BSONElement::toString(bool includeFieldName, bool full) const {
StringBuilder s;
- toString(s, includeFieldName, full, false);
+ toString(s, includeFieldName, full);
return s.str();
}
-void BSONElement::toString(
- StringBuilder& s, bool includeFieldName, bool full, bool redactValues, int depth) const {
+void BSONElement::toString(StringBuilder& s, bool includeFieldName, bool full, int depth) const {
if (depth > BSONObj::maxToStringRecursionDepth) {
// check if we want the full/complete string
if (full) {
@@ -644,21 +643,6 @@ void BSONElement::toString(
if (includeFieldName && type() != EOO)
s << fieldName() << ": ";
-
- switch (type()) {
- case Object:
- return embeddedObject().toString(s, false, full, redactValues, depth + 1);
- case mongo::Array:
- return embeddedObject().toString(s, true, full, redactValues, depth + 1);
- default:
- break;
- }
-
- if (redactValues) {
- s << "\"###\"";
- return;
- }
-
switch (type()) {
case EOO:
s << "EOO";
@@ -687,6 +671,12 @@ void BSONElement::toString(
case mongo::Bool:
s << (boolean() ? "true" : "false");
break;
+ case Object:
+ embeddedObject().toString(s, false, full, depth + 1);
+ break;
+ case mongo::Array:
+ embeddedObject().toString(s, true, full, depth + 1);
+ break;
case Undefined:
s << "undefined";
break;
diff --git a/src/mongo/bson/bsonelement.h b/src/mongo/bson/bsonelement.h
index 4b1f776696f..ad8429da9be 100644
--- a/src/mongo/bson/bsonelement.h
+++ b/src/mongo/bson/bsonelement.h
@@ -183,7 +183,6 @@ public:
void toString(StringBuilder& s,
bool includeFieldName = true,
bool full = false,
- bool redactValues = false,
int depth = 0) const;
std::string jsonString(JsonStringFormat format,
bool includeFieldNames = true,
diff --git a/src/mongo/bson/bsonobj.cpp b/src/mongo/bson/bsonobj.cpp
index 992e2dd0a89..b57f6bcf88b 100644
--- a/src/mongo/bson/bsonobj.cpp
+++ b/src/mongo/bson/bsonobj.cpp
@@ -603,15 +603,14 @@ int BSONObj::nFields() const {
return n;
}
-std::string BSONObj::toString(bool redactValues) const {
+std::string BSONObj::toString() const {
if (isEmpty())
return "{}";
StringBuilder s;
- toString(s, false, false, redactValues);
+ toString(s, false, false);
return s.str();
}
-void BSONObj::toString(
- StringBuilder& s, bool isArray, bool full, bool redactValues, int depth) const {
+void BSONObj::toString(StringBuilder& s, bool isArray, bool full, int depth) const {
if (isEmpty()) {
s << (isArray ? "[]" : "{}");
return;
@@ -636,7 +635,7 @@ void BSONObj::toString(
first = false;
else
s << ", ";
- e.toString(s, !isArray, full, redactValues, depth);
+ e.toString(s, !isArray, full, depth);
}
s << (isArray ? " ]" : " }");
}
diff --git a/src/mongo/bson/bsonobj.h b/src/mongo/bson/bsonobj.h
index fa405e9f299..2ae4e734279 100644
--- a/src/mongo/bson/bsonobj.h
+++ b/src/mongo/bson/bsonobj.h
@@ -211,12 +211,8 @@ public:
*/
enum { maxToStringRecursionDepth = 100 };
- std::string toString(bool redactValues = false) const;
- void toString(StringBuilder& s,
- bool isArray = false,
- bool full = false,
- bool redactValues = false,
- int depth = 0) const;
+ std::string toString() const;
+ void toString(StringBuilder& s, bool isArray = false, bool full = false, int depth = 0) const;
/** Properly formatted JSON string.
@param pretty if true we try to add some lf's and indentation
diff --git a/src/mongo/logger/SConscript b/src/mongo/logger/SConscript
index e9bd048f1d6..4554deb8dee 100644
--- a/src/mongo/logger/SConscript
+++ b/src/mongo/logger/SConscript
@@ -26,10 +26,3 @@ env.CppUnitTest('rotatable_file_writer_test',
env.CppUnitTest(target='parse_log_component_settings_test',
source='parse_log_component_settings_test.cpp',
LIBDEPS=['$BUILD_DIR/mongo/base', 'parse_log_component_settings'])
-
-env.CppUnitTest(target='redaction_test',
- source='redaction_test.cpp',
- LIBDEPS=[
- '$BUILD_DIR/mongo/base',
- ]
-)
diff --git a/src/mongo/logger/component_message_log_domain.cpp b/src/mongo/logger/component_message_log_domain.cpp
index 9f2964ad38e..9d1b41e9472 100644
--- a/src/mongo/logger/component_message_log_domain.cpp
+++ b/src/mongo/logger/component_message_log_domain.cpp
@@ -79,9 +79,5 @@ void ComponentMessageLogDomain::clearMinimumLoggedSeverity(LogComponent componen
_settings.clearMinimumLoggedSeverity(component);
}
-void ComponentMessageLogDomain::setShouldRedactLogs(bool shouldRedact) {
- _shouldRedact.store(shouldRedact);
-}
-
} // namespace logger
} // namespace mongo
diff --git a/src/mongo/logger/component_message_log_domain.h b/src/mongo/logger/component_message_log_domain.h
index 15f9301e695..49e55e4c160 100644
--- a/src/mongo/logger/component_message_log_domain.h
+++ b/src/mongo/logger/component_message_log_domain.h
@@ -79,21 +79,8 @@ public:
*/
void clearMinimumLoggedSeverity(LogComponent component);
- /**
- * Returns true if system logs should be redacted.
- */
- bool shouldRedactLogs() {
- return _shouldRedact.loadRelaxed();
- }
-
- /**
- * Set the 'redact' mode of the server.
- */
- void setShouldRedactLogs(bool shouldRedact);
-
private:
LogComponentSettings _settings;
- AtomicBool _shouldRedact{false};
};
} // namespace logger
diff --git a/src/mongo/logger/redaction.cpp b/src/mongo/logger/redaction.cpp
deleted file mode 100644
index c66d50fdb83..00000000000
--- a/src/mongo/logger/redaction.cpp
+++ /dev/null
@@ -1,85 +0,0 @@
-/* Copyright 2016 MongoDB Inc.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- * As a special exception, the copyright holders give permission to link the
- * code of portions of this program with the OpenSSL library under certain
- * conditions as described in each individual source file and distribute
- * linked combinations including the program with the OpenSSL library. You
- * must comply with the GNU Affero General Public License in all respects
- * for all of the code used other than as permitted herein. If you modify
- * file(s) with this exception, you may extend this exception to your
- * version of the file(s), but you are not obligated to do so. If you do not
- * wish to do so, delete this exception statement from your version. If you
- * delete this exception statement from all source files in the program,
- * then also delete it in the license file.
- */
-
-#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kDefault
-
-#include "mongo/platform/basic.h"
-
-#include "mongo/logger/redaction.h"
-
-#include "mongo/base/status.h"
-#include "mongo/bson/bsonobj.h"
-#include "mongo/bson/mutable/document.h"
-#include "mongo/util/assert_util.h"
-#include "mongo/util/log.h"
-
-namespace mongo {
-
-std::string redact(const BSONObj& objectToRedact) {
- if (!logger::globalLogDomain()->shouldRedactLogs()) {
- return objectToRedact.toString(false);
- }
-
- return objectToRedact.toString(true);
-}
-
-std::string redact(const std::string& stringToRedact) {
- if (!logger::globalLogDomain()->shouldRedactLogs()) {
- return stringToRedact;
- }
-
- // Return the default mask.
- return kRedactionDefaultMask;
-}
-
-std::string redact(const Status& statusToRedact) {
- if (!logger::globalLogDomain()->shouldRedactLogs()) {
- return statusToRedact.toString();
- }
-
- // Construct a status representation without the reason()
- StringBuilder sb;
- sb << statusToRedact.codeString();
- if (!statusToRedact.isOK())
- sb << ": " << kRedactionDefaultMask;
- if (statusToRedact.location() != 0)
- sb << " @ " << statusToRedact.location();
- return sb.str();
-}
-
-std::string redact(const DBException& exceptionToRedact) {
- if (!logger::globalLogDomain()->shouldRedactLogs()) {
- return exceptionToRedact.toString();
- }
-
- // Construct an exception representation with the what()
- std::stringstream ss;
- ss << exceptionToRedact.getCode() << " " << kRedactionDefaultMask;
- return ss.str();
-}
-
-} // namespace mongo
diff --git a/src/mongo/logger/redaction.h b/src/mongo/logger/redaction.h
deleted file mode 100644
index b5706b2bed6..00000000000
--- a/src/mongo/logger/redaction.h
+++ /dev/null
@@ -1,77 +0,0 @@
-/* Copyright 2016 MongoDB Inc.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- * As a special exception, the copyright holders give permission to link the
- * code of portions of this program with the OpenSSL library under certain
- * conditions as described in each individual source file and distribute
- * linked combinations including the program with the OpenSSL library. You
- * must comply with the GNU Affero General Public License in all respects
- * for all of the code used other than as permitted herein. If you modify
- * file(s) with this exception, you may extend this exception to your
- * version of the file(s), but you are not obligated to do so. If you do not
- * wish to do so, delete this exception statement from your version. If you
- * delete this exception statement from all source files in the program,
- * then also delete it in the license file.
- */
-
-#pragma once
-
-#include <string>
-
-/**
- * The 'redact' methods defined below should be used to redact possibly sensitive
- * information when operating the server in 'redact' mode.
- *
- * The performance impact of calling redact when not in 'redact' mode should be neglectible.
- *
- * The 'redact' methods are designed to be used as part of our log streams
- * log(), LOG(), warning(), error(), severe() similar to the example below.
- *
- * log() << "My sensitive query is: " << query;
- * log() << "My sensitive query is: " << redact(query);
- */
-
-namespace mongo {
-
-class BSONObj;
-class Status;
-class DBException;
-
-const std::string kRedactionDefaultMask = "###";
-
-/**
- * In 'redact' mode replace all values with '###' and keep keys intact.
- * In normal mode return objectToRedact.toString().
- */
-std::string redact(const BSONObj& objectToRedact);
-
-/**
- * In 'redact mode return '###'.
- * In normal mode return stringToRedact.
- */
-std::string redact(const std::string& stringToRedact);
-
-/**
- * In 'redact' mode keep status code and replace reason with '###'.
- * In normal mode return statusToRedact.toString().
- */
-std::string redact(const Status& statusToRedact);
-
-/**
- * In 'redact' mode keep exception type and replace causedBy with '###'.
- * In normal mode return exceptionToRedact.toString().
- */
-std::string redact(const DBException& exceptionToRedact);
-
-} // namespace mongo
diff --git a/src/mongo/logger/redaction_test.cpp b/src/mongo/logger/redaction_test.cpp
deleted file mode 100644
index 46c140eefb8..00000000000
--- a/src/mongo/logger/redaction_test.cpp
+++ /dev/null
@@ -1,130 +0,0 @@
-/**
- * Copyright (C) 2015 MongoDB Inc.
- */
-
-#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kDefault
-
-#include "mongo/logger/redaction.h"
-#include "mongo/db/jsobj.h"
-#include "mongo/unittest/unittest.h"
-#include "mongo/util/log.h"
-
-namespace mongo {
-namespace {
-
-const std::string kRedactionDefaultMask = "###";
-const std::string kMsg = "Not initialized";
-using BSONStringPair = std::pair<BSONObj, std::string>;
-
-TEST(RedactStringTest, NoRedact) {
- logger::globalLogDomain()->setShouldRedactLogs(false);
-
- std::string toRedact[] = {"", "abc", "*&$@!_\\\\\\\"*&$@!_\"*&$@!_\"*&$@!_"};
- for (auto s : toRedact) {
- ASSERT_EQ(redact(s), s);
- }
-}
-
-TEST(RedactStringTest, BasicStrings) {
- logger::globalLogDomain()->setShouldRedactLogs(true);
-
- std::string toRedact[] = {"", "abc", "*&$@!_\\\\\\\"*&$@!_\"*&$@!_\"*&$@!_"};
- for (auto s : toRedact) {
- ASSERT_EQ(redact(s), kRedactionDefaultMask);
- }
-}
-
-TEST(RedactStatusTest, NoRedact) {
- logger::globalLogDomain()->setShouldRedactLogs(false);
- Status status(ErrorCodes::InternalError, kMsg);
- ASSERT_EQ(redact(status), status.toString());
-}
-
-TEST(RedactStatusTest, BasicStatus) {
- logger::globalLogDomain()->setShouldRedactLogs(true);
- Status status(ErrorCodes::InternalError, kMsg);
- ASSERT_EQ(redact(status), "InternalError: " + kRedactionDefaultMask);
-}
-
-TEST(RedactStatusTest, StatusWithLocation) {
- logger::globalLogDomain()->setShouldRedactLogs(true);
- Status status(ErrorCodes::InternalError, kMsg, 777);
- ASSERT_EQ(redact(status), "InternalError: " + kRedactionDefaultMask + " @ 777");
-}
-
-TEST(RedactStatusTest, StatusOK) {
- logger::globalLogDomain()->setShouldRedactLogs(true);
- ASSERT_EQ(redact(Status::OK()), "OK");
-}
-
-TEST(RedactExceptionTest, NoRedact) {
- logger::globalLogDomain()->setShouldRedactLogs(false);
- DBException ex(kMsg, ErrorCodes::InternalError);
- ASSERT_EQ(redact(ex), ex.toString());
-}
-
-TEST(RedactExceptionTest, BasicException) {
- logger::globalLogDomain()->setShouldRedactLogs(true);
- DBException ex(kMsg, ErrorCodes::InternalError);
- ASSERT_EQ(redact(ex), "1 ###");
-}
-
-TEST(RedactBSONTest, NoRedact) {
- logger::globalLogDomain()->setShouldRedactLogs(false);
- BSONObj obj = BSON("a" << 1);
- ASSERT_EQ(redact(obj), obj.toString());
-}
-
-void testBSONCases(std::initializer_list<BSONStringPair> testCases) {
- for (auto m : testCases) {
- ASSERT_EQ(redact(m.first), m.second);
- }
-}
-
-TEST(RedactBSONTest, BasicBSON) {
- logger::globalLogDomain()->setShouldRedactLogs(true);
- std::vector<BSONStringPair> testCases;
-
- testBSONCases({BSONStringPair(BSONObj(), "{}"),
- BSONStringPair(BSON("" << 1), "{ : \"###\" }"),
- BSONStringPair(BSON("a" << 1), "{ a: \"###\" }"),
- BSONStringPair(BSON("a" << 1.0), "{ a: \"###\" }"),
- BSONStringPair(BSON("a"
- << "a"),
- "{ a: \"###\" }"),
- BSONStringPair(BSON("a" << 1 << "b"
- << "str"),
- "{ a: \"###\", b: \"###\" }"),
- BSONStringPair(BSON("a" << 1 << "a"
- << "1"),
- "{ a: \"###\", a: \"###\" }")});
-}
-/*
-TEST(RedactBSONTest, NestedBSON) {
- logger::globalLogDomain()->setShouldRedactLogs(true);
- std::vector<BSONStringPair> testCases;
-
- testCases.push_back(BSONStringPair(BSON("a" << BSONObj()), "{ a: {} }"));
- testCases.push_back(BSONStringPair(
- BSON("a" << BSONObj(BSONObj(BSONObj(BSONObj(BSONObj(BSONObj(BSONObj(BSONObj())))))))),
- "{ a: {} }"));
- testCases.push_back(BSONStringPair(BSON("a" << BSON("a" << 1)), "{ a: { a: \"###\" } }"));
- testCases.push_back(BSONStringPair(BSON("a" << BSON("a" << 1 << "b" << 1)),
- "{ a: { a: \"###\", b: \"###\" } }"));
- testBSONVector(testCases);
-}
-
-TEST(RedactBSONTest, BSONWithArrays) {
- logger::globalLogDomain()->setShouldRedactLogs(true);
- std::vector<BSONStringPair> testCases;
-
- testCases.push_back(BSONStringPair(BSON("a" << BSONArray()), "{ a: [] }"));
- testCases.push_back(
- BSONStringPair(BSON("a" << BSON_ARRAY("abc" << 1)), "{ a: [ \"###\", \"###\" ] }"));
- testCases.push_back(BSONStringPair(BSON("a" << BSON_ARRAY(BSON("a" << 1) << BSON("b" << 1))),
- "{ a: [ { a: \"###\" }, { b: \"###\" } ] }"));
-
- testBSONVector(testCases);
-}*/
-} // namespace
-} // namespace mongo
diff --git a/src/mongo/util/log.h b/src/mongo/util/log.h
index dbd9943e47d..82a78b3cf99 100644
--- a/src/mongo/util/log.h
+++ b/src/mongo/util/log.h
@@ -49,7 +49,6 @@
#include "mongo/logger/log_component.h"
#include "mongo/logger/logger.h"
#include "mongo/logger/logstream_builder.h"
-#include "mongo/logger/redaction.h"
#include "mongo/logger/tee.h"
#include "mongo/util/concurrency/thread_name.h"