Commit 123202b
authored
fix(builtins): prevent JSON injection in HTTP build_json_body (#1007)
## 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 #10001 parent 04d8aa1 commit 123202b
File tree
2 files changed
+49
-6
lines changed- crates/bashkit/src/builtins
- specs
2 files changed
+49
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
203 | 203 | | |
204 | 204 | | |
205 | 205 | | |
206 | | - | |
| 206 | + | |
| 207 | + | |
207 | 208 | | |
208 | | - | |
| 209 | + | |
209 | 210 | | |
210 | 211 | | |
211 | 212 | | |
212 | | - | |
| 213 | + | |
213 | 214 | | |
214 | 215 | | |
215 | | - | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
216 | 220 | | |
217 | 221 | | |
218 | 222 | | |
219 | 223 | | |
220 | | - | |
| 224 | + | |
221 | 225 | | |
222 | 226 | | |
223 | | - | |
| 227 | + | |
224 | 228 | | |
225 | 229 | | |
226 | 230 | | |
| |||
587 | 591 | | |
588 | 592 | | |
589 | 593 | | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
590 | 632 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
605 | 605 | | |
606 | 606 | | |
607 | 607 | | |
| 608 | + | |
608 | 609 | | |
609 | 610 | | |
610 | 611 | | |
| |||
0 commit comments