Skip to content

fix(security): sanitize CR/LF from user-controlled values before logging - #63

Merged
WomB0ComB0 merged 3 commits into
mainfrom
fix/log-forging-simservice
Apr 26, 2026
Merged

WomB0ComB0 merged 3 commits into
mainfrom
fix/log-forging-simservice

Conversation

@WomB0ComB0

Copy link
Copy Markdown
Member

Summary

Resolves CodeQL cs/log-forging alerts #10, #11, #17 in Services/SimulationService.cs.

Alert Site Tainted input
#10 line 149 — LogWarning("…drone {DroneId} not found.", droneId) droneId
#11 line 153 — LogDebug("Command {Command} sent to drone {DroneId}.", command, droneId) droneId
#17 line 182 — LogInformation("Terrain preset switched to '{Key}'.", key) key

All three values originate from HTTP requests via SimController and could carry CR/LF that forge fake log entries (CWE-117).

Fix

Adds a small private static string LogSafe(string?) helper that strips \r/\n (recognised by CodeQL as a valid cs/log-forging sanitiser), and routes the three call sites through it. command (a FlightCommand enum) is left alone — its renderer returns the type-system enum name, not user input.

Test plan

🤖 Generated with Claude Code

CodeQL `cs/log-forging` (CWE-117) flagged three sites in
SimulationService.cs where user-supplied strings (`droneId`, preset
`key`) flowed directly into `ILogger` calls:

  * Services/SimulationService.cs:149  LogWarning(droneId)
  * Services/SimulationService.cs:153  LogDebug(droneId)
  * Services/SimulationService.cs:182  LogInformation(key)

An attacker who can supply CR/LF in those values can inject fake log
entries (e.g. forge a "drone X armed" line). Adds a small private
static `LogSafe` helper that strips `\r`/`\n` and routes the three
call sites through it. Chained `String.Replace` is recognised by the
CodeQL rule as a valid sanitiser, so alerts #10/#11/#17 should
auto-close on the next scan.

`command` (FlightCommand enum) is left as-is; the renderer only
returns the type-system enum name and is not user-controlled.

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

coderabbitai Bot commented Apr 26, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Rate limit exceeded

@WomB0ComB0 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 37 minutes and 17 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 37 minutes and 17 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 75210619-05a1-4d53-9d04-c5a595ab9f85

📥 Commits

Reviewing files that changed from the base of the PR and between 1538299 and 90c6cc9.

📒 Files selected for processing (1)
  • src/ResQ.Viz.Web/Services/SimulationService.cs
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/log-forging-simservice

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request introduces a LogSafe utility to sanitize user-provided strings before logging, mitigating log forging vulnerabilities (CWE-117). The utility is applied to drone identifiers and terrain keys. Feedback suggests extending this sanitization to the AddDrone method, returning actual null values instead of the string "" to better support structured logging, and refining the replacement logic for improved robustness.

Comment thread src/ResQ.Viz.Web/Services/SimulationService.cs Outdated
WomB0ComB0 and others added 2 commits April 26, 2026 13:54
…ve null

Applies the gemini-code-assist review on PR #63:

- AddDrone (line 135) was a missed sink; the user-controlled `id` and
  `vendor` flow into LogInformation just like the three sites CodeQL
  flagged. Wrap both with LogSafe so the same protection applies.
- LogSafe now returns string? and preserves null instead of returning
  the magic literal "<null>". Structured loggers (Serilog, default
  JSON formatter, etc.) handle null natively; collapsing nulls to a
  string drops information from structured output.

The CR/LF chained Replace is kept (CodeQL recognises it as a valid
cs/log-forging sanitiser); ReplaceLineEndings would be more robust
against U+2028/U+2029 etc. but trades sanitiser recognition for that.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@WomB0ComB0
WomB0ComB0 merged commit 62fce5b into main Apr 26, 2026
37 checks passed
@WomB0ComB0
WomB0ComB0 deleted the fix/log-forging-simservice branch May 1, 2026 05:39
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