Skip to content

Accept empty transport bodies for agent grant revocation - #66

Merged
FlyOverCoderKY merged 2 commits into
mainfrom
codex/empty-agent-revocation-20261112
Nov 12, 2026
Merged

FlyOverCoderKY merged 2 commits into
mainfrom
codex/empty-agent-revocation-20261112

Conversation

@FlyOverCoderKY

@FlyOverCoderKY FlyOverCoderKY commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Changes

  • Accept a zero-byte DELETE transport stream when revoking an owned agent grant.
  • Bound body consumption by the existing browser deadline and yield cooperatively during empty-chunk reads. Reject a body containing any bytes, including a forged zero Content-Length.
  • Refresh the original browser authority, session, CSRF and request-header checks after awaiting the body and before the grant mutation.

Validation

  • The active-grant null-body control passed before the change. Both empty-stream and zero-byte-array requests reproduced a 400 response before the fix and passed afterward.
  • The final revision passed 129 focused agent and browser-freshness tests, normal checks and builds on Node 22.18 and Node 24.18.
  • Regressions cover nonempty and chunked bodies, stalled streams, cancellation, deadlines, and session, role and header changes during the body await.
  • The prior 674c980 commit passed the whole local suite on both Node versions, with 1,323 ordinary tests, 155 Native D1 tests and two benchmarks each. The final revision's configured full CI and OpenRouter review must pass before merge.

The live Codex acceptance workflow reached accepted KB evidence, then its grant-revocation action returned an error. The empty-body case is reproduced locally. Live revocation and the subsequent old-credential rejection will be verified after deployment.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
🔒 Security Review ✅ Completed 2026-11-12T04:10:07.488809Z 674c980 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

github-actions Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

OpenRouter review posted (clean). #66 (review)

@github-actions github-actions 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.

OpenRouter pull-request review

Verdict: issues
Scope: full-pr (full-pr)
Mode: initial
Commit: 674c98059e2ca92b49c1673a51078ca94f6c0224
Judge: openai/gpt-5.6-luna (repaired(canonical+4): source coverage preserved before publication cap)
Cost: $0.2225 (lanes $0.2205 + judge $0.0020)

Lanes

  • openai/gpt-6.1-sol: ok (0 finding(s), 36.1s, 163454+1091 tokens (128806 cached), 6 tool round(s), via Azure, $0.12)
  • z-ai/glm-5.3-flash: ok (5 finding(s), 353.6s, 1323344+46251 tokens (1200384 cached), 28 tool round(s), via Wafer, $0.0990)

Findings

🟠 Issue 1 — 16-empty-chunk cap can reject a semantically empty chunked DELETE body

worker/src/agent-access-api.ts:60 · risk · identified by z-ai/glm-5.3-flash

A client that sends a Transfer-Encoding: chunked DELETE whose body consists of more than 16 zero-length chunks transports exactly zero bytes — HTTP-semantically an empty body — but requireEmptyBody throws 400 invalid_request once the 16-read budget is exhausted, so a legitimate revocation fails.

The ten-second absolute deadline (expiresAt plus the setTimeout boundary) already bounds an endless empty-chunk flood, so the read cap adds false rejections without adding a protection the deadline does not already provide; a bytes-based rule (reject any non-zero byte, bound by the deadline) would accept every empty encoding.

Evidence: the loop counts reader.read() calls, not bytes; endless-empty in agent-access-runtime.test.ts pins the 16 cap as intended behavior, and the deadline checks (performance.now() >= expiresAt, request.signal.aborted) already terminate the loop independently of the count. The PR description itself calls this "a finite empty-chunk budget".

Proof gap: I could not confirm whether the production transport (workerd's decoded chunked body stream) or the UI's fetch ever surfaces zero-length chunks individually — undici as a client buffers and would not. If no real transport emits distinct zero-length chunks, the scenario is only reachable from hand-built streams; the finding stands as a semantic gap in the guard, not an observed production failure.

🔵 Issue 2 — Body-read deadline is expressed as two independent hard-coded 10_000 literals

worker/src/agent-access-api.ts:31 · nit · identified by z-ai/glm-5.3-flash

If a future edit changes only one of the two 10_000 literals (expiresAt = performance.now() + 10_000 on line 31 and setTimeout(onAbort, 10_000) on line 50), the wall-clock deadline and the abort/timer boundary diverge, and the effective bound becomes the larger of the two with confusing partial behavior.

The neighboring readJson in api-auth.ts threads a single timeoutMs value into both the expiresAt computation and the setTimeout, which is the established pattern this helper mirrors; a local const timeoutMs = 10_000 (or a shared constant reused with readJson's timeoutMs: 10_000 call sites) would remove the drift risk.

🔵 Issue 3 — Comment on the boundary catch misdescribes its purpose

worker/src/agent-access-api.ts:54 · nit · identified by z-ai/glm-5.3-flash

// Also observe an already-aborted boundary if header validation fails first. sits above void boundary.catch(() => {});.

The actual purpose of that statement is to suppress a potential unhandled promise rejection if boundary rejects (timer, abort) after the loop has already returned or thrown — the boundary is not "already-aborted" at that point, and the catch is not what observes an abort. A reader reconciling the comment with the code has to reverse-engineer the real reason; a comment like "the boundary may still reject after this function exits; keep its rejection handled" would match the mechanism.

🔵 Issue 4 — Mid-reauthentication block duplicated between the DELETE branch and the consent POST path

worker/src/agent-access-api.ts:152 · nit · identified by z-ai/glm-5.3-flash

The new grant DELETE branch (lines ~152–169) is a near-verbatim copy of the consent POST path's post-body re-check (lines ~231–237): sameBrowserHeaders() → requireAgentBrowserContext(request, options, true) → sameBrowserHeaders() → compare rawSessionId and principalId → throw 403 'browser_credential_changed'.

The same re-check protocol now lives in three places in this file (initial derivation, DELETE mid-check, approve mid-check) plus the final check. If the protocol ever gains a field (for example also comparing the CSRF token or extending credentialHeaders), each copy must be updated in lockstep or the two mutation routes diverge in what they accept.

A small local helper taking the captured sessionId/principalId and returning the fresh context would collapse the duplication.

🔵 Issue 5 — Body-deadline documentation not extended to the new empty-DELETE revocation read

docs/KNOWLEDGE_COMPOSITION.md:254 · nit · identified by z-ai/glm-5.3-flash

docs/KNOWLEDGE_COMPOSITION.md (lines 254–258) enumerates exactly which transports carry the ten-second total body-read deadline: "Host-owned JSON POST bodies for portal reads, staff commands, agent test reports and consent approvals", with the 408 request_timeout + cancel + "starts no … command" guarantees.

This PR adds a fourth bounded body read — the empty DELETE body on /api/agent-access/grants/{id}, with the same 408/cancel/no-grant-read-or-commit behavior pinned by the new freshness tests — but the paragraph is not updated to include it, so the composition doc now under-describes the route's actual bounding behavior.

Workflow run

Comment thread worker/src/agent-access-api.ts Resolved
Comment thread worker/src/agent-access-api.ts Resolved
Comment thread worker/src/agent-access-api.ts Resolved
Comment thread worker/src/agent-access-api.ts Resolved

@github-actions github-actions 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.

OpenRouter pull-request review

Verdict: clean
Scope: latest-commit (commit-range)
Mode: verify
Commit: e70bc7cf9bc15f81463ef7f177f6d2e7331b0aa2
Judge: openai/gpt-5.6-luna
Cost: $0.0655 (lanes $0.0654 + judge $0.0001)

Lanes

  • openai/gpt-6.1-sol: ok (0 finding(s), 20.1s, 50524+676 tokens (32728 cached), 3 tool round(s), via Azure, $0.0600)
  • z-ai/glm-5.3-flash: ok (0 finding(s), 29.3s, 54494+3188 tokens (30720 cached), 4 tool round(s), via Venice, $0.0054)

Round 2 resolution

  • ✅ r1-1 fixed correctly — 16-empty-chunk cap can reject a semantically empty chunked DELETE body: requireEmptyBody no longer rejects after 16 empty reads. It continues until EOF, rejecting nonzero bytes and enforcing the absolute ten-second deadline and abort boundary. Every 16 empty reads now yields through a timer so immediately resolved reads cannot starve deadline or cancellation callbacks.

The updated tests cover successful revocation after 33 empty chunks, including invalidation of ac…

  • 4 nit finding(s) from earlier rounds retired (severity floor for follow-up rounds is risk).
  • Open findings after this round: 0 (0 bug-severity).

No structured findings from the successful lane(s).

Workflow run

@FlyOverCoderKY

Copy link
Copy Markdown
Contributor Author

r1-5 is fixed in e70bc7c. The current endpoint paragraph in docs/KNOWLEDGE_COMPOSITION.md documents empty-body grant revocation, cooperative empty-chunk yielding, the ten-second deadline and cancellation, and fresh authorization before the grant mutation.

@FlyOverCoderKY
FlyOverCoderKY merged commit 0c54c5a into main Nov 12, 2026
2 checks passed
@FlyOverCoderKY
FlyOverCoderKY deleted the codex/empty-agent-revocation-20261112 branch November 12, 2026 04:34
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