Security: Unsafe JSON Parsing via String Replacement in Echo Server - #3561
Closed
tomaioo wants to merge 1 commit into
Closed
Security: Unsafe JSON Parsing via String Replacement in Echo Server#3561tomaioo wants to merge 1 commit into
tomaioo wants to merge 1 commit into
Conversation
The echo server attempts to parse POST bodies using `json.loads(body.decode('utf-8').replace("'", '"'))`. Replacing single quotes with double quotes is a naive approach to handle single-quoted strings, but it will corrupt valid JSON payloads that contain apostrophes (e.g., `{"message": "it's a test"}` becomes `{"message": "it"s a test"}`). This can lead to JSONDecodeError exceptions or data corruption. If this server is used to validate webhook callbacks, this flaw could cause valid callbacks to fail or be misinterpreted.
Signed-off-by: tomaioo <203048277+tomaioo@users.noreply.github.com>
Contributor
|
This is part of the test infrastructure, not the app. |
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.
Summary
Security: Unsafe JSON Parsing via String Replacement in Echo Server
Problem
Severity:
Medium| File:backend/test_nightly/echo_server.py:L39The echo server attempts to parse POST bodies using
json.loads(body.decode('utf-8').replace("'", '"')). Replacing single quotes with double quotes is a naive approach to handle single-quoted strings, but it will corrupt valid JSON payloads that contain apostrophes (e.g.,{"message": "it's a test"}becomes{"message": "it"s a test"}). This can lead to JSONDecodeError exceptions or data corruption. If this server is used to validate webhook callbacks, this flaw could cause valid callbacks to fail or be misinterpreted.Solution
Remove the
.replace("'", '"')logic and rely on standardjson.loads()which strictly expects double quotes. If the client sending the data cannot be changed to produce valid JSON, useast.literal_eval()to safely parse Python dictionary literals instead of performing fragile string replacements.Changes
backend/test_nightly/echo_server.py(modified)