fix: sanitize user-supplied command before logging to prevent log injection#1671
Open
rajkumar-prog wants to merge 2 commits into
Open
fix: sanitize user-supplied command before logging to prevent log injection#1671rajkumar-prog wants to merge 2 commits into
rajkumar-prog wants to merge 2 commits into
Conversation
…ection Fixes openai#1542 Newlines and carriage returns in user-controlled `command` input were written to logs verbatim, allowing an attacker to inject fake log entries. Replace \n and \r with their escaped equivalents before logging, and also sanitize the ValueError message arg (which callers pass to logger.error). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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 #1542
In
_execute_command(), thecommandfield from the request body is written directly to logs without sanitization:Because
commandis user-controlled, an attacker can embed newlines (\n,\r) to inject fake log entries — e.g.:The same unsanitized string is also passed as
ValueError.args[0], which callers log vialogger.error(e.args[0]).Fix
Strip newlines and carriage returns from
commandbefore any logging by creating asafe_commandlocal variable:The original
command(unsanitized) is still forwarded to the API error response unchanged, so callers retain full fidelity — only the log output is sanitized.Change
evals/elsuite/multistep_web_tasks/docker/flask-playwright/app.py— 2 logging sites updated (+2 lines, -1 line net)