ppkarwasz opened a new issue, #4464: URL: https://github.com/apache/logging-log4j2/issues/4464
`Rfc5424Layout` escapes `"`, `\` and `]` in structured data parameter values, as required by RFC 5424, section 6.3.3, but applies the `newLineEscape` replacement afterwards (`escapeNewlines(escapeParamValue(value), escapeNewLine)` in `appendMap`). The replacement is therefore emitted verbatim inside the PARAM-VALUE. With the documented `newLineEscape="\n"`, a value `A<CR><LF>B` from a `StructuredDataMessage` or from the MDC (`includeMDC="true"`) is written as `k="A\nB"`, with an unescaped backslash. Conforming receivers read this as a literal backslash followed by `n`, as RFC 5424 requires for invalid escape sequences, but the output does not conform to the sender requirements. A replacement containing `]` or `"` would also be emitted unescaped. The free-form MSG part is not affected, since it has no escaping rules. This issue originates from a private security report classified as a bug. Fix: apply the newline replacement first and the SD-PARAM-VALUE escaping second, i.e. `escapeParamValue(escapeNewlines(value, escapeNewLine))`, in both 2.x and `main`. With `newLineEscape="\n"` the value is then emitted as `A\\nB`, which conforming receivers decode to `A\nB`. Receivers that do not decode RFC 5424 escapes will see `\\n` instead of `\n` in structured data values; this should be mentioned in the changelog. Add a test with `newLineEscape="\n"` and CR/LF in both an MDC value and a `StructuredDataMessage` value, asserting that the emitted PARAM-VALUE contains only the escapes `\"`, `\\` and `\]`. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
