Commit 69aaae8
authored
[BUGFIX] Response Text Returns Junk (#31)
* fix: critical security vulnerabilities and improve proxy test coverage
This commit addresses multiple security issues discovered during edge case
analysis and improves test infrastructure for better reliability.
Security Fixes:
- Fix HTTP/1.1 body reallocation bug causing data loss (#1)
* Modified realloc_body_buffer() to use current_data_size parameter
* Fixes issue where response->body_len was 0 during receive
* Prevents data loss when buffer needs to grow during receive
- Add integer overflow protection in 8 critical locations (#7, #8)
* HTTP/2 data callback buffer doubling (http2_logic.c:140)
* HTTP/1.1 body buffer reallocation (http1.c:417, 549, 606)
* Gzip decompression buffer expansion (compression.c:55)
* Response header array growth (response.c:123)
* Request header array growth (request.c:112)
* Async request array growth (async_request_manager.c:171)
* All checks use SIZE_MAX/2 to prevent integer overflow
- Fix memory leak in DNS cache deep copy (#13)
* Added proper cleanup on allocation failures in addrinfo_deep_copy()
* Prevents memory leaks when malloc/strdup fails mid-operation
Async HTTP Proxy Improvements:
- Fix async HTTP proxy to use absolute URI for proxy requests
- Add Proxy-Authorization header support for authenticated HTTP proxies
- Properly distinguish between HTTP (uses absolute URI) and HTTPS (uses path)
Test Infrastructure:
- Add comprehensive edge case security tests (25 test cases)
* Integer overflow protection tests
* Memory leak prevention tests
* Thread safety tests
* Boundary condition tests
- Add buffer reallocation regression tests (11 test cases)
* Large response handling
* Gzip decompression
* Chunked transfer encoding
* Multiple buffer doubling scenarios
- Update proxy tests to use httpmorph-bin.bytetunnels.com
* Added fixtures for both HTTP and HTTPS testing
* HTTPS uses verify=False for self-signed certificates
* Improved test reliability by using dedicated test server
Results: All 371 tests pass with 14 expected skips
* chore: more test cases
* [FIX] Make dotenv import optional in test files for CI compatibility
Fix ModuleNotFoundError in CI environments where python-dotenv is not installed.
Changes:
- Wrap dotenv import in try/except block in test_buffer_reallocation.py
- Wrap dotenv import in try/except block in test_edge_cases_security.py
- Follow same pattern as conftest.py for optional dependency handling
Impact:
- Tests now work in CI without requiring python-dotenv installation
- Local development still benefits from .env file loading when dotenv is available
- Environment variables can be set directly in CI/CD pipelines
Fixes CI failures across all workflows with:
ModuleNotFoundError: No module named 'dotenv'
* [FIX] Pass TEST_HTTPBIN_HOST secret to CI test workflows
Add TEST_HTTPBIN_HOST environment variable to CI workflows to fix test failures.
Changes:
- Add TEST_HTTPBIN_HOST to workflow secrets in _test.yml
- Pass TEST_HTTPBIN_HOST to test environment in _test.yml
- Pass TEST_HTTPBIN_HOST from ci.yml to _test.yml workflow
Impact:
- Edge case security tests can now access httpmorph-bin test server in CI
- Buffer reallocation tests can run in CI environment
- Fixes collection errors: "TEST_HTTPBIN_HOST environment variable is not set"
Related:
- Works together with previous commit making dotenv import optional
- TEST_HTTPBIN_HOST must be configured as repository secret in GitHub
* Release v0.2.5
## Security Fixes
This release addresses 9 critical security vulnerabilities discovered during code analysis:
### 1. HTTP/1.1 Body Reallocation Bug
- **Severity**: HIGH - Data loss during response handling
- **Impact**: Response body data was being discarded when buffer needed to grow
- **Fix**: Corrected realloc_body_buffer() to track actual data size
- **File**: src/core/http1.c:31
### 2. Integer Overflow Protection (8 locations)
- **Severity**: CRITICAL - Heap overflow vulnerability
- **Impact**: Buffer doubling operations could overflow on large responses
- **Locations**: HTTP/2 data callback, HTTP/1.1 body buffer, gzip decompression,
response/request headers, async requests
- **Fix**: Added overflow checks using SIZE_MAX/2 before all buffer doubling
### 3. DNS Cache Memory Leak
- **Severity**: MEDIUM - Memory leak on allocation failure
- **Fix**: Proper cleanup on all error paths in addrinfo_deep_copy()
- **File**: src/core/network.c:78-123
## Improvements
### Async HTTP Proxy
- Use absolute URI for HTTP requests through proxy
- Add Proxy-Authorization header for authenticated proxies
- Proper HTTP vs HTTPS proxy distinction
- **File**: src/core/async_request.c:1012-1064
### CI/CD
- Enhanced test configuration with proper secret handling
- Improved workflow environment variable passing
## Changed Files
**Core Security Fixes**:
- src/core/http1.c - Body reallocation + overflow checks
- src/core/http2_logic.c - Integer overflow protection
- src/core/compression.c - Decompression overflow check
- src/core/response.c - Header array overflow check
- src/core/request.c - Header array overflow check
- src/core/async_request_manager.c - Request array overflow check
- src/core/async_request.c - HTTP proxy improvements
- src/core/network.c - DNS cache memory leak fix
**Infrastructure**:
- .github/workflows/_test.yml - Enhanced test configuration
- .github/workflows/ci.yml - Improved workflow secrets
- tests/* - Comprehensive security test coverage
## Impact
- **Security**: All 9 vulnerabilities patched
- **Performance**: No regression - O(1) overflow checks
- **Compatibility**: No breaking changes
## Upgrade Recommendation
1 parent 598d439 commit 69aaae8
File tree
16 files changed
+931
-135
lines changed- .github/workflows
- src
- bindings
- core
- tests
16 files changed
+931
-135
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
| 22 | + | |
21 | 23 | | |
22 | 24 | | |
23 | 25 | | |
| |||
234 | 236 | | |
235 | 237 | | |
236 | 238 | | |
| 239 | + | |
237 | 240 | | |
238 | 241 | | |
239 | 242 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| 31 | + | |
31 | 32 | | |
32 | 33 | | |
33 | 34 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
| 12 | + | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| |||
74 | 75 | | |
75 | 76 | | |
76 | 77 | | |
77 | | - | |
| 78 | + | |
78 | 79 | | |
79 | 80 | | |
80 | 81 | | |
81 | 82 | | |
82 | 83 | | |
| 84 | + | |
83 | 85 | | |
84 | 86 | | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
85 | 90 | | |
86 | 91 | | |
87 | 92 | | |
| |||
215 | 220 | | |
216 | 221 | | |
217 | 222 | | |
| 223 | + | |
218 | 224 | | |
219 | 225 | | |
220 | 226 | | |
| |||
312 | 318 | | |
313 | 319 | | |
314 | 320 | | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
315 | 326 | | |
316 | 327 | | |
317 | 328 | | |
318 | 329 | | |
319 | | - | |
| 330 | + | |
320 | 331 | | |
321 | 332 | | |
322 | 333 | | |
| |||
472 | 483 | | |
473 | 484 | | |
474 | 485 | | |
| 486 | + | |
475 | 487 | | |
476 | 488 | | |
477 | 489 | | |
| |||
621 | 633 | | |
622 | 634 | | |
623 | 635 | | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
624 | 641 | | |
625 | 642 | | |
626 | 643 | | |
627 | 644 | | |
628 | | - | |
| 645 | + | |
629 | 646 | | |
630 | 647 | | |
631 | 648 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| |||
1009 | 1010 | | |
1010 | 1011 | | |
1011 | 1012 | | |
1012 | | - | |
1013 | | - | |
1014 | | - | |
1015 | | - | |
1016 | | - | |
1017 | | - | |
1018 | | - | |
1019 | | - | |
| 1013 | + | |
| 1014 | + | |
| 1015 | + | |
| 1016 | + | |
| 1017 | + | |
| 1018 | + | |
| 1019 | + | |
| 1020 | + | |
| 1021 | + | |
| 1022 | + | |
| 1023 | + | |
| 1024 | + | |
| 1025 | + | |
| 1026 | + | |
| 1027 | + | |
| 1028 | + | |
| 1029 | + | |
| 1030 | + | |
1020 | 1031 | | |
1021 | 1032 | | |
1022 | | - | |
| 1033 | + | |
1023 | 1034 | | |
1024 | 1035 | | |
1025 | | - | |
| 1036 | + | |
1026 | 1037 | | |
1027 | 1038 | | |
1028 | 1039 | | |
| |||
1034 | 1045 | | |
1035 | 1046 | | |
1036 | 1047 | | |
| 1048 | + | |
| 1049 | + | |
| 1050 | + | |
| 1051 | + | |
| 1052 | + | |
| 1053 | + | |
| 1054 | + | |
| 1055 | + | |
| 1056 | + | |
| 1057 | + | |
| 1058 | + | |
| 1059 | + | |
| 1060 | + | |
| 1061 | + | |
| 1062 | + | |
| 1063 | + | |
| 1064 | + | |
| 1065 | + | |
| 1066 | + | |
1037 | 1067 | | |
1038 | 1068 | | |
1039 | 1069 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
168 | 168 | | |
169 | 169 | | |
170 | 170 | | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
171 | 177 | | |
172 | 178 | | |
173 | 179 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
55 | 68 | | |
56 | 69 | | |
57 | 70 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
73 | 73 | | |
74 | 74 | | |
75 | 75 | | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
129 | 80 | | |
130 | 81 | | |
131 | 82 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
26 | 30 | | |
27 | | - | |
| 31 | + | |
28 | 32 | | |
29 | 33 | | |
30 | 34 | | |
| |||
41 | 45 | | |
42 | 46 | | |
43 | 47 | | |
44 | | - | |
45 | | - | |
46 | | - | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
47 | 51 | | |
48 | 52 | | |
49 | 53 | | |
| |||
413 | 417 | | |
414 | 418 | | |
415 | 419 | | |
416 | | - | |
417 | | - | |
418 | | - | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
419 | 423 | | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
420 | 430 | | |
421 | 431 | | |
422 | 432 | | |
| |||
436 | 446 | | |
437 | 447 | | |
438 | 448 | | |
439 | | - | |
| 449 | + | |
440 | 450 | | |
441 | 451 | | |
442 | 452 | | |
| |||
536 | 546 | | |
537 | 547 | | |
538 | 548 | | |
539 | | - | |
540 | | - | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
541 | 558 | | |
542 | 559 | | |
543 | 560 | | |
| |||
586 | 603 | | |
587 | 604 | | |
588 | 605 | | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
589 | 611 | | |
590 | | - | |
| 612 | + | |
591 | 613 | | |
592 | 614 | | |
593 | 615 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
137 | 137 | | |
138 | 138 | | |
139 | 139 | | |
140 | | - | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
141 | 150 | | |
142 | 151 | | |
143 | 152 | | |
| |||
0 commit comments