Skip to content

fix: validate --body before confirmation prompts - #504

Merged
petebacondarwin merged 4 commits into
mainfrom
cjol/generator-body-before-confirm
Nov 4, 2026
Merged

petebacondarwin merged 4 commits into
mainfrom
cjol/generator-body-before-confirm

Conversation

@cjol

@cjol cjol commented Nov 4, 2026 •

Copy link
Copy Markdown
Member

Follow-up to #498, from the review of #477.

Generated commands parsed --body only after authenticating, and for
confirm-gated commands only after the prompt. A malformed or oversized body,
or an unreadable @file, therefore failed after an account lookup or after
the user had accepted a destructive prompt. On main this affected 51
confirm-gated leaves, including kv bulk delete, cache purge,
r2 objects bulk-delete, queues purge and
resource-sharing recipients|excluded-recipients update.

Changes in generator/plugin/emit/handler.ts:

  • Parse once, before auth. Every command with --body now parses (JSON)
    or resolves (raw) it before auth and any prompt, and the bypass reuses the
    result (1043 leaves). Multipart-only commands are excluded because they
    append --body to the form as given.
  • Empty JSON --body. The bypass guard was if (argv.body), so
    --body "" passed the required-body check and then exited 0 without doing
    anything. It is now !== undefined, matching the dry run, which already
    rejected it. Raw bodies keep sending an empty body, as fix: enforce required plain-text request bodies #499 intended.
  • Dry run shows --file. Raw-body dry runs now show the --file path
    instead of body: undefined.
  • No dead parseBody import. It is imported only for JSON bodies, which
    removes the unused import from 29 raw-body leaves (_generated/** isn't
    linted).

On the regenerated output, no confirm-gated leaf parses after the prompt and
no leaf has an unused parseBody import. Most of the generated diff is the
one-line guard change.

Tests: body-limits covers oversized, malformed and empty bodies, each rejected
before auth and confirmation, for PUT/POST/PATCH/DELETE, plus a command with
no confirmation. required-raw-bodies covers an unreadable @file rejected
before auth, the --file dry run, and the absent import.

🤖 Generated with Claude Code

Confirm-gated commands parsed --body only after authenticating and
prompting, so a malformed or oversized body failed after the user had
accepted a destructive prompt. #498 hoisted only the presence check; the
parse now happens before auth and confirmation too.

Also guard the --body branch with `!== undefined`, matching the dry run
and the required-body check, so an empty JSON --body is rejected instead
of skipped; show --file in raw-body dry runs; and import parseBody only
for JSON bodies.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cjol
cjol requested a review from a team as a code owner November 4, 2026 11:12
@cjol
cjol requested a review from jamesopstad November 4, 2026 11:12

@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 8ab6e389.

This review, of 2cd369f2

💬 Approved with comments — The fix is correct and consistent across the generator and the regenerated commands. The only note is an INFO: the raw-body early-parse branch has no test.

Findings: 1 info (1 is an inline comment on the diff)

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


📋 Code Quality: 💬 1 info

The generator change and the regenerated output are correct. The raw-body early-parse branch has no test.

Recommendation: 💬 Optional Nits

  • [INFO] The raw-body branch of preparsedBody has no test and no generated example. (packages/cli/generator/plugin/emit/handler.ts:158)
View full review
  • Generated output: it falls into four uniform patterns:
    • the guard change to argv.body !== undefined
    • the early parsedBody in confirm-gated leaves, reused by the bypass
    • the parseBody import dropped from raw-body leaves
    • the --file dry-run output
  • Ordering: in the confirm-gated leaves, the body is parsed after the dry-run and required-body checks, and before the client, auth and confirmDelete.
  • Raw-body early-parse branch: the non-JSON branch of preparsedBody (handler.ts:156-158) emits resolveFileToken(argv.body, 'body', 'binary') unconditionally. No generated leaf uses it today. It is safe, because resolveFileToken passes undefined through and the bypass re-checks argv.body !== undefined. Still, no test covers it.

✅ All other checks passed

🚀 Release: ✅ LGTM

Low risk. The changeset accompanies the user-facing fix. The tag and prior-release history check was not performed because that history is not available here.


🔒 Security: ✅ LGTM

Confirmation and the --force bypass are unchanged. The body is parsed earlier with the same input. The stricter guard closes a silent no-op on --body "".


📖 AGENTS.md: ✅ LGTM

The generated output comes from a generator change, not hand edits. A changeset is included.


⚡ Performance: ✅ LGTM

No performance concerns.


📝 Documentation: ✅ LGTM

No documentation issues.


Reviewed commit: 2cd369f2

@pkg-pr-new

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

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

commit: ea24beb

@github-actions

github-actions Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

cf --help startup

mean stddev min max
PR 280.7 ms 8.3 ms 272.9 ms 298.9 ms
base 278.6 ms 4.3 ms 273.8 ms 287.2 ms

Δ (PR vs base): ↑ +2.1 ms (+0.8%)

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.

@ask-bonk

ask-bonk Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

LGTM!

github run

@petebacondarwin
petebacondarwin removed the request for review from jamesopstad November 4, 2026 11:34
Generalise the early parse from confirm-gated commands to every command
with --body, so a bad body or unreadable @file fails before auth and
account lookup too. Multipart-only commands keep appending --body to
the form as given, so they are excluded.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@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 01b34012.

This review, of 8ab6e389

✅ Approved — The early body validation is correct and applied the same way across the generator and the regenerated commands. The new tests cover the raw-body branch noted in the last review, and there are 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. The changeset documents the fix as a patch.


🔒 Security: ✅ LGTM

The confirmation prompt and the --force bypass are unchanged. The same input is validated, only earlier. The stricter !== undefined guard closes the silent no-op on --body "".


📖 AGENTS.md: ✅ LGTM

The generated output comes from a generator change, not hand edits. A changeset is included.


📋 Code Quality: ✅ LGTM

Generator. preparsedBody runs after the dry-run and required-body checks and before auth and deleteConfirm. multipartTakesBody leaves multipart-only operations out. parseBody is imported only for JSON bodies.

Generated leaves. They match the generator. parseBody arguments such as item limits and redaction paths carry over unchanged.

Tests. required-raw-bodies.test.ts now covers the raw early-parse branch.


⚡ Performance: ✅ LGTM

No performance concerns.


📝 Documentation: ✅ LGTM

No documentation issues in the changed files. The changeset describes the user-facing fix.


Reviewed commit: 8ab6e389

@ask-bonk

ask-bonk Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

Review: 1 findings.

🤖 I've done a thorough review of your PR.

Moves body validation before authentication and confirmation.

  • Warning: 1 inline suggestion posted.

github run

@ask-bonk

ask-bonk Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

LGTM!

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 ea24beb2.

This review, of 01b34012

✅ Approved — No findings. --body is now validated before auth and before confirmation prompts. Precedence between --body, --file and multipart inputs is unchanged, and the regenerated commands match the generator.

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. The changeset marks this fix as a patch release.


🔒 Security: ✅ LGTM

The confirmation prompt and the --force bypass are unchanged. The same input is validated as before, only earlier. The !== undefined guard stops --body "" from passing the required-body check and then exiting without doing anything.


📖 AGENTS.md: ✅ LGTM

The generated output comes from the generator change, not from hand edits, and a changeset is included.


📋 Code Quality: ✅ LGTM

  • Ordering. preparsedBody runs after the dry-run and required-body checks and before auth and deleteConfirm.
  • Precedence. The new earlierBranchReads guard skips the early parse when a multipart field or --file will be used instead of --body.
  • Parse arguments. parseBody arguments such as redaction paths and item limits carry over unchanged.
  • Raw bodies. These resolve once with resolveFileToken, and the dry run now shows --file.
  • Tests. Both oversized/malformed/empty bodies and --file precedence are covered.

⚡ Performance: ✅ LGTM

No performance concerns. The body is parsed once.


📝 Documentation: ✅ LGTM

The changeset describes the user-facing fix.


Reviewed commit: 01b34012

@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 — No findings. --body is now validated before auth and before confirmation prompts. Precedence between --body, --file and multipart inputs is unchanged, and the regenerated commands match the generator.

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. The changeset marks this fix as a patch release.


🔒 Security: ✅ LGTM

The confirmation prompt and the --force bypass are unchanged. The same input is validated as before, only earlier. The !== undefined guard stops --body "" from passing the required-body check and then exiting without doing anything.


📖 AGENTS.md: ✅ LGTM

The generated output comes from the generator change, not from hand edits, and a changeset is included.


📋 Code Quality: ✅ LGTM

  • Ordering. preparsedBody runs after the dry-run and required-body checks and before auth and deleteConfirm.
  • Precedence. The new earlierBranchReads guard skips the early parse when a multipart field or --file will be used instead of --body.
  • Parse arguments. parseBody arguments such as redaction paths and item limits carry over unchanged.
  • Raw bodies. These resolve once with resolveFileToken, and the dry run now shows --file.
  • Tests. Both oversized/malformed/empty bodies and --file precedence are covered.

⚡ Performance: ✅ LGTM

No performance concerns. The body is parsed once.


📝 Documentation: ✅ LGTM

The changeset describes the user-facing fix.


Reviewed commit: ea24beb2 — same changes as 01b34012, so this is that commit's review (no new review was run; line numbers are as of 01b34012)

@ask-bonk

ask-bonk Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

LGTM!

github run

@petebacondarwin
petebacondarwin added this pull request to the merge queue Nov 4, 2026
Merged via the queue into main with commit 1de7b1b Nov 4, 2026
11 checks passed
@petebacondarwin
petebacondarwin deleted the cjol/generator-body-before-confirm branch November 4, 2026 21:44
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.

2 participants