Skip to content

fix(builtins): prevent JSON injection in HTTP build_json_body#1007

Merged
chaliy merged 2 commits intomainfrom
fix/issue-1000-json-injection
Apr 2, 2026
Merged

fix(builtins): prevent JSON injection in HTTP build_json_body#1007
chaliy merged 2 commits intomainfrom
fix/issue-1000-json-injection

Conversation

@chaliy
Copy link
Copy Markdown
Contributor

@chaliy chaliy commented Apr 2, 2026

Summary

  • Replaced manual string formatting in build_json_body with serde_json for proper JSON escaping
  • Values containing ", \, newlines, or other special characters are now safely escaped
  • Added threat model entry TM-NET-018

What & Why

build_json_body constructed JSON via format!("\"{}\"", v) without escaping, allowing injection of arbitrary JSON fields (e.g., name='test","admin":true' would inject an admin field). Now uses serde_json::Value::String which handles all escaping correctly.

Tests Added

  • test_json_body_escapes_quotes — verifies injection attempt is neutralized
  • test_json_body_escapes_backslash_and_newline — verifies control chars are escaped
  • test_json_body_raw_field_unchanged — verifies raw fields still work

Closes #1000

chaliy added 2 commits April 2, 2026 09:20
…_json_body

Closes #1000 — build_json_body was constructing JSON via string formatting
without escaping special characters, allowing injection of arbitrary JSON
fields. Now uses serde_json::Value::String for proper escaping.
@chaliy chaliy merged commit 123202b into main Apr 2, 2026
27 checks passed
@chaliy chaliy deleted the fix/issue-1000-json-injection branch April 2, 2026 09:39
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.

JSON injection via unescaped values in HTTP build_json_body

1 participant