This is an automated email from the ASF dual-hosted git repository.

yesamer pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-kie.git


The following commit(s) were added to refs/heads/main by this push:
     new 5b27dc35cee [NO-ISSUE] sanitize control characters in DataAuditQuery 
toString (#7268)
5b27dc35cee is described below

commit 5b27dc35cee2e9226ac7638d0dc93c5d2068852a
Author: Jaedon Paget <[email protected]>
AuthorDate: Mon Nov 9 13:51:18 2026 +0000

    [NO-ISSUE] sanitize control characters in DataAuditQuery toString (#7268)
    
    Replace all control characters, not only line terminators, with an 
underscore so
    user-supplied values cannot forge log entries. Add DataAuditQueryTest.
    
    Co-authored-by: Jaedon Paget <[email protected]>
---
 .../kie/kogito/app/audit/api/DataAuditQuery.java   |  4 +-
 .../kogito/app/audit/api/DataAuditQueryTest.java   | 80 ++++++++++++++++++++++
 2 files changed, 83 insertions(+), 1 deletion(-)

diff --git 
a/kogito-data-audit/data-audit-common/src/main/java/org/kie/kogito/app/audit/api/DataAuditQuery.java
 
b/kogito-data-audit/data-audit-common/src/main/java/org/kie/kogito/app/audit/api/DataAuditQuery.java
index 59b2d3ff7f9..8705107dd1f 100644
--- 
a/kogito-data-audit/data-audit-common/src/main/java/org/kie/kogito/app/audit/api/DataAuditQuery.java
+++ 
b/kogito-data-audit/data-audit-common/src/main/java/org/kie/kogito/app/audit/api/DataAuditQuery.java
@@ -65,7 +65,9 @@ public class DataAuditQuery {
         if (value == null) {
             return null;
         }
-        return value.replaceAll("\\R+", "_");
+        // Replace all control characters (CR, LF, tab, null byte, etc.) to 
prevent
+        // CWE-117 Log Forging via user-supplied input reaching the log sink.
+        return value.replaceAll("[\\p{Cntrl}]+", "_");
     }
 
 }
diff --git 
a/kogito-data-audit/data-audit-common/src/test/java/org/kie/kogito/app/audit/api/DataAuditQueryTest.java
 
b/kogito-data-audit/data-audit-common/src/test/java/org/kie/kogito/app/audit/api/DataAuditQueryTest.java
new file mode 100644
index 00000000000..12b916e6510
--- /dev/null
+++ 
b/kogito-data-audit/data-audit-common/src/test/java/org/kie/kogito/app/audit/api/DataAuditQueryTest.java
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+package org.kie.kogito.app.audit.api;
+
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+class DataAuditQueryTest {
+
+    @Test
+    void testToStringWithNullFields() {
+        DataAuditQuery query = new DataAuditQuery();
+        assertThat(query.toString())
+                .isEqualTo("DataAuditQuery [identifier=null, 
graphQLDefinition=null, query=null]");
+    }
+
+    @Test
+    void testToStringWithCleanInput() {
+        DataAuditQuery query = new DataAuditQuery();
+        query.setIdentifier("audit-123");
+        query.setGraphQLDefinition("query { getAudit }");
+        query.setQuery("SELECT * FROM Audit");
+
+        assertThat(query.toString())
+                .isEqualTo("DataAuditQuery [identifier=audit-123, 
graphQLDefinition=query { getAudit }, query=SELECT * FROM Audit]");
+    }
+
+    @Test
+    void testSanitizeSingleControlCharacters() {
+        DataAuditQuery query = new DataAuditQuery();
+        query.setIdentifier("id\nwith\nnewlines");
+        query.setGraphQLDefinition("def\rwith\rcr");
+        query.setQuery("query\twith\ttabs");
+
+        assertThat(query.toString())
+                .isEqualTo("DataAuditQuery [identifier=id_with_newlines, 
graphQLDefinition=def_with_cr, query=query_with_tabs]");
+    }
+
+    @Test
+    void testSanitizeConsecutiveControlCharactersCollapsed() {
+        DataAuditQuery query = new DataAuditQuery();
+        query.setIdentifier("id\r\nwith\r\n\tcrlf");
+        query.setGraphQLDefinition("def\n\n\nmultiple");
+        query.setQuery("query\0null\r\nbyte");
+
+        assertThat(query.toString())
+                .isEqualTo("DataAuditQuery [identifier=id_with_crlf, 
graphQLDefinition=def_multiple, query=query_null_byte]");
+    }
+
+    @Test
+    void testCwe117LogForgingInjectionAttempt() {
+        DataAuditQuery query = new DataAuditQuery();
+        String injectionPayload = "audit-1\r\n2023-01-01 10:00:00 [ERROR] 
Forged log message\r\nidentifier: audit-2";
+        query.setIdentifier(injectionPayload);
+
+        String result = query.toString();
+
+        assertThat(result)
+                .doesNotContain("\r")
+                .doesNotContain("\n")
+                .isEqualTo("DataAuditQuery [identifier=audit-1_2023-01-01 
10:00:00 [ERROR] Forged log message_identifier: audit-2, 
graphQLDefinition=null, query=null]");
+    }
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to