Skip to content

sanitize SD-ID and MSGID in Rfc5424Layout - #4235

Open
jmestwa-coder wants to merge 1 commit into
apache:2.xfrom
jmestwa-coder:rfc5424-sd-id-sanitize
Open

sanitize SD-ID and MSGID in Rfc5424Layout#4235
jmestwa-coder wants to merge 1 commit into
apache:2.xfrom
jmestwa-coder:rfc5424-sd-id-sanitize

Conversation

@jmestwa-coder

Copy link
Copy Markdown

Rfc5424Layout sanitizes SD-PARAM-NAME and escapes SD-PARAM-VALUE, but two neighboring fields of the same record go out unmodified:

  • appendMessageId appends StructuredDataMessage.getType() raw, so a newline in the type ends the record and what follows is read as a separate syslog message
  • formatStructuredElement appends the SD-ID raw, so a ] closes the element early and the remainder reads as a second, caller-controlled element
  • neither setType nor the StructuredDataId constructors check characters, only length, and both fields carry application data

new StructuredDataMessage("a] [forged@1 user=\"root", "login ok", "Audit\n<13>1 - - - - -") through a Syslog appender, before:

<128>1 1970-01-01T05:30:00.001+05:30 host - 95177 Audit
<13>1 - - - - - [a] [forged@1 user="root] login ok

after:

<128>1 1970-01-01T05:30:00.001+05:30 host - 95119 Audit?<13>1?-?-?-?-?- [a??[forged@1?user??root] login ok

Same ? replacement #4073 introduced for parameter names. SD-ID reuses the SD-NAME rule since RFC 5424 gives both fields the same production, MSGID keeps the wider printable US-ASCII range its own rule allows. Lengths are left alone so callers that raise StructuredDataId's 32 character limit keep working.

Checklist

  • Based on 2.x
  • ./mvnw verify succeeds (ran the build and Rfc5424LayoutTest for log4j-api, log4j-core and log4j-core-test locally)
  • Entry added under src/changelog/.2.x.x
  • Tests are provided

Parameter names and values were already sanitized, but MSGID and SD-ID went to the syslog record unmodified. A newline in a StructuredDataMessage type ends the record so the rest is read as a separate message, and a ']' in the id closes the structured data element early.
@jmestwa-coder
jmestwa-coder force-pushed the rfc5424-sd-id-sanitize branch from 0f16517 to a8180a7 Compare August 3, 2026 13:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

1 participant