Skip to content

Harden logging: neutralize log injection + stop logging sensitive tokens (#464, #465) - #480

Merged
ExtraToast merged 4 commits into
mainfrom
fix/log-security-hardening
Aug 9, 2026
Merged

Harden logging: neutralize log injection + stop logging sensitive tokens (#464, #465)#480
ExtraToast merged 4 commits into
mainfrom
fix/log-security-hardening

Conversation

@jorisjonkers-dev-agents

Copy link
Copy Markdown
Contributor

Summary

Changes

New helper — shared/util/LogSanitizer.kt

String?.forLog() replaces [\r\n] with underscores and handles nulls. Applied consistently at every flagged site so the pattern is greppable.

EmailTrackingController (lines 53, 55, 57)

Drops token from all three log calls. The success path logs outbox.id only; the not-found and error paths omit any token reference. This closes both the java/sensitive-log alerts (#465) and the corresponding java/log-injection hits for this file (#464).

BrevoListAdapter (lines 51, 57, 60)

User-supplied list name wrapped in .forLog() at all three createList log calls.

MockContactAdapter (line 84)

Same name.forLog() fix in the mock adapter's createList log.

ForwardAuthController (line 66)

X-Forwarded-Host header value sanitized before the unknown-host warn log.

ExceptionLoggingResolver (line 41)

request.requestURI and ex.message both sanitized in the catch-all error log.

FileService (line 92)

multipart.originalFilename sanitized before the store info log.

Test plan

  • CodeQL run on this branch clears all 10 java/log-injection alerts and all 3 java/sensitive-log alerts.
  • Existing API unit and integration tests pass in CI (no behaviour change — only log arguments are touched).
  • No build warnings introduced.

Closes #464
Closes #465

@jorisjonkers-dev-agents jorisjonkers-dev-agents Bot added the bug Something isn't working label Jul 17, 2026

@ExtraToast ExtraToast left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review comments made by CodeQL, dismiss and address appropriately, then re-requeested review

@jorisjonkers-dev-agents
jorisjonkers-dev-agents Bot force-pushed the fix/log-security-hardening branch from ae2bf75 to e9470cf Compare July 18, 2026 06:30
@jorisjonkers-dev-agents

Copy link
Copy Markdown
Contributor Author

Addressed the additional CodeQL java/log-injection findings from the review.

Sanitized (wrapped user-provided value with .forLog()):

  • MockContactAdapter.kt — created-contact log line: data.emaildata.email.forLog()
  • MockContactAdapter.kt — deleted-contact log line: removed.emailremoved.email.forLog()

These two contact-email interpolations were the remaining unsanitized user-influenced String values within the files this PR touches; the previously-flagged sites (FileService filename, BrevoListAdapter list name x3, ForwardAuthController forwarded host) were already sanitized in the initial pass and remain so. No log levels or messages were otherwise changed. Rebased on latest main.

Commit: e9470cf

@ExtraToast ExtraToast left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

There's still a lot of codeql notifications on this, fix them.

@jorisjonkers-dev-agents
jorisjonkers-dev-agents Bot force-pushed the fix/log-security-hardening branch 2 times, most recently from 1111b11 to 0785b45 Compare August 8, 2026 09:41
#464, #465)

Log injection (java/log-injection, #464): CR/LF are stripped from every
user-influenced value before it is logged (FileService filename,
BrevoListAdapter list name, MockContactAdapter email/name,
ForwardAuthController forwarded host, ExceptionLoggingResolver URI/message),
via String.replace('\r','_').replace('\n','_') at the log call site.

The sanitization is inline (a local val per scope, reused across a
function's log calls) rather than a shared helper on purpose: CodeQL's
query only credits replace with String/Char arguments and only when the
barrier is in the same callable as the sink — it does not follow the
sanitizer through a helper function, and does not recognize the Regex
overload of replace. A LogSanitizer.forLog() helper (tried with both
regex and char/replaceAll bodies) left every site flagged; inlining the
recognized form clears them.

Sensitive tokens (java/sensitive-log, #465): EmailTrackingController no
longer logs the raw email tracking token; the success path logs only
outbox.id, the not-found/error paths log no token.

Closes #464
Closes #465

Co-Authored-By: Joris Jonkers <info@jorisjonkers.dev>
@jorisjonkers-dev-agents
jorisjonkers-dev-agents Bot force-pushed the fix/log-security-hardening branch from 0785b45 to 4b69403 Compare August 8, 2026 09:55
ExtraToast and others added 3 commits August 8, 2026 20:19
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@ExtraToast
ExtraToast merged commit e46049f into main Aug 9, 2026
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

2 participants