Skip to content

fix: enforce required plain-text request bodies - #499

Open
petebacondarwin wants to merge 3 commits into
mainfrom
codex/fix-required-raw-bodies
Open

petebacondarwin wants to merge 3 commits into
mainfrom
codex/fix-required-raw-bodies

Conversation

@petebacondarwin

@petebacondarwin petebacondarwin commented Nov 3, 2026 •

Copy link
Copy Markdown
Collaborator

Required plain-text request bodies could lose their input requirement during generation and fall through to a bodyless typed request. This is the regression reported for cf zaraz workflow update in the review on #477.

Preserve the requirement for non-JSON bodies and reject missing --body / --file input before authentication. Keep valid empty multipart requests supported, send explicitly supplied empty raw bodies, and validate explicitly supplied file paths. Regenerate the tracked commands with the existing OpenAPI pin and include a patch changeset. Regenerating #477 with this plugin restores its workflow input guard.

Validation:

  • pnpm check passes.
  • Generator suite plus the body-bypass, KV, and R2 command tests: 443 tests pass across 22 files.
  • Full Wrangler compatibility suite: 659 tests pass across 60 test files.
  • Generate and execute the workflow command from chore: update OpenAPI to 42c9a46a5c1b #477's pinned Zaraz schema: missing input fails before authentication and no bodyless typed fallback is emitted.

@petebacondarwin
petebacondarwin requested a review from a team as a code owner November 3, 2026 20:35
@pkg-pr-new

pkg-pr-new Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
npm i https://pkg.pr.new/cf@499

commit: 257de79

@github-actions

github-actions Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

cf --help startup

mean stddev min max
PR 284.2 ms 4.6 ms 274.4 ms 290.9 ms
base 283.8 ms 5.5 ms 275.0 ms 295.2 ms

Δ (PR vs base): — +0.4 ms (+0.1%)

Measured with hyperfine on ubuntu-latest (3 warmup runs, 20 timed runs). CI numbers carry ±a few ms of runner jitter; treat small deltas as noise.

@clanky-the-clanker clanky-the-clanker Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Superseded by the review of 6b55e475.

This review, of 8c2435de

💬 Approved with comments — The raw-body requirement fix is correct and regenerated consistently. One WARNING: multipart commands still let an explicit empty --file through without validating it.

Findings: 1 warning

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.

🔧 Fix with your agent

Paste the following into your coding agent to investigate and fix these issues.

Fix the following code review issues found in pull request #499.

Before making changes, review each issue and present a brief summary table:
- For each finding, state whether you agree, disagree, or need clarification
- If you disagree (e.g., the fix would require disproportionate changes
  for minimal ROI, or the finding is factually incorrect), explain why
- If you need to clarify something before deciding, ask those questions
- Then share your plan for which issues to tackle and in what order

## WARNING (1)

### [Code Quality] The multipart emitter still checks `argv.file` by truthiness. An explicit `--file ""` enters the multipart branch (the outer guard uses `!== undefined`) but skips `readFileForFlag`, so the command sends a FormData request with no payload field instead of rejecting the empty path. Raw uploads now reject it; use `argv.file !== undefined` here as well and regenerate.
- **File:** packages/cli/generator/plugin/emit/handler.ts:423

📋 Code Quality: ⚠️ 1 warning

The raw-body fix is coherent; the multipart branch still skips validation of an explicit empty --file.

Recommendation: 📝 Minor Comments

  • [WARNING] The multipart emitter still checks argv.file by truthiness. An explicit --file "" enters the multipart branch (the outer guard uses !== undefined) but skips readFileForFlag, so the command sends a FormData request with no payload field instead of rejecting the empty path. Raw uploads now reject it; use argv.file !== undefined here as well and regenerate. (packages/cli/generator/plugin/emit/handler.ts:423)
View full review

Multipart --file "" is not validated (packages/cli/generator/plugin/emit/handler.ts:423; generated output such as packages/cli/src/commands/_generated/dns/records/import.ts:94)

This pull request changes fileUpload() to if (argv.file !== undefined), so readFileForFlag now rejects --file "" on raw uploads. The multipart emitter's outer guard already treats argv.file !== undefined as input, so --file "" enters that branch. Its inner if (argv.file) { is falsy, though, and --body is undefined, so the command sends a FormData request with no payload field instead of failing with the invalid-file error. That falls short of the stated goal of validating explicitly supplied file paths, and it leaves raw and multipart commands handling the shared --file flag differently.

Fix: emit if (argv.file !== undefined) { in the multipart branch, regenerate the commands, and add a multipart --file "" case to required-raw-bodies.test.ts.


✅ All other checks passed

🚀 Release: ✅ LGTM

Risk: low. The patch changeset is appropriate for this fix.


🔒 Security: ✅ LGTM

No security issues. Missing required input is now rejected before authentication.


📖 AGENTS.md: ✅ LGTM

The generated output is regenerated rather than hand-edited, and the pull request includes a patch changeset, as the repository rules require.


⚡ Performance: ✅ LGTM

No performance concerns.


📝 Documentation: ✅ LGTM

No documentation issues.


Reviewed commit: 8c2435de

@ask-bonk

ask-bonk Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

LGTM

github run

@ask-bonk

ask-bonk Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

No new concerns since the last review

github run

@clanky-the-clanker clanky-the-clanker Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Superseded by the review of 257de795.

This review, of 6b55e475

💬 Approved with comments — The raw-body requirement fix is correct and was regenerated consistently. One WARNING is still open: multipart commands let an explicit empty --file through without validating it.

Findings: 1 warning

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.

🔧 Fix with your agent

Paste the following into your coding agent to investigate and fix these issues.

Fix the following code review issues found in pull request #499.

Before making changes, review each issue and present a brief summary table:
- For each finding, state whether you agree, disagree, or need clarification
- If you disagree (e.g., the fix would require disproportionate changes
  for minimal ROI, or the finding is factually incorrect), explain why
- If you need to clarify something before deciding, ask those questions
- Then share your plan for which issues to tackle and in what order

## WARNING (1)

### [Code Quality] Multipart emitter still checks `argv.file` by truthiness: an explicit `--file ""` enters the multipart branch but skips `readFileForFlag`, so it sends a FormData request with no payload instead of rejecting the empty path.
- **File:** packages/cli/generator/plugin/emit/handler.ts:423

📋 Code Quality: ⚠️ 1 warning

One open warning: multipart commands do not validate an explicit empty --file "".

Recommendation: 📝 Minor Comments

  • [WARNING] Multipart emitter still checks argv.file by truthiness: an explicit --file "" enters the multipart branch but skips readFileForFlag, so it sends a FormData request with no payload instead of rejecting the empty path. (packages/cli/generator/plugin/emit/handler.ts:423)
View full review

Multipart --file "" is not validated (packages/cli/generator/plugin/emit/handler.ts:423; generated output such as packages/cli/src/commands/_generated/dns/records/import.ts:95)

  • This pull request changes fileUpload() to if (argv.file !== undefined), so raw uploads now reject --file "" through readFileForFlag.
  • The multipart emitter's outer guard (handler.ts:410-411) already treats argv.file !== undefined as input, so --file "" enters the multipart branch.
  • The inner check at handler.ts:423 is still if (argv.file) {. An empty string is falsy, so file validation is skipped. With --body unset, the command then sends a FormData request with no payload field.

This misses the stated goal of validating explicitly supplied file paths, and raw and multipart commands now treat the shared --file flag differently.

Fix: emit if (argv.file !== undefined) { at handler.ts:423, regenerate the commands, and add a multipart --file "" case to required-raw-bodies.test.ts.

The updated snapshot in kv/key.test.ts matches the generated kv/keys/put.ts error message.


✅ All other checks passed

🚀 Release: ✅ LGTM

Risk: Low. A patch changeset is appropriate for this fix.


🔒 Security: ✅ LGTM

No security issues found.


📖 AGENTS.md: ✅ LGTM

The pull request follows the repository rules: generated commands are regenerated rather than hand-edited, and a patch changeset is included.


⚡ Performance: ✅ LGTM

No performance concerns.


📝 Documentation: ✅ LGTM

No documentation issues.


Reviewed commit: 6b55e475

@clanky-the-clanker clanky-the-clanker Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Approved — The raw-body requirement fix is correct and consistently regenerated, and the earlier multipart --file "" warning is fixed and covered by a regression test. No open findings.

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


✅ All checks passed

🚀 Release: ✅ LGTM

Risk: Low. A patch changeset is appropriate for this fix.


🔒 Security: ✅ LGTM

No security issues found.


📖 AGENTS.md: ✅ LGTM

The pull request follows the repository rules: generated commands are regenerated rather than hand-edited, and a patch changeset is included.


📋 Code Quality: ✅ LGTM

The multipart emitter at packages/cli/generator/plugin/emit/handler.ts:423 now emits if (argv.file !== undefined), so --file "" is validated through readFileForFlag the same way as on the raw upload path. No generated command still uses a truthiness check on argv.file. The regression test in required-raw-bodies.test.ts checks that the command rejects the empty path and that no request is sent. Sampled regenerated commands (analytics-engine/sql/query.ts, logs/query.ts) no longer have the bodyless typed fallback.


⚡ Performance: ✅ LGTM

No performance concerns.


📝 Documentation: ✅ LGTM

No documentation issues.


Reviewed commit: 257de795

@ask-bonk

ask-bonk Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

LGTM!

github run

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant