]> jfr.im git - irc/evilnet/znc.git/commitdiff
Hide password in PASS debug lines without : in trailing param
authorAlexey Sokolov <redacted>
Tue, 1 Jun 2021 20:55:35 +0000 (21:55 +0100)
committerAlexey Sokolov <redacted>
Tue, 1 Jun 2021 20:58:07 +0000 (21:58 +0100)
src/ZNCDebug.cpp
test/CMakeLists.txt
test/DebugTest.cpp [new file with mode: 0644]

index 9b7984547b23d03e70ee641231f1e5ecb822c2ee..5e2d1521a3b12ad231660a70037e8bbd80ef012b 100644 (file)
@@ -29,11 +29,16 @@ CString CDebug::Filter(const CString& sUnfilteredLine) {
 
     // If the line is a PASS command to authenticate to a server / znc
     if (sUnfilteredLine.StartsWith("PASS ")) {
+        CString sPrefix = sUnfilteredLine.substr(0, sUnfilteredLine[5] == ':' ? 6 : 5);
+        CString sRest = sUnfilteredLine.substr(sPrefix.length());
+
         VCString vsSafeCopy;
-        sUnfilteredLine.Split(":", vsSafeCopy);
+        sRest.Split(":", vsSafeCopy);
 
         if (vsSafeCopy.size() > 1) {
-            sFilteredLine = vsSafeCopy[0] + ":<censored>";
+            sFilteredLine = sPrefix + vsSafeCopy[0] + ":<censored>";
+        } else {
+            sFilteredLine = sPrefix + "<censored>";
         }
     }
 
index 2710c742df8c98dd173eb9d2ca7249a7506d40fe..4b0745631bdc5f74f42be1ee496594851ab638a9 100644 (file)
@@ -61,7 +61,7 @@ add_executable(unittest_bin EXCLUDE_FROM_ALL
        "ThreadTest.cpp" "NickTest.cpp" "ClientTest.cpp" "NetworkTest.cpp"
        "MessageTest.cpp" "ModulesTest.cpp" "IRCSockTest.cpp" "QueryTest.cpp"
        "StringTest.cpp" "ConfigTest.cpp" "BufferTest.cpp" "UtilsTest.cpp"
-       "UserTest.cpp")
+       "UserTest.cpp" "DebugTest.cpp")
 target_link_libraries(unittest_bin PRIVATE znclib)
 target_include_directories(unittest_bin PRIVATE
        "${GTEST_ROOT}" "${GTEST_ROOT}/include"
diff --git a/test/DebugTest.cpp b/test/DebugTest.cpp
new file mode 100644 (file)
index 0000000..d335d81
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * Copyright (C) 2004-2021 ZNC, see the NOTICE file for details.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <gtest/gtest.h>
+#include <gmock/gmock.h>
+#include <znc/ZNCDebug.h>
+
+TEST(DebugTest, Filter) {
+    EXPECT_EQ(CDebug::Filter("JOIN #znc"), "JOIN #znc");
+    EXPECT_EQ(CDebug::Filter("PASS hunter2"), "PASS <censored>");
+    EXPECT_EQ(CDebug::Filter("PASS :hunter2"), "PASS :<censored>");
+    EXPECT_EQ(CDebug::Filter("PASS user/net:hunter2"), "PASS user/net:<censored>");
+    EXPECT_EQ(CDebug::Filter("PASS :user/net:hunter2"), "PASS :user/net:<censored>");
+    EXPECT_EQ(CDebug::Filter("pass hunter2"), "pass <censored>");
+}