Commit a0035e7
Ankit Prateek
Cap HTTP response body size to bound adversarial-target memory use
The scanner's HTTP egress paths buffered response bodies into memory with
no size ceiling on three independent code paths:
* common/.../OkHttpHttpClient.java :: parseResponse — used by every
detector going through send / sendAsync. Calls
okResponse.body().bytes(), which only enforces a 2 GB cap on bodies
advertising a Content-Length and that ceiling is bypassed entirely
by chunked encoding with no Content-Length header.
* common/.../OkHttpHttpClient.java :: sendAsIs — used by the
crafted-URL probes that fire against hostile targets. Calls
ByteString.readFrom on the raw HttpURLConnection input stream with
no ceiling at all.
* plugin_server/py/.../requests_http_client.py :: send +
_parse_response — uses session.send() with the default
stream=False, which buffers the entire body into the Response
object before returning, then reads res.content unconditionally.
Because Tsunami probes adversarial endpoints by definition, an
attacker-controlled target can detect the TsunamiSecurityScanner
User-Agent on inbound requests and serve an unbounded chunked response.
Each chunk arrives within the read-timeout window so the read timeout
never fires, and the body buffer grows until the JVM heap or Python
process is exhausted (CWE-770 / CWE-400). The result: a compromised
asset can deterministically crash the scanner that is probing it,
producing the false-negative "scanned, no findings" outcome an attacker
wants from a detection tool.
Fix: introduce a configurable max-response-body cap (default 100 MB)
enforced at every body-ingestion point. Reads are drained chunk by
chunk into a bounded buffer; once the cap is exceeded, the underlying
connection is closed and the call fails with IOException / IOError so
the affected probe errors out cleanly while the surrounding scan
continues.
Wiring:
* Java: new HttpClientModule.@MaxResponseBodyBytes provider resolves
--http-client-max-response-body-mb (CLI) → maxResponseBodyMb
(config) → 100 MB default, mirroring the existing timeout flag
pattern. New OkHttpHttpClient constructor + builder setter expose
the cap; the legacy 6-arg constructor is preserved with the
default value to keep external callers source-compatible.
* Python: new --max_response_body_mb absl flag plumbed through
RequestsHttpClientBuilder.set_max_response_body_bytes into
RequestsHttpClient. session.send() now passes stream=True so the
body never lands in the Response object before we get a chance to
cap it.
Tests:
* OkHttpHttpClientTest: send / sendAsIs throw IOException when the
body exceeds the cap; bodies within the cap pass through unchanged.
* requests_http_client_test: send raises IOError on advertised
Content-Length over cap, on actual streamed bytes over cap, and
passes through small bodies unchanged.
Disclosure note: the unbounded reads were originally surfaced by an
external security review. The patch is local to the HTTP-client layer;
no detector code changes and no detector behavior changes for any
response under the cap. Couldn't run gradle/pytest locally (no wrapper
checked in, no project-wide pytest harness configured); relying on CI.1 parent f29c42a commit a0035e7
8 files changed
Lines changed: 333 additions & 7 deletions
File tree
- common/src
- main/java/com/google/tsunami/common/net/http
- test/java/com/google/tsunami/common/net/http
- plugin_server/py
- common/net/http
Lines changed: 14 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
68 | 76 | | |
69 | 77 | | |
70 | 78 | | |
71 | 79 | | |
72 | 80 | | |
73 | 81 | | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
74 | 88 | | |
75 | 89 | | |
76 | 90 | | |
| |||
Lines changed: 7 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
53 | 60 | | |
Lines changed: 31 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
141 | 141 | | |
142 | 142 | | |
143 | 143 | | |
144 | | - | |
| 144 | + | |
| 145 | + | |
145 | 146 | | |
146 | | - | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
147 | 154 | | |
148 | 155 | | |
149 | 156 | | |
| |||
271 | 278 | | |
272 | 279 | | |
273 | 280 | | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
274 | 298 | | |
275 | 299 | | |
276 | 300 | | |
| |||
326 | 350 | | |
327 | 351 | | |
328 | 352 | | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
329 | 358 | | |
330 | 359 | | |
331 | 360 | | |
| |||
Lines changed: 97 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| 33 | + | |
33 | 34 | | |
| 35 | + | |
34 | 36 | | |
35 | 37 | | |
36 | 38 | | |
| |||
46 | 48 | | |
47 | 49 | | |
48 | 50 | | |
| 51 | + | |
| 52 | + | |
49 | 53 | | |
50 | 54 | | |
51 | 55 | | |
| |||
55 | 59 | | |
56 | 60 | | |
57 | 61 | | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
58 | 68 | | |
59 | 69 | | |
60 | 70 | | |
61 | 71 | | |
62 | 72 | | |
63 | 73 | | |
| 74 | + | |
64 | 75 | | |
65 | 76 | | |
66 | 77 | | |
| |||
69 | 80 | | |
70 | 81 | | |
71 | 82 | | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
72 | 101 | | |
73 | 102 | | |
74 | 103 | | |
75 | 104 | | |
76 | 105 | | |
77 | 106 | | |
| 107 | + | |
78 | 108 | | |
79 | 109 | | |
80 | 110 | | |
| |||
134 | 164 | | |
135 | 165 | | |
136 | 166 | | |
137 | | - | |
| 167 | + | |
138 | 168 | | |
139 | 169 | | |
140 | 170 | | |
| |||
310 | 340 | | |
311 | 341 | | |
312 | 342 | | |
313 | | - | |
| 343 | + | |
314 | 344 | | |
315 | 345 | | |
316 | 346 | | |
| |||
322 | 352 | | |
323 | 353 | | |
324 | 354 | | |
325 | | - | |
| 355 | + | |
| 356 | + | |
326 | 357 | | |
327 | 358 | | |
328 | 359 | | |
329 | 360 | | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
330 | 414 | | |
331 | 415 | | |
332 | 416 | | |
| |||
357 | 441 | | |
358 | 442 | | |
359 | 443 | | |
| 444 | + | |
360 | 445 | | |
361 | 446 | | |
362 | 447 | | |
| |||
366 | 451 | | |
367 | 452 | | |
368 | 453 | | |
| 454 | + | |
369 | 455 | | |
370 | 456 | | |
371 | 457 | | |
| |||
392 | 478 | | |
393 | 479 | | |
394 | 480 | | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
395 | 487 | | |
396 | 488 | | |
397 | 489 | | |
| |||
400 | 492 | | |
401 | 493 | | |
402 | 494 | | |
403 | | - | |
| 495 | + | |
| 496 | + | |
404 | 497 | | |
405 | 498 | | |
406 | 499 | | |
Lines changed: 67 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
710 | 710 | | |
711 | 711 | | |
712 | 712 | | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
713 | 770 | | |
714 | 771 | | |
715 | 772 | | |
| |||
761 | 818 | | |
762 | 819 | | |
763 | 820 | | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
764 | 831 | | |
765 | 832 | | |
766 | 833 | | |
| |||
0 commit comments