Skip to content

MaskXmlInvalidCharacters() corrupts supplementary Unicode characters in XmlLayoutSchemaLog4J #290

Closed

Description

@N0tre3l

Summary
MaskXmlInvalidCharacters() in Transform.cs processes UTF-16 code units instead of Unicode code points. This causes supplementary characters (U+10000–U+10FFFF) encoded as surrogate pairs to be replaced with “?”, resulting in silent data corruption in XML log output.

Root Cause
The regex [^\x09\x0A\x0D\x20-\uD7FF\uE000-\uFFFD] operates on UTF-16 char units. Supplementary characters are represented as surrogate pairs, and both surrogates fall outside the allowed range, so both are replaced.

Impact

Silent corruption of non-BMP characters (emoji, CJK extensions, symbols)
Loss of original data in XmlLayoutSchemaLog4J XML output
Affects structured logs consumed by downstream systems

Example
Input: admin🔑
Output: admin?

Suggestion
Use code-point aware processing (surrogate pair handling or XmlConvert.IsXmlChar) instead of regex over UTF-16 code units.

Severity
Low (data integrity issue)

Activity

  1. added a commit that references this issue on Apr 16, 2026
    6f26f14
  2. FreeAndNil commented on Apr 16, 2026

    @FreeAndNil
    Contributor

    @N0tre3l thanks for reporting.
    Can you check whether #291 fixes your problem?

  3. added this to the 3.3.1 milestone on Apr 16, 2026
  4. N0tre3l commented on Apr 16, 2026

    @N0tre3l
    ContributorAuthor

    Yes, #291 fixes it. The regex now matches surrogate pairs first and preserves them, only replacing lone surrogates and other invalid code units

  5. added a commit that references this issue on Apr 16, 2026
    7fcc7f4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions