Skip to content

Block every refusal §6.4 names in the adapters - #616

Open
bar-capsule wants to merge 4 commits into
GenAI-Security-Project:release/0.2from
bar-capsule:bar/adapters-fail-closed
Open

bar-capsule wants to merge 4 commits into
GenAI-Security-Project:release/0.2from
bar-capsule:bar/adapters-fail-closed

Conversation

@bar-capsule

Copy link
Copy Markdown
Collaborator

What changed

The adapters now end a step the three ways #603 sets in §6.4:

  1. A verified decision is honored, as before.
  2. A decision failure follows the posture: silence past the timeout, a failed connection or TLS handshake, an HTTP 408 or 5xx with no JSON-RPC body, or a signed -32603.
  3. Anything else blocks the step whatever the posture:
    • any other non-2xx HTTP status, whatever its body, 429, 404 and redirects included (was 400 and 413 with no JSON-RPC body, while a signed allow under any status was honored);
    • every signed error but -32603, a code added later or one that isn't an integer included (was six listed codes);
    • an answer that can't be parsed (not HTTP, not JSON, nested past the parser's depth) or that fails response-envelope.json anywhere in the envelope, an allow and a signed -32603 included (these followed the posture, and only the result was checked).

The handshake applies the same split. These answers refuse the session whatever ACS_STARTUP_POSTURE says, and so does a signed ServerHello that fails handshake.json or doesn't answer the ClientHello (it counted as no answer, and only some fields were checked).

Three changes keep the split exact:

  • A connection that closes before the end of the body is a transport failure, so it follows the posture instead of reading as a malformed answer.
  • A refusing status stays a refusal when its body stalls past the deadline, instead of reading as silence.
  • NAT composes its block reason from the class and cause, as Claude Code and Cursor already do, so the text the agent sees never quotes the Guardian's error message.

Docs: the README's degraded-Guardian section, SECURITY.md T5, the three mapping pages, and the env-table and troubleshooting rows. The NAT README's audit samples now show guardian_refusal_fail_closed, which the adapter already emitted for those codes.

Which issue does this implement

Refs #32
Refs #603

Merge timing: like the spec change it implements, this belongs to 0.2, so it shouldn't merge before 0.1.5 is cut. I'll retarget it to the 0.2 branch once that exists.

Base branch

  • integration, because this touches the specification, schemas, a reference
    implementation, an adapter, tests, or CI
  • main, because every changed path is on the documentation lane allowlist in
    CONTRIBUTING.md

Type of change

  • Specification change (schema, hooks, events, AgBOM)
  • Reference implementation or adapter
  • Documentation
  • Tooling or CI
  • Governance (licensing, security policy, contributor docs)

Breaking for deployments? Yes, for a deployment that opted into proceed. A Guardian behind a rate limiter that answers 429, a wrong URL path that answers 404, or a Guardian that answers a malformed allow now blocks the step instead of letting it through. The audit cause names the status (http_429_refusal), and the troubleshooting rows say so.

I tested this

  • I synced my branch with the base branch before opening this
  • uv run pytest -v passes on my machine
  • uv run mkdocs build --strict passes on my machine

Each rule has a test in tests/client/test_exchange.py, tests/client/test_session.py and tests/core/test_errors.py. NAT's test_untrusted_answers.py checks that the protected function never ran. The 133 new assertions all fail on integration. Two existing NAT controls had been answering with an allow that fails response-envelope.json, so they now send a conformant one.

  • Adapters with the NAT extra: 672 passed, 3 skipped (all 3 expected: two opt-in live Claude Code tests and one manual Cursor check). Without it: 527 passed, 3 skipped.
  • lint-imports: 2 contracts kept. The wheel check passes.
  • Root pytest: 1237 passed, 1 skipped.

Live run of the built wheel in Claude Code and NAT, through a recording proxy and a proxy that injects the answer to the tool call, with the agent opted into proceed. The stalled-body cases skip the recording proxy, which buffers whole responses, and 404, -32050, the stalled 503 and the Guardian that declares deny ran in Claude Code only:

  1. Ran the tool: 503, a 503 whose body stalls past the deadline, and a signed -32603.
  2. Blocked it: 429, a 429 carrying a signed allow, 404, a signed -32601, a signed -32050, a malformed allow, an allow that is also a ServerHello, a signed -32603 with no message, JSON nested past the parser's depth, and a 429 whose body stalls past the deadline. The canary file stayed absent, and NAT's protected function ran 0 times.
  3. Blocked despite the opt-in: a 503 from a Guardian that declares deny.

The block text names the class and cause, for example refused (http_429_refusal). The Guardian's error message appears only in the audit record. Cursor wasn't run live; it goes through the same client code.

Checklist

  • Commits are signed off with git commit -s (required by the DCO)
  • Prose follows STYLE.md
  • No secrets, tokens, or internal URLs in the diff

Security

  • This change has no security impact

Under proceed, an attacker who could make the Guardian answer 429, 404, an unregistered error code or a malformed allow could let the step through, and a signed allow under a 4xx went through under either posture. Those answers now block it.

@drk-ram drk-ram left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewed _exchange.py, _handshake.py, _outcome.py, _error.py, and the updated adapter test suites (132abe8d):

  • Unified §6.4 refusal boundary in acs.client (http_decision_failure, MalformedResponseError, round_trip): Treating only HTTP 408 and 500..599 (with no JSON-RPC body) and signed -32603 as Undecided decision failures, while classifying every other non-2xx HTTP status (429, 404, redirects included—even if headers arrived before the deadline via aborter.status), any signed error other than -32603, any unsigned error, and any AcsResult that fails response-envelope.json (including a malformed allow) as Refused closes the remaining fail-open paths under ACS_DEFAULT_DENY=0.
  • Truncated body & schema validation (_read, _validator): Raising ConnectionError on http.client.IncompleteRead or positive remaining resp.length and validating ServerHello against handshake.json#/$defs/ServerHello keep the handshake and step gates consistent.

artmaro
artmaro previously approved these changes Nov 18, 2026

@artmaro artmaro left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@bar-capsule Looks good, thanks. I checked it against §6.4 from #603 and ran the adapter tests locally.

@bar-capsule
bar-capsule marked this pull request as draft November 19, 2026 09:31
@bar-capsule

Copy link
Copy Markdown
Collaborator Author

Back to draft while we wait for other PRs to merge first: #618 changes the same client files as this one, after #600 already did. I'll rebase once on top of them and ask for another look then.

@Noctis-dev1

Copy link
Copy Markdown

@bar-capsule a real-host check of this PR at 132abe8, from the #434 item 6 runs (Claude Code 2.1.322, the claude_code adapter, six malformed answers at steps/toolCallRequest, two postures × two wirings, five reps each). It matches #603's §6.4. Against integration at 3f6d1d2, a signed allow that fails response-envelope.json and a non-JSON 200 both ran under an opted-in proceed. With this PR (on bf985ca) both are refused in every configuration, HTTP 500 stays on the posture, and the other four faults are unchanged. The base gap doesn't explain it: db457a8, before #600, and 3f6d1d2, after it, gave identical results. Evidence and verifier: https://github.com/Noctis-dev1/acs-434-item6 (REPORT.md, findings 4 and 5). I'll re-run after the rebase.

One question from the runs: which class should a mismatched id get? D-029 says signature_invalid, and trace/events.md keeps that class apart "so a tampered response does not blend into organic failures". The mapping's definitions, #603's included, put it under malformed_response ("for any reason other than its signature"), and failure_class() in client/_config.py does the same. If D-029 is the intent, the change sits in failure_class(). I'm happy to take it once there's an accepted issue for it (D-041).

@bar-capsule

Copy link
Copy Markdown
Collaborator Author

Thanks for the runs. D-029 is the intent: a mismatched id or result.request_id is signature_invalid, since a verified response bound to another request is a replayed or spliced answer. The signature_invalid definitions in otel-mapping.json and trace/events.md predate #603 (#275) and say otherwise, so they need fixing together with failure_class(). I noted it on #308, where D-029 was decided.

@rocklambros

Copy link
Copy Markdown
Collaborator

Hi Bar, this draft conflicts with integration in nine files, mostly the adapter docs under adapters/docs/ and the client handshake in adapters/src/acs/client/. Since it builds on #603, rebasing it after #603 is rebased should be the least work.

@rocklambros
rocklambros changed the base branch from integration to release/0.2 November 26, 2026 14:27
@rocklambros
rocklambros dismissed artmaro’s stale review November 26, 2026 14:27

The base branch was changed.

@rocklambros

Copy link
Copy Markdown
Collaborator

I moved this PR's base to release/0.2, the new branch for 0.2 work. Changes to the spec, the schemas, or the conformance requirements now go there, and PR #675 records that rule as D-052. Please rebase onto release/0.2 instead of integration. The two branches are the same commit today, so the conflicts from my earlier comment haven't changed.

Moving the base dismissed Evgeniy's approval, though the rebase would have dismissed it anyway.

rocklambros
rocklambros previously approved these changes Nov 26, 2026

@rocklambros rocklambros left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Restoring the approval that moving this PR to release/0.2 dismissed. The commit is the one Evgeniy approved, 132abe8. I didn't re-review the code or run it, because it still conflicts with release/0.2. The rebase will dismiss this approval too, so it needs a fresh review after that.

rocklambros added a commit that referenced this pull request Nov 26, 2026
Bar Kaduri's review on PR #675: an adapter that enforces a rule only the 0.2 specification has, like PR #616, has to land with that change. D-052, CONTRIBUTING.md, and the pull request template now say so.

Signed-off-by: rocklambros <rock@rockcyber.com>
Only an HTTP 408 or 5xx with no JSON-RPC body and a signed -32603 follow
the posture. Any other non-2xx status, every other signed error, and an
answer that cannot be parsed or fails response-envelope.json, an allow
included, block the step and refuse the handshake. The ML-DSA keyring
path follows the same rule.

Signed-off-by: Bar Kaduri <bar@capsule.security>
A signed step result offered as a ServerHello, on the HMAC and the key
document path, and an id with neither result nor error now refuse the
session. The gateway's 429 cause is http_429_refusal; it still denies.

Signed-off-by: Bar Kaduri <bar@capsule.security>
@bar-capsule
bar-capsule force-pushed the bar/adapters-fail-closed branch from 132abe8 to 5c97225 Compare November 29, 2026 10:00
@bar-capsule
bar-capsule marked this pull request as ready for review November 29, 2026 10:00
@bar-capsule

Copy link
Copy Markdown
Collaborator Author

Rebased onto release/0.2. #600 and #618 rewrote the client code this PR changes, so I re-applied the same rules on top of them: only a timeout, a lost connection, an HTTP 408 or 5xx with no JSON-RPC body, or a signed -32603 follows the posture, and everything else that arrives is refused, the ML-DSA path included. A second commit moves the tests and docs added since then onto the refusal. The gateway still denies a 429, now with cause http_429_refusal.

Ran locally: conformance for Claude Code, Cursor and NAT (with the nat and pqc extras), guardian, interop and the gateway suite, all passing.

@artmaro the base move dismissed your approval, could you take another look? @rocklambros same for you, the code under your approval changed. @Noctis-dev1 this is the rebase you were waiting for.

@Noctis-dev1

Copy link
Copy Markdown

@bar-capsule re-ran the item-6 real-host check against the rebased head (5c97225 on release/0.2), with the same fault Guardian, runner and verifier as the 20 Nov run (unchanged) and Claude Code 2.1.322. All 140 runs match the 20 Nov campaign at 132abe8:

So the refusals survived the rebase onto #600 and #618. verify.py → 140 runs, 28 configurations, VERIFIED; check_delivery.py → DELIVERY CHECKED. Evidence and verifier, campaign D at 5c97225: https://github.com/Noctis-dev1/acs-434-item6 (REPORT.md pinned-versions table).

One unchanged item from the 20 Nov run, for the record: wrong_request_id still records as malformed_response, not signature_invalid (finding 5). I see you've logged the D-029 fix on #308, so it's tracked — just noting this run reproduces it; nothing needed here.

@bar-capsule

Copy link
Copy Markdown
Collaborator Author

@Noctis-dev1 thanks for re-running it on the rebased head, that's the check this rebase needed. @artmaro @rocklambros the real-host results match the 20 Nov run, so #616 is ready for another look.

@DanPazlev

Copy link
Copy Markdown
Collaborator

This needs a fresh review at the current head, since the earlier approvals were dismissed when the PR moved to release/0.2. Noctis's real-host runs match the 20 Nov campaign, so please re-approve or request changes at the current head.

@DanPazlev

Copy link
Copy Markdown
Collaborator

Approvals were dismissed on the move to release/0.2, and the head I think is now e5d92e0. I think it could use a fresh review at that head. Don't forget to include the Noctis real-host results in the review request.

@DanPazlev

Copy link
Copy Markdown
Collaborator

Current head is e5d92e0. Please re-review there. I think noctis's real-host results were run on the rebased head, 5c97225, and do seem to match the 20 Nov campaign though...

@Lrd0036

Lrd0036 commented Nov 30, 2026

Copy link
Copy Markdown
Collaborator

@DanPazlev @bar-capsule — looking at the CI failure on 37adcb8a (tests and tests-without-nat), all 3 failures are in the newly merged Codex suite from #162:

  • adapters/tests/integrations/codex/test_adapter.py:338 (AdapterTests.test_an_unreadable_response_follows_the_posture) for raw=b'no json', b'[]', and b'{"jsonrpc":"2.0","result":[]}' under posture='0'.

The Codex adapter is actually enforcing the 0.2 refusal behavior ('deny' under posture='0'), so the test synced from integration just needs to be updated to expect deny under either posture (along with the "unreadable allow" line in adapters/docs/codex/mapping.md if applicable). Once that's green, I'm happy to review and approve.

@acs-board-reconciler acs-board-reconciler Bot moved this from Needs triage to In progress in ACS Project Tracker Dec 3, 2026

This branch has not been deployed

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

Labels

None yet

Projects

Status: In progress

Development

Successfully merging this pull request may close these issues.

7 participants