Repository navigation
fix(agt): validate Guardian decision responses - #249
mjatin2007 wants to merge 10 commits into
Conversation
|
Hi @shivang-sec and @President, may I check how you’d prefer to sequence this? Section 6.4 on |
|
Thanks for checking, @mjatin2007 . I’d lean toward opening a Discussion for the Section 6.4 clarification first, while keeping this draft open for implementation review in parallel. That should let us resolve the intended behavior for parseable but schema-invalid Guardian responses before merging a change that deliberately differs from the current wording. I agree with keeping protocol violations distinct from technical failures, with the exact fail-closed behavior and its relationship to I’ll defer to @President on the preferred sequencing before we treat the behavior as settled. |
|
@mjatin2007 @shivang-sec - I think no new Discussion needed: same question is already open in #32 and in Rock's #308. In #308 I proposed that a reply that breaks the spec, e.g. a missing required field, is DENY, not a decision failure. That is what this draft already does. Until the spec's §6.4 text changes, I'd note in the host adapter's README that this is a stricter reading of §6.4. #182, the issue this draft fixes, is already accepted. Once #229 adds response signatures, I'd check the signature first (a bad one is DENY), then the schema. |
|
@President @shivang-sec I added the requested README clarification that the adapter intentionally takes a stricter reading of the current §6.4. I left signature-before-schema validation for #229. The update is in 3f4debc. Thanks! |
|
Hi Jatin, OWASP requires a sign-off on every commit, and 3f4debc on this PR doesn't have one. The Please run these commands: They add a |
Signed-off-by: Jatin Mannepalli <mjatin2007@users.noreply.github.com>
Signed-off-by: Jatin Mannepalli <mjatin2007@users.noreply.github.com>
3f4debc to
625efb4
Compare
|
Thanks, Rock. I rebased the branch onto the current |
|
@mjatin2007 thanks, the README note is exactly what I meant. Looks good to me. |
drk-ram
left a comment
There was a problem hiding this comment.
Security peer review of commit 625efb48f91276239a7961e30a6cfb96b6be9df0.
No exploitable security vulnerability found in the changed code. Decision results are checked against both the canonical response envelope and the method-specific result contract. Schema-invalid replies and recognized refusals take the deny path regardless of the negotiated delivery-failure posture; local validator unavailability remains a separately audited host fault.
Validation at that exact commit:
- Directly changed decision-client and failure-posture suites: 91 passed, 0 failed.
- Broader host-adapter and affected host suites: 393 passed, 53 failed across 446 tests. The 91 focused tests are included in this broader count, not additional tests.
- Comparison against the exact pre-change base
bac52e1c63ba479e7193b9a33d6b40ca5c4e046a: 382 passed, 53 failed across 435 tests on the same Windows host. The broader run therefore is not a clean pass, and the same failure count is present without this change.
I am leaving a non-blocking comment rather than an approval because the broader affected suite is not green in this environment. I found no security issue in this change that warrants a request for changes.
|
@rocklambros @President @drk-ram, thank you for the feedback. Please let me know if there is anything else I can help with here. I'm happy to assist. |
|
Tested rows 1 to 3 from #378 and the no-reasoning deny from #182 through the Claude Code shim, replaying real Guardian responses with one field changed each. integration at db457a8 vs 625efb4: Blocked ones are invalid_response, audited. A real Guardian still allows |
rocklambros
left a comment
There was a problem hiding this comment.
Hi Jatin, thank you for this, and thank you for waiting. I reviewed commit 625efb4.
The validation works. An unknown decision, wrong types, missing fields, a result together with an error, and a deny with no reasoning are all denied now. A second reviewer also tried very deep nesting, a 20 MB string, and __proto__ keys, and none of them made the validator throw. One change is needed before merge.
-
When the host cannot load its schemas, a deny from the Guardian becomes an allow.
applyFailurePosture()inreference-implementations/agt/packages/host-adapter/src/failure-posture.ts:334setsfailClosed = refused || invalidResponse, soresponse_validation_unavailablefollows the posture, andDEFAULT_POSTUREisproceed. Onintegrationthe same deny is honored, so this is a new break. The schemas load from a path relative to the source file (validate-response.ts:14), so a missing or broken schema file is enough to trigger it. I movedspecification/v0.1.0/aside and ran:bun test hosts/claude-code/test/wire-shape.test.ts -t "renders a deny with the policy"Output:
- "permissionDecision": "deny", + "permissionDecision": "allow", + "permissionDecisionReason": "this host could not validate the response for steps/toolCallRequest (response_validation_unavailable: ...); the session's negotiated posture applies -- on_decision_failure=proceed, so this step was proceeded.",Fix: change line 334 to
const failClosed = refused || invalidResponse || validationUnavailable;. Then update the tests that expect the posture for this kind, and the README row and file header that say the posture applies to it. This also matches D-036, which makes deny the default posture.
What I ran, on integration with this pull request merged in, from reference-implementations/agt, on Bun 1.4.4:
bun run typecheck. It exits 0.bun test. Result: 1352 passed, 1 skipped, 0 failed.- The test above, with
specification/v0.1.0/moved aside.
What I did not check: Windows, the OpenCode host, and response signatures (#229).
Three follow-ups. They can go in this pull request or a later one:
- A response with the wrong JSON-RPC
idor the wrongresult.request_idstill follows the posture, so it is allowed underproceed. This already happens onintegration. D-029 says a mismatched id blocks whatever the posture. The new test atpackages/host-adapter/test/client.test.ts:668expectsallow. Please classifyGuardianResponseMismatchErrorandGuardianResultCorrelationErrorasinvalid_response, and change that test to expectdeny. packages/guardian/src/audit-to-otlp.tshas no row forinvalid_responseorresponse_validation_unavailable, so both become classotheron the trace span. Please add a row for each.- Two comments are now out of date:
packages/host-adapter/src/failure-kinds.ts:53("Neither of these is reachable fromclassifyDeliveryFailure") and the comment aboveREFUSAL_RPC_CODESinfailure-posture.ts, which says an error object never fails closed.
When you push, the dco check will also run. It has not run on this commit yet.
Bar and Ariel (@bar-capsule, @afogel), one question for you. §6.4 in docs/spec/instrument/specification.md:223 says a malformed response follows on_decision_failure. This pull request denies a response that fails the schema, whatever the posture.
Jatin asked that it not merge before §6.4 is clarified, and D-040 does not name this case. Can you confirm that a response that fails response-envelope.json is denied whatever the posture, so this pull request can merge after the fix above?
Make response-validation unavailability fail closed so schema loading failures cannot turn a Guardian deny into allow. Preserve `response_validation_unavailable` as the machine-readable reason, and update the affected failure-posture and wire expectations, implementation header, and host-adapter documentation. Focused failure-posture and schema-present/missing wire checks passed. Valid full-repository typecheck and full-suite results for this candidate remain pending because the local dependency tree is incomplete. Signed-off-by: Jatin Mannepalli <mjatin2007@users.noreply.github.com>
|
@rocklambros, I pushed the update in |
rocklambros
left a comment
There was a problem hiding this comment.
Hi Jatin, thank you for the quick fix. I reviewed commit 00e8a78.
The blocker is fixed. With specification/v0.1.0/ moved aside, the deny test now gets deny. A second reviewer made the validator throw at load and in the middle of a check, and both gave deny, while timeouts and transport failures still follow the posture.
I reran the agt-go (macos-15) job, and it passes now. The agt failure is real, so a rerun will not fix it. One change is needed:
-
A test from #521, which merged into
integrationyesterday, fails with this pull request.reference-implementations/agt/hosts/claude-code/test/result-companions.test.ts:123has a stub Guardian that answersresult: decision, with notypeorrequest_id. Your validator now rejects that answer, so the test "the result gate leaves stderr alone when nothing is withheld > on an allow" fails (Expected: false,Received: true). I reproduced it three times onintegrationwith this pull request merged in.Fix:
-
git fetch upstream(upstreamis GenAI-Security-Project/agent-control-standard), thengit merge upstream/integration, so your branch has that file. -
In the
answering()helper, read the request id and send a valid result:const rpc = (await req.json()) as { id: string | number; method: string; params?: { request_id?: string } };
and
return Response.json({ jsonrpc: "2.0", id: rpc.id, result: { type: "final", acs_version: "0.1.0", request_id: rpc.params?.request_id, ...decision } });
-
git push.
I tried this change: the file gives 7 passed, 0 failed, and the full suite gives 1386 passed, 0 failed.
-
What I ran, on integration with this pull request merged in, from reference-implementations/agt, on Bun 1.4.4:
bun run typecheck. It exits 0.bun test. Result: 1385 passed, 1 skipped, 1 failed (the test above).bun test hosts/claude-code/test/wire-shape.test.ts -t "renders a deny with the policy"withspecification/v0.1.0/moved aside. Result: 1 passed.
What I did not check: Windows, the OpenCode host, and response signatures (#229).
Three follow-ups. They can go in this pull request or a later one:
- The three follow-ups from my last review are still open: a wrong
idorrequest_idfollows the posture,audit-to-otlp.tshas no row for the two new kinds, and the comment atfailure-kinds.ts:53still says "Neither of these". - The
validationUnavailable ?branch atfailure-posture.ts:467can no longer run, because that kind always returns earlier. Please remove it. - The expected reason at
hosts/claude-code/test/wire-shape.test.ts:195changes withexistsSync(SCHEMA_ROOT), so the deny test also passes when the schemas are missing. Please assert only the policy deny there.
Bar and Ariel have not answered the §6.4 question yet. When they do, and the test above is fixed, this pull request can merge.
Signed-off-by: Jatin Mannepalli <mjatin2007@users.noreply.github.com>
Update the result-companion test helper to emit the required final-result discriminator, ACS version, and request correlation so the test exercises the intended allow path under the hardened response validator. Signed-off-by: Jatin Mannepalli <mjatin2007@users.noreply.github.com>
|
Thanks so much, @rocklambros. Done! |
rocklambros
left a comment
There was a problem hiding this comment.
Jatin, thank you. The stub fix in 2733cd3 works. I merged this PR into the current integration branch and ran bun test in reference-implementations/agt: 1387 tests, 0 failures. That blocker is closed.
One blocker is left. I missed it in my last review, and I am sorry for the extra round.
Blocker
-
A Guardian answer for another request is allowed under the
proceedposture.The test at
reference-implementations/agt/packages/host-adapter/test/client.test.ts:628("answers 'no decision' for another request's decision, however well-formed it is") adds the posture check at lines 668-673. It sends anallowwhoserequest_idnames another request, and then it expects the step to be allowed:expect(decision.decision).toBe("allow"); expect(events[0]).toMatchObject({ posture: "proceed", outcome: "proceeded", failure: { kind: "unknown" } });I ran it from
reference-implementations/agt:bun test packages/host-adapter/test/client.test.ts -t "another request's decision" 1 pass, 0 failD-040 in
docs/decisions/index.mdsays a mismatched id blocks the step whatever the posture. Your README row in this PR also says a response the validator rejects is a deny. A mismatchedrequest_idis the same kind of failure, so it must not followproceed.The fix:
- In
reference-implementations/agt/packages/host-adapter/src/failure-posture.ts:199, addGuardianResponseMismatchErrorandGuardianResultCorrelationErrorto the check that returnskind: "invalid_response". Both classes are exported fromguardian-client.ts(lines 89 and 104). - In the test at
client.test.ts:628, expectdecision.decisionto be"deny"and the audit event to showfailure: { kind: "invalid_response" }. - Run
bun testinreference-implementations/agtagain.
- In
Follow-ups (not blocking)
- The three deny tests in
hosts/claude-code/test/result-companions.test.ts(lines 157, 169 and 178) also pass when the host blocks an invalid response. Please also check the reason ("no"), so they fail if the stub breaks again. packages/guardian/src/audit-to-otlp.ts:82has no row forinvalid_responseorresponse_validation_unavailable, so both come out of the OTLP converter asother.- The
validationUnavailable ? ...branch atpackages/host-adapter/src/failure-posture.ts:467can never run, because theif (failClosed)block above it returns first.
Bar Kaduri and Ariel Fogel have not answered the §6.4 question yet. After the blocker is fixed and they answer, this PR can merge.
|
@rocklambros @mjatin2007 yes, confirmed: a response that fails |
Signed-off-by: Jatin Mannepalli <mjatin2007@users.noreply.github.com>
Classify JSON-RPC response-id and result.request_id correlation failures as invalid responses so they fail closed under every decision-failure posture. Update the focused regressions to assert deny, invalid_response audit classification, and the existing machine-readable reason for both mismatch paths. Signed-off-by: Jatin Mannepalli <mjatin2007@users.noreply.github.com>
|
No worries, and done! I updated the Guardian response handling so mismatched JSON-RPC response IDs and |
rocklambros
left a comment
There was a problem hiding this comment.
Jatin, thank you for the quick fix. The blocker from my last review is fixed. A reply whose id or result.request_id does not match is now invalid_response, and it is denied under both postures.
Commit reviewed: af3ea77
One new blocker, and it comes from the fix I asked for. I am sorry for that.
Blocker 1. An HTTP error with no JSON-RPC body now blocks the step under proceed.
post() in packages/host-adapter/src/guardian-client.ts:222 reads the body without checking the HTTP status. When a gateway or load balancer in front of the Guardian answers with its own JSON error, such as HTTP 503 with {"message": "upstream unavailable"}, the body has no id. Line 248 then throws GuardianResponseMismatchError, and failure-posture.ts:204 now files that as invalid_response, so the step is denied.
D-040 says this case follows the posture: "an HTTP 408, 429 or 5xx arrives with no JSON-RPC body". Bar's #603 keeps that wording in §6.4 and in D-040.
I checked it with a mock server under on_decision_failure: "proceed", using the setup from your test at test/client.test.ts:659:
PROBE 503 gateway json -> deny ["invalid_response"]
PROBE 502 html-free json -> deny ["invalid_response"]
The expected result is allow under proceed, and deny under deny.
Fix:
- In
post(), afterfetchand before theidcheck, decide whether the body is a JSON-RPC response. It is one only when it is an object withjsonrpc: "2.0"and anidkey. - When the HTTP status is
408,429or5xxand the body is not a JSON-RPC response, throw a delivery error that follows the posture, the same way a transport failure does. - When the status is any other
4xxand the body is not a JSON-RPC response, the step is refused whatever the posture, as D-040 says. - Keep
invalid_responsefor a body that is a JSON-RPC response but fails theidcheck, theresult.request_idcheck, orresponse-envelope.json. - Add tests for 503 and 429 with a non-JSON-RPC body under
proceed(allow) and underdeny(deny), and for 403 underproceed(deny).
Follow-ups. They are not blockers, and you can do them in this pull request or later:
packages/guardian/src/audit-to-otlp.ts:82:FAILURE_CLASS_BY_KINDhas no row forinvalid_responseorresponse_validation_unavailable, so these blocked steps export as classother. Map them, and extend the table test attest/audit-to-otlp.test.ts:177.- A body of JSON
nullthrows aTypeErroratguardian-client.ts:244, andfailure-posture.ts:225files everyTypeErrorastransport, so it follows the posture. The step 1 check above will catch it if you treat a non-object body as "not a JSON-RPC response". hosts/claude-code/test/wire-shape.test.ts:291accepts two outputs, the policy reason or the validator-unavailable text. A broken schema path then still passes. Pin the policy reason only.
Checks run: bun install --frozen-lockfile and bun test in reference-implementations/agt (1386 pass, 0 fail, 1 skip. One earlier run had 1 failure that did not come back in four reruns.), a probe of 12 malformed replies under both postures (all denied as invalid_response), the mock server probe above, and git merge-tree against integration (clean). Not checked: Windows, and the other adapters.
|
Thanks, @rocklambros. Two quick clarifications before I update this. PR #603's current description reads to me as treating any 4xx other than 408 (429 included) as a refusal that blocks under every posture, while your review asks for a 429 with no JSON-RPC body to follow posture. Which should #249 implement? And if a 429 does carry a valid, correlated JSON-RPC allow response, does that response take precedence, or does the HTTP status still block? |
|
Jatin, good questions, and the first one is my mistake. My review said a
Here are the fix steps from my review again, changed to match D-056:
The blocker itself has not changed: a gateway |
Bring the current integration branch into PR GenAI-Security-Project#249 before applying the D-056 HTTP response-precedence correction. Signed-off-by: Jatin Mannepalli <mjatin2007@users.noreply.github.com>
Make HTTP 429 and final non-2xx statuses outside 408 and 5xx refuse regardless of body. For 408 and 5xx, send only JSON-RPC 2.0 response candidates through existing correlation and envelope validation. Other 408 and 5xx bodies follow the configured failure posture. Disable automatic redirects, document the failure classification, and add focused status/body regressions. Signed-off-by: Jatin Mannepalli <mjatin2007@users.noreply.github.com>
Add the required result type and ACS version to the cross-process retry-pairing fixture so it reaches the request-pairing assertion under response-envelope validation. Signed-off-by: Jatin Mannepalli <mjatin2007@users.noreply.github.com>
|
Thanks for the clarification, @rocklambros. D-056 is now applied in |
What changed
Validates parsed, correlated Guardian decision responses against the canonical
response-envelope.jsonschema and its method-specificAcsResultbranch before the host adapter accepts them. A canonical-schema or method-result violation is audited and denied even underon_decision_failure: proceed; inability to run the local validator remains a host-side failure and follows the negotiated posture.This follows the accepted issue's fail-closed direction, but under
proceedit deliberately differs from the literal current §6.4 treatment of a malformed response. Validation covers the complete canonical response envelope, not onlydeny.reasoning. This draft should not be treated as conformant until §6.4 is clarified, and it should not merge ahead of that clarification unless maintainers direct otherwise. Response-signature verification is separate and remains pending in #229.Which issue does this implement
Part of #182
meaning, so it needs no issue
Base branch
integration, because this touches the specification, schemas, a referenceimplementation, an adapter, tests, or CI
main, because every changed path is on the documentation lane allowlist inCONTRIBUTING.md
Type of change
I tested this
uv run pytest -vpasses on my machineuv run mkdocs build --strictpasses on my machineThe AGT validation also passes on the repository's pinned Bun 1.3.11: TypeScript succeeds, and the complete Bun suite reports 1,123 passed, 1 skipped, 0 failed across 68 files.
Checklist
git commit -s(required by the DCO)Security
Security impact: schema-invalid or method-invalid Guardian responses are blocked and audited. Local validator unavailability remains posture-governed and is attributed to the host rather than the Guardian.