Class DebugTextSanitizer
A remote client can place CR/LF (or Unicode line/paragraph separators, bidi controls, or other control characters)
into a request URI, header name/value, or body, and — if that text is interpolated verbatim into a log record — forge
additional physical log lines (e.g. a fake status banner) or corrupt a downstream log parser/SIEM. This utility
replaces every such character with a visible, inert escape (
The transform:
- CR (
\\u000D ) →\r , LF (\\u000A ) →\n . - All other C0 controls (
\\u0000 –\\u001F ) except TAB (\\u0009 ) →\\uXXXX . - DEL and C1 controls (
\\u007F –\\u009F , which includes NEL\\u0085 ) →\\uXXXX . - Line separator (
\\u2028 ), paragraph separator (\\u2029 ), and bidi controls (\\u202A –\\u202E ,\\u2066 –\\u2069 ) →\\uXXXX . - TAB (
\\u0009 ) is preserved — it cannot forge a line.
When a length cap is supplied, truncation is applied after escaping, counts sanitized (character) output,
appends a
All methods are thread-safe (the utility is stateless).
See Also:
- Since:
- 10.0.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringMarker appended when a value is truncated by the length cap. -
Method Summary
-
Field Details
-
TRUNCATED_MARKER
Marker appended when a value is truncated by the length cap.- See Also:
-
-
Method Details
-
sanitize
Escapes every log-forging control character in the given string, with no length cap.- Parameters:
value- The string to sanitize. Can benull (returnsnull ).- Returns:
- The sanitized string, or the original reference if nothing needed escaping.
null if the input wasnull .
-
sanitize
Escapes every log-forging control character in the given string, then caps the sanitized output tomaxLencharacters.The cap counts the escaped (rendered) length, appends
…[truncated]when it clips, and never splits an escape sequence or a surrogate pair.- Parameters:
value- The string to sanitize. Can benull (returnsnull ).maxLen- The maximum number of sanitized characters to keep (excluding the truncation marker).- Returns:
- The sanitized (and possibly truncated) string, or the original reference if nothing needed escaping and it
was within the cap.
null if the input wasnull .
-