[PR #1583] [CLOSED] fix(server): reject incomplete chunked request trailers #3545

Closed
opened 2026-11-07 14:42:14 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/1583
Author: @hulkbig
Created: 10/8/2026
Status: ❌ Closed

Base: main ← Head: fix/reject-incomplete-http-bodies-20261008


📝 Commits (2)

  • 2602760 Reject incomplete HTTP request body framing
  • e93ef94 Limit body framing fix to incomplete chunked trailers

📊 Changes

2 files changed (+51 additions, -5 deletions)

View changed files

📝 serve/server.py (+7 -4)
📝 serve/test_chunked_body.py (+44 -1)

📄 Description

Summary

Reject incomplete chunked request framing before applying the decoded body. _read_chunked currently accepts EOF or whitespace as a terminal blank line and returns successfully when its trailer-read limit is exhausted. An otherwise valid JSON body can therefore change /settings despite incomplete framing.

What changed

  • Require the actual terminal \r\n, complete CRLF-terminated trailer lines, and a terminator within the existing 64-read cap.
  • Add raw-socket regressions for missing, partial and malformed terminators, overlong trailers, and cap exhaustion; assert HTTP 400 and unchanged settings.
  • Preserve valid chunk extensions and trailers, including 63 trailer lines plus the final blank line.

Reproduction: send a chunked /settings POST containing {"defaults":{"temperature":0.5}}, end after 0\r\n without the final blank line, and half-close the sending side. The baseline applies the settings with HTTP 200; this change returns 400 without applying them.

Validation

  • 9 new failing cases/subcases reproduced on the baseline; 41 focused tests pass with the fix.
  • Independent review reran all 12 serve.test_chunked_body tests successfully.
  • Full tracked suite: 597 tests on this branch versus 593 on the base; both have the same telemetry environment error (disk_io_counters() returns None) and 11 skips. The full suite is not green in this environment.
  • py_compile and git diff --check pass.

Scope

This complements #1126 by fixing chunked trailer parsing. The Content-Length _body path is unchanged to avoid duplicating its ongoing validation work.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/1583 **Author:** [@hulkbig](https://github.com/hulkbig) **Created:** 10/8/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/reject-incomplete-http-bodies-20261008` --- ### 📝 Commits (2) - [`2602760`](https://github.com/Niko1221/Strata/commit/26027609d2fb56a1759fe95debcf5c718808a79c) Reject incomplete HTTP request body framing - [`e93ef94`](https://github.com/Niko1221/Strata/commit/e93ef945c99c22553ab9abbc9be5b2395d5985c4) Limit body framing fix to incomplete chunked trailers ### 📊 Changes **2 files changed** (+51 additions, -5 deletions) <details> <summary>View changed files</summary> 📝 `serve/server.py` (+7 -4) 📝 `serve/test_chunked_body.py` (+44 -1) </details> ### 📄 Description ## Summary Reject incomplete chunked request framing before applying the decoded body. `_read_chunked` currently accepts EOF or whitespace as a terminal blank line and returns successfully when its trailer-read limit is exhausted. An otherwise valid JSON body can therefore change `/settings` despite incomplete framing. ## What changed - Require the actual terminal `\r\n`, complete CRLF-terminated trailer lines, and a terminator within the existing 64-read cap. - Add raw-socket regressions for missing, partial and malformed terminators, overlong trailers, and cap exhaustion; assert HTTP 400 and unchanged settings. - Preserve valid chunk extensions and trailers, including 63 trailer lines plus the final blank line. Reproduction: send a chunked `/settings` POST containing `{"defaults":{"temperature":0.5}}`, end after `0\r\n` without the final blank line, and half-close the sending side. The baseline applies the settings with HTTP 200; this change returns 400 without applying them. ## Validation - 9 new failing cases/subcases reproduced on the baseline; 41 focused tests pass with the fix. - Independent review reran all 12 `serve.test_chunked_body` tests successfully. - Full tracked suite: 597 tests on this branch versus 593 on the base; both have the same telemetry environment error (`disk_io_counters()` returns `None`) and 11 skips. The full suite is not green in this environment. - `py_compile` and `git diff --check` pass. ## Scope This complements #1126 by fixing chunked trailer parsing. The Content-Length `_body` path is unchanged to avoid duplicating its ongoing validation work. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 14:42:14 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#3545
No description provided.