Skip to content

Rfc5424Layout: Fix sanitization of SD parameter names#4073

Merged
ppkarwasz merged 6 commits into2.25.xfrom
fix/2.25.x/rfc5424-sd-param
Mar 24, 2026
Merged

Rfc5424Layout: Fix sanitization of SD parameter names#4073
ppkarwasz merged 6 commits into2.25.xfrom
fix/2.25.x/rfc5424-sd-param

Conversation

@ppkarwasz
Copy link
Copy Markdown
Contributor

@ppkarwasz ppkarwasz commented Mar 24, 2026

This change corrects the sanitization of PARAM-NAME in RFC 5424 structured data produced by Rfc5424Layout.

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 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.

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>
@ppkarwasz ppkarwasz requested review from Copilot and vy and removed request for Copilot March 24, 2026 19:09
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-NAME constraints by replacing invalid characters with ? and truncating to 32 chars.
  • Keep value escaping for PARAM-VALUE while 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.

Copy link
Copy Markdown

@FreeAndNil FreeAndNil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two minor hints.

@vy vy added bug Incorrect, unexpected, or unintended behavior of existing code layouts Affects one or more Layout plugins labels Mar 24, 2026
@vy vy added this to the 2.25.4 milestone Mar 24, 2026
@ppkarwasz ppkarwasz merged commit eb9a0fa into 2.25.x Mar 24, 2026
7 checks passed
@ppkarwasz ppkarwasz deleted the fix/2.25.x/rfc5424-sd-param branch March 24, 2026 22:53
@github-project-automation github-project-automation bot moved this from Approved to Merged in Log4j pull request tracker Mar 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Incorrect, unexpected, or unintended behavior of existing code layouts Affects one or more Layout plugins

Projects

Development

Successfully merging this pull request may close these issues.

4 participants