Commit 375bb3dad for clamav.net

commit 375bb3dadcba53d6d7ef4dcbd23fa2eecab39e19
Author: Valerie Snyder <valsnyde@cisco.com>
Date:   Mon Nov 16 14:16:39 2026 -0500

    clamsubmit: Restore safe debug diagnostics

    Enable common debug output when -d is selected. Restrict libcurl text diagnostics to known-safe connection-status messages because CURLINFO_TEXT can include cookies and URLs.

    Strengthen the debug-output test to require useful diagnostics while continuing to reject sensitive values.

    CLAM-3108

diff --git a/clamsubmit/clamsubmit.c b/clamsubmit/clamsubmit.c
index 807a98de3..1b85768f0 100644
--- a/clamsubmit/clamsubmit.c
+++ b/clamsubmit/clamsubmit.c
@@ -151,10 +151,48 @@ static size_t write_cb(char *ptr, size_t size, size_t nmemb, void *userdata)
     return chunk_size;
 }

+/** @brief Check whether a libcurl text diagnostic is safe to display. */
+static bool debug_text_is_safe(const char *data, size_t size)
+{
+    static const char *const safe_prefixes[] = {
+        "  Trying ",
+        "ALPN:",
+        "CAfile:",
+        "CApath:",
+        "Connected to ",
+        "Connection #",
+        "Connection timed out",
+        "Could not connect to server",
+        "Established connection to ",
+        "Failed to connect to ",
+        "Hostname ",
+        "HTTP 1.0, assume close after body",
+        "Request completely sent off",
+        "SSL connection using ",
+        "TLSv",
+        "shutting down connection #",
+        "upload completely sent off:",
+        "using HTTP/",
+    };
+    size_t i;
+
+    for (i = 0; i < sizeof(safe_prefixes) / sizeof(safe_prefixes[0]); i++) {
+        size_t prefix_size = strlen(safe_prefixes[i]);
+
+        if (size >= prefix_size && memcmp(data, safe_prefixes[i], prefix_size) == 0) {
+            return true;
+        }
+    }
+
+    return false;
+}
+
 /**
- * @brief Emit connection diagnostics without request headers or bodies.
+ * @brief Emit safe connection diagnostics without request data or credentials.
  *
- * Headers and bodies contain cookies, CSRF tokens, and signed upload fields.
+ * Headers, bodies, and some text diagnostics contain cookies, CSRF tokens,
+ * signed upload fields, or URLs. Only known-safe connection status messages
+ * are displayed.
  */
 static int debug_cb(CURL *curl, curl_infotype type, char *data, size_t size, void *userdata)
 {
@@ -162,7 +200,7 @@ static int debug_cb(CURL *curl, curl_infotype type, char *data, size_t size, voi
     (void)curl;
     (void)userdata;

-    if (type != CURLINFO_TEXT || size == 0) {
+    if (type != CURLINFO_TEXT || size == 0 || !debug_text_is_safe(data, size)) {
         return 0;
     }
     printable_size = size > INT_MAX ? INT_MAX : (int)size;
@@ -682,7 +720,9 @@ int main(int argc, char *argv[])
                 false_positive_name = optarg;
                 break;
             case 'd':
-                g_debug = true;
+                g_debug         = true;
+                logg_verbose    = 1;
+                mprintf_verbose = 1;
                 break;
             case 'h':
                 usage(argv[0], stdout);
diff --git a/unit_tests/clamsubmit_test.py b/unit_tests/clamsubmit_test.py
index a025313bf..84ad95b39 100644
--- a/unit_tests/clamsubmit_test.py
+++ b/unit_tests/clamsubmit_test.py
@@ -412,6 +412,8 @@ class ClamSubmitTest(unittest.TestCase):
         scenario = Scenario()
         result = self.run_client(scenario, self.standard_arguments() + ["-d"])
         self.assertEqual(result.returncode, 0, result.stderr.decode())
+        debug_output = result.stdout + result.stderr
+        self.assertIn(b"libcurl:", debug_output)
         for secret in (
             CSRF_TOKEN,
             FORM_AUTHENTICITY_TOKEN,
@@ -422,7 +424,7 @@ class ClamSubmitTest(unittest.TestCase):
             "submitter@example.com",
         ):
             with self.subTest(secret=secret):
-                self.assertNotIn(secret.encode(), result.stderr)
+                self.assertNotIn(secret.encode(), debug_output)

     def test_cli_validation(self):
         result = subprocess.run(