Sanitize control bytes in formatted log messages#1031
Open
yosuke-wolfssl wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR mitigates log injection risks by escaping network-supplied SSH protocol strings at the logging sink (rather than mutating parsed protocol data), preventing CR/LF and control-byte injection into log records.
Changes:
- Adds
wolfSSH_LogSafeStr()plusWLOG_SAFE*helper macros to escape untrusted strings before logging. - Wraps multiple log sinks in
src/internal.cthat previously logged attacker-controlled%sdata directly. - Adds a unit test in
tests/api.ccovering escaping behavior, truncation, and edge cases.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
wolfssh/log.h |
Declares the new escaping API and introduces WLOG_SAFE, WLOG_SAFE_U, and WLOG_SAFE2 macros. |
src/log.c |
Implements wolfSSH_LogSafeStr() used to sanitize untrusted strings for log output. |
src/internal.c |
Replaces vulnerable WLOG(... "%s", ...) call sites with WLOG_SAFE* wrappers for network-controlled fields. |
tests/api.c |
Adds a unit test validating escaping rules and safety/truncation guarantees. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
cbd743e to
2aa5c85
Compare
2aa5c85 to
2ef6f8b
Compare
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #1031
Scan targets checked: wolfssh-bugs, wolfssh-src
No new issues found in the changed files. ✅
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Sanitize control bytes in formatted log messages
Summary
Network-supplied SSH protocol strings were logged verbatim through
WLOG("%s", ...).A peer could embed
CR/LFor terminal control bytes to forge or corrupt log records (log injection). This scrubs control bytes once, centrally, inwolfSSH_Log, closing the whole class across every logging sink.Problem
Parser routines (
GetString,GetStringRef,GetStringAlloc) copy protocol fields verbatim.Many
wolfSSH_Log/WLOGsinks acrosssrc/internal.c,src/wolfsftp.c,src/wolfscp.c, andapps/wolfsshd/then logged those fields with%sand no filtering.DefaultLoggingCbwrites the formatted line withfprintfand no escaping, so an embedded\nsplices forged log entries that are indistinguishable from genuine ones.The service-name and
SSH_MSG_DEBUGsinks are reachable pre-authentication.Fix
Scrub the formatted message in
wolfSSH_Log, afterWVSNPRINTFand before the logging callback runs: replace any byte< 0x20(except tab) and0x7f(DEL) with?.Why this layer:
WLOGexpands towolfSSH_Log, and directwolfSSH_Logcallers(including wolfsshd) build their line here too, so one site covers all current
and future sinks across all files and custom logging callbacks.
byte-exact (so comparisons and consumed values such as env values, exec
command, and filenames are unaffected). This is why the fix belongs here and
not in the parsers.
filenames are not mangled.
Findings closed
Closes the log-injection family in one change: 4234, 4347, 4348,
4350-4353, 4662, 4721, 4797, 4944, 5113, 5689, 5854.
Tests
test_wolfSSH_Log_sanitizeinstalls a capturing logging callback andasserts that
CR/LF/ESC/DELin a%sargument are scrubbed, tab ispreserved, and clean strings pass through unchanged.
confirming it detects regressions.