Skip to content

Security: Unsafe JSON Parsing via String Replacement in Echo Server - #3561

Closed
tomaioo wants to merge 1 commit into
webrecorder:mainfrom
tomaioo:fix/security/unsafe-json-parsing-via-string-replaceme
Closed

Security: Unsafe JSON Parsing via String Replacement in Echo Server#3561
tomaioo wants to merge 1 commit into
webrecorder:mainfrom
tomaioo:fix/security/unsafe-json-parsing-via-string-replaceme

Conversation

@tomaioo

@tomaioo tomaioo commented Aug 6, 2026

Copy link
Copy Markdown

Summary

Security: Unsafe JSON Parsing via String Replacement in Echo Server

Problem

Severity: Medium | File: backend/test_nightly/echo_server.py:L39

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.

Solution

Remove the .replace("'", '"') logic and rely on standard json.loads() which strictly expects double quotes. If the client sending the data cannot be changed to produce valid JSON, use ast.literal_eval() to safely parse Python dictionary literals instead of performing fragile string replacements.

Changes

  • backend/test_nightly/echo_server.py (modified)

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>
@mistydemeo

Copy link
Copy Markdown
Contributor

This is part of the test infrastructure, not the app.

@mistydemeo mistydemeo closed this Aug 6, 2026
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.

2 participants