@@ -1605,6 +1605,8 @@ public static boolean isGZIPCompressedDataSafe(byte[] compressedBytes, long maxC
16051605 * The following information are removed:
16061606 * <ul>
16071607 * <li>Characters: Carriage Return (CR), Linefeed (LF) and Tabulation (TAB).</li>
1608+ * <li>Characters: Unicode LINE SEPARATOR and Unicode PARAGRAPH SEPARATOR.</li>
1609+ * <li>Characters: CSI sequences and bare ESC.</li>
16081610 * <li>Leading and trailing spaces.</li>
16091611 * <li>Any HTML tags.</li>
16101612 * </ul><br>
@@ -1633,10 +1635,14 @@ public static String sanitizeLogMessage(String message, int maxMessageLength) {
16331635 }
16341636 //Step 1: Remove any CR/LR/TAB characters as well as leading and trailing spaces
16351637 sanitized = sanitized .replaceAll ("[\\ n\\ r\\ t]" , "" ).trim ();
1636- //Step 2: Remove any HTML tags
1638+ //Step 2: Remove any Unicode LINE SEPARATOR or Unicode PARAGRAPH SEPARATOR as well as leading and trailing spaces
1639+ sanitized = sanitized .replace ("\u2028 " , "" ).replace ("\u2029 " , "" ).trim ();
1640+ //Step 3: Remove ANSI escape sequences as well as leading and trailing spaces
1641+ sanitized = sanitized .replaceAll ("\u001B \\ [[\\ d;]*[a-zA-Z]" , "" ).replace ("\u001B " , "" ).trim ();
1642+ //Step 4: Remove any HTML tags
16371643 PolicyFactory htmlSanitizerPolicy = new HtmlPolicyBuilder ().toFactory ();
16381644 sanitized = htmlSanitizerPolicy .sanitize (sanitized );
1639- //Step 3 : Truncate the string in case of need
1645+ //Step 5 : Truncate the string in case of need
16401646 if (sanitized .length () > maxSanitizedMessageLength ) {
16411647 sanitized = sanitized .substring (0 , maxSanitizedMessageLength );
16421648 }
0 commit comments