Repository navigation
fix(rest): the email send door refuses an array or null body with its own 400 INVALID_REQUEST - #31541
Conversation
Claude-Session: https://claude.ai/code/session_01FEkQ5mNZhe975x6zR3ULqS Co-authored-by: Claude <noreply@anthropic.com>
The send route admitted a JSON array (typeof object) and defaulted a
JSON null to {}, so both reached the email service and were refused
there as VALIDATION_FAILED. A present body must now be a plain object;
anything else takes the route's own 400 INVALID_REQUEST.
Claude-Session: https://claude.ai/code/session_01FEkQ5mNZhe975x6zR3ULqS
Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FEkQ5mNZhe975x6zR3ULqS Co-authored-by: Claude <noreply@anthropic.com>
📓 Docs Drift Check1 anchor(s) derived from 1 changed package(s); no hand-written page names any of them, so this run has nothing to list — not a clean bill of health. This check sees only pages that NAME a derived anchor: one that documents this change in prose, or enumerates it in an authoring dialect, names none and stays invisible to it on every run. What this run could not see
Coarse fallback — 19 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): Which tree this was computed onThis run read A worktree cut from an older # while this PR is open — GitHub drops the merge commit once it closes
git fetch origin 46edf43e3a106b4276a5642a8d84706f13f6540c && git checkout 46edf43e3a106b4276a5642a8d84706f13f6540c
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 7d7af560562d7f739b32a8cd66390151a1c34946 0319dc519cf4ad6147279eefde2e4599be5f3953 && git checkout -B drift-repro 7d7af560562d7f739b32a8cd66390151a1c34946 && git merge --no-ff 0319dc519cf4ad6147279eefde2e4599be5f3953
node scripts/docs-audit/affected-docs.mjs --json 7d7af560562d7f739b32a8cd66390151a1c34946 |
|
domain:server#5 · os-project-manager · session_01FEkQ5o8PE7ZtVjcor51wBZ 席位意见:接受。 席位核对 — ACCEPT ·
|
Requested by Leehom · project thread
Fixes #31496
Clause-②: no
Metadata-protocol: none
维护者速读
POST /api/v1/email/send收到 JSON 数组或 JSONnull作为请求体时,现在在路由自己这一层直接回400 INVALID_REQUEST("JSON body required"),邮件服务不再被调用。typeof也是object,能穿过路由原来的检查;null原来被默认成{}。两者都被送进邮件服务,再由服务以400 VALIDATION_FAILED("subject is required")拒绝,错误码与路由自己的约定不一致(QA QA run · owed:weekly (73/73) · 0647dabb · 2026-11-08 · 61 PASS / 7 PARTIAL / 4 FAIL / 1 BLOCKED / 0 NOT-RUN #31486 C3a)。VALIDATION_FAILED变为路由的INVALID_REQUEST;对象请求体和不带请求体的请求行为不变。回滚即 revert 本 PR。packages/rest/src/email-routes.ts(请求体检查那 7 行),再看packages/rest/src/email-send-door-bounds.test.ts末尾新增的 describe。pnpm --filter @objectstack/rest exec vitest run src/email-send-door-bounds.test.ts,预期 50 个用例全绿;把检查改回typeof body !== 'object'后数组三个用例转红。What changes
The send door's body check, in
registerEmailEndpoints(packages/rest/src/email-routes.ts), was the only route body check in that file:const body = req.body ?? {}; if (!body || typeof body !== 'object'). An array passestypeof body !== 'object', and a JSONnullwas defaulted to{}. Both reachedemailService.send, which refused them as malformed messages (400 VALIDATION_FAILED, "subject is required" from plugin-email'snormalizeMessage).const body = req.body === undefined ? {} : req.body; if (!isPlainObject(body)).isPlainObjectis the helper the same file already uses forheaders(it excludes arrays withArray.isArray). An array ornullnow takes the route's own400 INVALID_REQUEST"JSON body required", before the service is reached.{}for an empty body; theundefinedarm covers an embedder whose adapter leaves it unset.) Every object body is forwarded exactly as before, and a string or number body keeps the same answer.Sweep of the same file.
email-routes.tsregisters one route, so this is the only route body check in it. The other object-shape check in the file,headersRefusal, already goes throughisPlainObject.Clause-② read from the diff:
no. The shipped service refuses every array andnullbody with a 400, because none of them carries asubject. After this change they are still refused with a 400, now with the route's own code. Nothing that answered 200 before is refused now.Tests
packages/rest/src/email-send-door-bounds.test.tsgets a new top-leveldescribein the existing harness. It runs through the realHonoHttpServertransport, with a contract-typed email double:400withcode: 'INVALID_REQUEST'whilesendis never called: an array of numbers, an empty array, an array holding a well-formed message, a JSONnull, a JSON string and a JSON number.send, as sent.{}still reachessend, stamped only withsentBy. It is a message for the service to judge, not a missing body.The file also gains a module-top
import '@objectstack/objectql';.check:test-source-aliasasks for it on any edited test whose server reach loads objectql dynamically inside a handler.Red on main first (4 of the 6 refusal cases; the string and number cases were already green)
Ablation (scripts/ablation-replace.mjs, src is what the suite imports, so no build leg)
Leg 1 puts back
if (!body || typeof body !== 'object') {. Mutation landed (anchor 1 → 0, blob 626f40efea2e → 895cf1968604):Leg 2 puts back
const body = req.body ?? {};. Mutation landed (blob 626f40efea2e → 47919d207c32):Acceptance notes
packages/rest(not in this diff). I searchedpackages/rest/src, excluding tests, for everytypeof …body… !== 'object'check. There are four. Three already exclude arrays:analytics-dataset-body-door.ts,meta-record-currency-backfill-route.tsanduser-work-routes.ts. The fourth is this one. Nothing is left to list.INVALID_REQUESTandVALIDATION_FAILEDanswers are still the flat{ code, error }body, while its bounds answer the nested ADR-0112 envelope. That predates this card, and this PR does not change it.Verification
HEAD0319dc5 (after mergingorigin/mainonce):pnpm --filter @objectstack/rest test: 394 files and 7546 tests passed, 332 skipped (run on 1dfcd3e, before the merge and the test-only import commit).pnpm --filter @objectstack/rest exec vitest run src/email-send-door-bounds.test.ts src/email-send-display-name.test.tson 0319dc5: 2 files, 69 tests passed.pnpm --filter @objectstack/rest typecheck: exit 0.pnpm exec eslint --no-inline-configon the two touched source files: exit 0.dispatch-gates --commands: 64 commands. Their exit codes are in the seat report on the card.Generated by Claude Code