fix: sanitize user-controlled tokens to prevent log forging (CWE-117)#361
Open
muhamedfazalps wants to merge 1 commit into
Open
fix: sanitize user-controlled tokens to prevent log forging (CWE-117)#361muhamedfazalps wants to merge 1 commit into
muhamedfazalps wants to merge 1 commit into
Conversation
Apply escapeLogField() to all user-controlled HTTP tokens: - :url, :method, :user-agent, :referrer, :req, :remote-addr - :http-version Add sanitizeLogLine() as defense-in-depth to strip \r, \n, \x00 from final output before writing to stream. Fixes CVE-2026-5078
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.
Problem
Fixes CVE-2026-5078
User-controlled HTTP tokens (URL, User-Agent, Referrer, Request Headers, Remote Address) were not sanitized before being written to log output. This allows CRLF injection (
\r``\n) to forge log entries.Example Attack
This would create two log lines, making the second line appear as a legitimate request.
Solution
escapeLogField()to all user-controlled tokens (not just:remote-addr)sanitizeLogLine()as defense-in-depth to strip\r,\n,\x00from final outputTokens now sanitized:
:url- wrapsreq.originalUrl || req.url:method- wrapsreq.method:user-agent- wrapsreq.headers['user-agent']:referrer- wrapsreq.headers.referer:req- wrapsreq.headers[field.toLowerCase()]:remote-addr- wrapsgetip(req):http-version- wraps version stringTesting
Added tests for CRLF injection prevention in
:url,:user-agent,:req, and:remote-addrtokens.If this was helpful, consider supporting: https://buymeacoffee.com/muhamedfazalps