Rfc5424Layout: Fix sanitization of SD parameter names#4073
Merged
Conversation
This change corrects the sanitization of `PARAM-NAME` in RFC 5424 structured data produced by `Rfc5424Layout`. Previously, parameter names were sanitized using the same escaping mechanism as parameter values. However, RFC 5424 does not define an escape mechanism for `PARAM-NAME`; instead, names must follow the `SD-NAME` syntax (`1*32PRINTUSASCII` with additional character restrictions). This change enforces these constraints when rendering structured data parameters: * Invalid characters are replaced with `?`. * Parameter names are truncated to a maximum of **32 characters**. * If sanitization results in an empty name, `?` is used instead. This ensures that generated structured data complies with the RFC 5424 grammar for `PARAM-NAME`. Co-authored-by: Volkan Yazıcı <volkan@yazi.ci>
Contributor
There was a problem hiding this comment.
Pull request overview
Updates Rfc5424Layout to sanitize RFC 5424 structured data parameter names (PARAM-NAME) according to the RFC grammar instead of applying value escaping rules, and adds regression tests plus a changelog entry.
Changes:
- Enforce RFC 5424
PARAM-NAMEconstraints by replacing invalid characters with?and truncating to 32 chars. - Keep value escaping for
PARAM-VALUEwhile using dedicated sanitization for parameter names. - Add parameterized tests for MDC key sanitization and a changelog entry for the fix.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/changelog/.2.x.x/4073_rfc5424-sd-param.xml |
Adds changelog entry documenting the RFC 5424 parameter-name sanitization fix. |
log4j-core/src/main/java/org/apache/logging/log4j/core/layout/Rfc5424Layout.java |
Implements dedicated PARAM-NAME sanitization (replace invalid chars, truncate to 32). |
log4j-core-test/src/test/java/org/apache/logging/log4j/core/layout/Rfc5424LayoutTest.java |
Adds parameterized regression test coverage for parameter-name sanitization. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
log4j-core-test/src/test/java/org/apache/logging/log4j/core/layout/Rfc5424LayoutTest.java
Show resolved
Hide resolved
log4j-core/src/main/java/org/apache/logging/log4j/core/layout/Rfc5424Layout.java
Outdated
Show resolved
Hide resolved
FreeAndNil
approved these changes
Mar 24, 2026
log4j-core/src/main/java/org/apache/logging/log4j/core/layout/Rfc5424Layout.java
Show resolved
Hide resolved
log4j-core/src/main/java/org/apache/logging/log4j/core/layout/Rfc5424Layout.java
Outdated
Show resolved
Hide resolved
Co-authored-by: Jan Friedrich <freeandnil@apache.org>
vy
approved these changes
Mar 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This change corrects the sanitization of
PARAM-NAMEin RFC 5424 structured data produced byRfc5424Layout.The issue was reported by @N0tre3l on March 8th, 2026.
Previously, parameter names were sanitized using the same escaping mechanism as parameter values. However, RFC 5424 does not define an escape mechanism for
PARAM-NAME; instead, names must follow theSD-NAMEsyntax (1*32PRINTUSASCIIwith additional character restrictions).This change enforces these constraints when rendering structured data parameters:
?.?is used instead.This ensures that generated structured data complies with the RFC 5424 grammar for
PARAM-NAME.