Repository navigation
Commit dd291b8
fix(storage, plugin-hono-server): every byte-reading upload door holds a body with no declared length to its own bound (#33323)
Clause-②: yes (widening)
Metadata-protocol: none
## 维护者速读
-
**改了什么**:每个按字节读取上传内容的入口(分片上传、本地直传、上传链接)现在对"未声明长度"的请求体也按自己的上限计数,超限即停读并拒绝;`IHttpRequest.rawBody`
新增可选参数 `{ maxBytes }`。
- **为什么改**:此前只有声明了长度的请求体会被这些入口的上限挡住,未声明长度的会先读完再判断;规则应当一致。
- **风险与回滚**:契约是加宽(参数可选,旧实现照样通过类型检查);`max_upload_mb` 未设置时行为不变。回滚即还原本 PR。
-
**先看**:`packages/plugins/plugin-hono-server/src/body-limit.ts`(有界读取)、`packages/services/service-storage/src/storage-routes.ts`(各入口传入上限、上传链接先判链接再读)、`packages/spec/src/contracts/http-server.ts`(契约文字)。
- **两分钟验证**:`pnpm --filter @objectstack/plugin-hono-server exec vitest
run src/body-limit.test.ts -t "own bound"` ,预期 8 个用例全部通过。
- **需要你做的**:无,席位落地。
## What changes
**The rule:** every byte-reading upload door holds a body with no
declared length to its own bound, exactly as it holds a declared one,
and refuses past the bound before the body is buffered further.
### The contract change (rule level) — for the contract-tier review
`IHttpRequest.rawBody` (`packages/spec/src/contracts/http-server.ts`)
widens from an accessor that takes no argument to one that takes an
optional `{ maxBytes?: number }`, still answering a promise of the
body's bytes:
- The reading door states its own bound as `maxBytes`. An implementation
MUST then hold the body to it whether or not a length is declared: a
declared `Content-Length` over it is refused unread; a body with no
declared length is refused once it passes it, and read no further;
exactly `maxBytes` is read whole.
- A refusal rejects with an error carrying `status` 413 and `code`
`PAYLOAD_TOO_LARGE`. The door answers it with its own refusal; one it
lets escape is answered `413 PAYLOAD_TOO_LARGE`.
- Without `maxBytes` the whole body is read, as before. Repeated calls
answer what the first read: the same bytes (judged against each call's
bound) or the first refusal.
- The `body` member's text now names the transport's `413` refusal and
its one way out: a door that then reads `rawBody` takes the read over
under its own bound, which it owes to `rawBody`.
Widening: an implementation that takes no argument still type-checks,
and every call that passes nothing behaves as before.
### What each consumer does with it
| Consumer | Role | What it does |
|:--|:--|:--|
| `@objectstack/plugin-hono-server` (`adapter.ts`, `body-limit.ts`) |
implementation | Holds `maxBytes` on every read path a byte door
reaches: the original body, and a body a JSON or form pre-read already
held. Past the bound the source is cancelled. An escaped refusal with no
answer written is answered `413 PAYLOAD_TOO_LARGE`. |
| `@objectstack/http-conformance` (`adapter.ts`, private, QA) |
reference implementation | Mirrors the rule: declared length over the
bound refused unread; undeclared body refused past it with the stream
paused; escaped refusal answered the same bytes as the standard
transport. |
| `@objectstack/service-storage` chunk `PUT` | caller | States what
`max_upload_mb` leaves this chunk (the limit minus the bytes the upload
already holds). |
| `@objectstack/service-storage` presigned local raw `PUT` | caller |
States `max_upload_mb`. |
| `@objectstack/service-storage` upload-link `PUT`, one file | caller |
States `max_upload_mb`; also judges the link (open, unexpired, the
caller's) **before** reading a byte of the body. A body declaring more
than the door takes is still refused first, as before. |
| `@objectstack/service-storage` upload-link several-file form, taken
over past the transport limit | caller | States its form limit. |
| Every caller, `max_upload_mb` unset | — | States no bound; reads the
whole body, as before (see Acceptance notes). |
Each storage door also still judges the bytes it read after the read, so
a host whose `rawBody` ignores `maxBytes` keeps the answers it had.
## Tests
All named by the rule, each with CONTROLS for the unchanged paths:
- `plugin-hono-server` `body-limit.test.ts` — *a byte door's own bound
holds a body whether or not it declares a length*: undeclared body past
the bound refused with the source cancelled and bytes pulled at most the
bound plus two chunks (`application/octet-stream`, `application/json`);
a form taken over after the transport refusal held the same way;
declared length over the bound refused with zero bytes pulled; escaped
refusal answered 413 naming the bound. CONTROLS: exactly the bound read
whole (declared and not); a body already read through `req.body` judged
against the bound once read.
- `http-conformance` `request-body.conformance.test.ts` — on both
adapters over a real socket: body past the bound refused 413 (declared
and not); escaped refusal answered 413; parity of the escaped answer's
bytes. CONTROLS: exactly the bound read whole.
- `service-storage` `storage-limits.test.ts` — local raw `PUT` and chunk
`PUT` state their bound and answer 413 with nothing stored and progress
unchanged. CONTROLS: exactly the bound stored; no `max_upload_mb` states
no bound.
- `service-storage` `record-file-access.integration.test.ts` — the
upload-link door: bound held for one file with the link left unspent;
the link judged before a byte is read (another user's link, a spent
link: the body is never read); the several-file form held to the form
limit. CONTROLS: a body within the bound lands; no `max_upload_mb`
states no bound.
**Ablation** (fix committed first, each mutation through
`scripts/ablation-replace.mjs`, restored to the HEAD blob with `git diff
HEAD` empty):
1. Storage doors state no bound to `rawBody`: 4 of the new storage cases
red; restored.
2. Upload-link door reads before judging the link: 1 case red (the
link-judged-first case); restored.
3. Transport ignores `maxBytes` on the original body: the new transport
describe red (the run did not complete); restored.
Not ablated: the reference adapter's in-read stop (its answer is the
same either way, since the post-read judgement also refuses; only the
transport case measures bytes read).
## Acceptance notes
- **Open product choice, not decided here:** with `max_upload_mb` unset
a byte door has no bound of its own, so it states none and reads the
whole body, as before. What a door's bound should be then is a
maintainer decision, reported to the seat as a fork.
- The upload-link form's take-over still holds the form's bytes, the
parsed form and one buffer per file at once; each is bounded by the form
limit. Unchanged here.
- A route outside this repository that reads `rawBody` and has a bound
should pass it (rule stated in the contract).
## Verification
Final head `36ce94c0` (after merging `origin/main` 47a3b95):
<details><summary>Touched packages: tests</summary>
- `@objectstack/plugin-hono-server` — Test Files 42 passed · Tests 555
passed
- `@objectstack/service-storage` — Test Files 84 passed · Tests 1640
passed, 1 skipped
- `@objectstack/hono` — Test Files 14 passed · Tests 258 passed
- `@objectstack/http-conformance` — Test Files 20 passed · Tests 286
passed
</details>
<details><summary>Typecheck and generated artifacts</summary>
- `typecheck` for `spec`, `plugin-hono-server`, `service-storage`,
`http-conformance`, `hono`, `rest`: exit 0, every `check:test-typecheck`
OK.
- `pnpm --filter @objectstack/spec check:generated`: all 14 generated
artifacts up to date.
</details>
<details><summary>Derived gate families (dispatch-gates --commands,
93)</summary>
On `36ce94c0`: 93 derived, 92 exit 0, 1 NOT MEASURED — `node
scripts/check-plugin-teardown-shape.mjs --self-test` exit 3
(PREREQUISITE NOT MET: its fixture commit is outside this shallow
clone). `dispatch-gates --ran` with exit codes recorded: 93 accounted
for, 0 UNRUN. Every other family CI runs is read from this PR's
check-runs, not re-run locally.
</details>
---
_Generated by [Claude
Code](https://claude.ai/code/session_017xRBcTHcckwGChckTwu6Lp)_
<!-- signed: security#1 · sunhaolin · session_017xRBcT1w3zpekijraHJE4f
-->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 89defde commit dd291b8
10 files changed
Lines changed: 928 additions & 95 deletions
File tree
- .changeset
- packages
- plugins/plugin-hono-server/src
- qa/http-conformance/src
- services/service-storage/src
- spec/src/contracts
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
| 44 | + | |
44 | 45 | | |
| 46 | + | |
| 47 | + | |
45 | 48 | | |
46 | 49 | | |
47 | 50 | | |
| |||
868 | 871 | | |
869 | 872 | | |
870 | 873 | | |
| 874 | + | |
| 875 | + | |
871 | 876 | | |
872 | 877 | | |
873 | 878 | | |
| |||
912 | 917 | | |
913 | 918 | | |
914 | 919 | | |
| 920 | + | |
| 921 | + | |
| 922 | + | |
| 923 | + | |
| 924 | + | |
| 925 | + | |
915 | 926 | | |
916 | 927 | | |
917 | 928 | | |
918 | 929 | | |
919 | 930 | | |
920 | 931 | | |
921 | | - | |
| 932 | + | |
| 933 | + | |
922 | 934 | | |
923 | | - | |
| 935 | + | |
| 936 | + | |
924 | 937 | | |
925 | | - | |
| 938 | + | |
| 939 | + | |
| 940 | + | |
| 941 | + | |
| 942 | + | |
926 | 943 | | |
927 | 944 | | |
928 | 945 | | |
929 | 946 | | |
| 947 | + | |
| 948 | + | |
930 | 949 | | |
931 | 950 | | |
932 | | - | |
| 951 | + | |
| 952 | + | |
| 953 | + | |
| 954 | + | |
| 955 | + | |
| 956 | + | |
| 957 | + | |
| 958 | + | |
| 959 | + | |
| 960 | + | |
| 961 | + | |
| 962 | + | |
| 963 | + | |
933 | 964 | | |
934 | 965 | | |
935 | 966 | | |
| |||
1093 | 1124 | | |
1094 | 1125 | | |
1095 | 1126 | | |
| 1127 | + | |
| 1128 | + | |
| 1129 | + | |
| 1130 | + | |
| 1131 | + | |
| 1132 | + | |
| 1133 | + | |
| 1134 | + | |
| 1135 | + | |
1096 | 1136 | | |
1097 | 1137 | | |
1098 | 1138 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
243 | 243 | | |
244 | 244 | | |
245 | 245 | | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
0 commit comments