Skip to content

IDS-10384: Encode CRLF in log output to prevent log injection (S5145)#279

Open
jl-0 wants to merge 1 commit into
developfrom
IDS-10384
Open

IDS-10384: Encode CRLF in log output to prevent log injection (S5145)#279
jl-0 wants to merge 1 commit into
developfrom
IDS-10384

Conversation

@jl-0

@jl-0 jl-0 commented Jun 3, 2026

Copy link
Copy Markdown
Collaborator

Summary

SonarQube identified 17 Log Injection findings (javasecurity:S5145, MINOR) across the codebase. Every one shares a single root cause: the Log4j2 PatternLayout used the raw %m message converter, which does not encode CR/LF characters. An authenticated user could therefore inject CRLF sequences into a user-controlled value (e.g. uuid, procDefKey, beanName, workerId, urlString, processVariables) and forge log lines.

Instead of sanitizing each of the ~17 call sites individually (brittle, leaves gaps, and rots as new log statements are added), this applies the Log4j2-native remediation centrally: wrap the message converter in %encode{%m}{CRLF} on every PatternLayout.

Why this approach

  • Central & complete — fixes every current and future log statement in one place, including sites SonarQube did not flag.
  • Native & safe%encode{...}{CRLF} encodes CR/LF only within the message body; auto-appended stack traces sit outside the wrapper and stay readable/multi-line.
  • Low risk — config-only; no Java changes, no recompile. monitorInterval = 30 reloads the Tomcat config live.
  • Supported%encode{}{CRLF} is the documented OWASP/SonarQube fix for S5145; fully supported in the bundled Log4j 2.25.x.

Changes

File Appenders updated
install/tomcat_lib/log4j2-tomcat.properties rolling, artemis, CONSOLE
cws-installer/src/main/resources/log4j2.properties console

Each ... - %m%n becomes ... - %encode{%m}{CRLF}%n.

SonarQube findings cleared (IDS-10384)

All 17 javasecurity:S5145 findings, including:
SchedulerDbService.java:500, SecurityService.java:124, SpringApplicationContext.java:74,78, WebUtils.java:83,180, RestService.java:523,542,854,1126,1568,1592,1605,1636, InitiatorsService.java:416, Scheduler.java:130,140.

Testing

  • Smoke-test log output after deploy: confirm normal messages render, multi-line stack traces remain intact, and a value containing \r\n is encoded on a single line.
  • Re-run SonarQube scan to confirm the 17 S5145 findings clear.

Out of scope

The related SSRF finding (javasecurity:S7044, IDS-10385) is not addressed here — it is being dispositioned as an accepted risk (see ticket).

🤖 Generated with Claude Code

SonarQube flagged 17 Log Injection findings (javasecurity:S5145) where
user-controlled values (e.g. uuid, procDefKey, beanName, workerId,
urlString) are concatenated into log messages. All 17 share a single
root cause: the Log4j2 PatternLayout used the raw %m message converter,
which does not encode carriage-return / line-feed characters, allowing
an authenticated user to forge log lines via CRLF injection.

Rather than sanitizing each of the ~17 call sites individually, this
applies the Log4j2-native remediation centrally: wrap the message
converter in %encode{%m}{CRLF} on every PatternLayout. This encodes CR
and LF within the logged message only (auto-appended stack traces stay
outside the wrapper and remain readable), and covers all current and
future log statements.

Changed appenders:
- install/tomcat_lib/log4j2-tomcat.properties: rolling, artemis, CONSOLE
- cws-installer/src/main/resources/log4j2.properties: console

Clears SonarQube findings under IDS-10384. Config-only change; no Java
changes and no recompile required (monitorInterval reloads it live).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@sonarqubecloud

sonarqubecloud Bot commented Jun 3, 2026

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant