Repository navigation
Treat a Guardian reply whose signature check throws as a bad signature - #757
Merged
Merged
Conversation
Signed-off-by: Jason Crittenden <jrcrittenden@gmail.com>
- Reject non-finite timestamp drift so a leap-second timestamp (23:59:60, which date-time accepts and Date.parse returns NaN for) no longer passes the §10.3 skew window or lands in the replay store with a NaN expiry. - Commit each ContextEntry to its request content via request_hash, the lowercase-hex SHA-256 of the JCS-canonicalized params (context-entry.json, RECOMMENDED). - README: mark the handshake as not yet enforced (-32003) and the hook set as partial (subagentStart and agentTrigger return -32011). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Jason Crittenden <jrcrittenden@gmail.com>
- Guardian: record each session's ClientHello methods_implemented and refuse with -32003 CAPABILITY_NOT_NEGOTIATED any step from a session that never sent handshake/hello, or for a method it did not declare (§4, §17.1). system/ping stays exempt. The check runs before the replay store remembers the request_id, so a retry after re-handshaking is not a false replay. The record is bounded (LRU, 4096 sessions). - Hosts: on -32003, governStep repeats the handshake once and retries with a fresh request, so a Guardian restart does not deny every step until the session ends. Only a decision replaces the refusal; a failed re-handshake or an undelivered retry keeps the -32003. - Conformance probes and tests now handshake before posting steps. - README: handshake row is implemented; replay protection names the remaining gap that the in-memory store does not survive a restart. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Jason Crittenden <jrcrittenden@gmail.com>
A full replay-protection cache answered a brand-new request with -32005 REPLAY_DETECTED. §17.1 recovers from -32005 by regenerating request_id, which cannot succeed while the cache is full. Return -32000 SESSION_REFUSED with data.reason "replay_protection_capacity" instead: it is in the §17.1 registry, so every ACS client fails closed on it. startGuardian takes an optional replayProtectionStore so a server test can fill the cache. Reported by @shivang-sec on #229. Signed-off-by: Jason Crittenden <jrcrittenden@gmail.com>
The HMAC signing block in handleAcsRequest ran outside any try, on unauthenticated input. A session_id over 1024 bytes makes HKDF throw, and a deeply nested body overflows the stack in JCS canonicalization. Either escaped handleAcsRequest as an HTML 500, which a host reads as a hook that never fired. The block is now wrapped. A request that throws there cannot carry a valid signature, so its response goes out unsigned, like any other unauthenticated request's, and the failure is reported on stderr. The envelope log records the same response it did before, minus the signature it could never have had. Every AcsResult now carries metadata.evaluator "deterministic", so the trace exporter in #244 reads the evaluator from the wire instead of assuming it. Both raised by @rocklambros on #229. Signed-off-by: Jason Crittenden <jrcrittenden@gmail.com>
Request-signature verification canonicalises the unauthenticated body before computing the HMAC. A signed body nested past the stack made that throw, and the throw fell through dispatch to the outer net, which answers -32020. That code is outside the section 17.1 registry, so a client branching on registered codes could fail open on it. verifyHmacSha256 now treats an input it cannot canonicalise as an invalid signature, so the request gets -32004 SIGNATURE_INVALID like any other unauthenticated one. The signing-boundary test now asserts the answer for each of its two inputs. Raised by @astrogilda on #229. Signed-off-by: Jason Crittenden <jrcrittenden@gmail.com>
With HMAC on, two host paths turned a deny into an allow. The client threw on any unverifiable response before reading its code, so a refusal the Guardian cannot sign (oversize body, -32700, a bad request signature) became an "unknown" failure and the proceed posture ran the step. A refusal-coded error with no result is now passed through unverified: it can only fail the step closed. The refusal codes move to failure-kinds.ts so the client can read them without an import cycle. A request too deep to canonicalise threw inside request building and the posture answered it. Signing is now its own "sign" stage whose failure, kind "unsignable", blocks regardless of posture. Signed-off-by: Jason Crittenden <jrcrittenden@gmail.com>
A protocols/MCP/tools/call payload carrying both tool/arguments and
params was evaluated on the former while a forwarding server runs the
latter. Both shapes together are now refused as envelope_invalid, and
{value} is unwrapped only in the ACS shape.
The stock rules skip a policy target that is not a string, so an object
or array command was allowed on any tool-call path. The snapshot
assembler now throws on one, which denies with evaluation_failed.
Signed-off-by: Jason Crittenden <jrcrittenden@gmail.com>
The host listed the refusal codes it knew, so a code added later, such as the retryable overload code Discussion #257 proposes, was classified error_without_decision and the proceed posture ran the step. The host now treats -32700 and the whole -32000..-32099 range as a refusal, both when it accepts an unsigned refusal and when it classifies one. Codes outside the range, like -32601 or -32603, still keep the posture. Signed-off-by: Jason Crittenden <jrcrittenden@gmail.com>
…he MCP method handshake/hello, which #229's Guardian refuses with -32003. postRaw and the generator now send one first; the hello gets no span. protocols/MCP/tools/call is evaluated but otel-mapping.json maps only steps/* and agbom/* methods, so it is named in METHODS_WITHOUT_SPAN with that reason until the spec gives it a step_to_span entry. The decision event now carries acs.evaluator, and the response carries a chain_hash that covers each entry's recorded time. The two tests that compare a Guardian with export on and off give both the same clock, and the sample comparison sets the hash's value aside with the timestamps. The committed sample is regenerated. Signed-off-by: Jason Crittenden <jrcrittenden@gmail.com>
…example The sample trace was regenerated under #229's Guardian, whose decision event now carries acs.evaluator and acs.chain_hash. The example on the page is checked against the sample, so it is copied again, and the sentence that lists the event's contents names both. Signed-off-by: Jason Crittenden <jrcrittenden@gmail.com>
PR #272 defines key_id for HMAC as an opaque label from the deployment's configuration that names one secret. This tree used the session_id as key_id and rejected any other value. The Guardian now requires ACS_HMAC_KEY_ID beside ACS_HMAC_SECRET, with no default, and verifies a request with the secret its key_id names. An unknown label is SIGNATURE_INVALID, unsigned, and is never tried against another secret. A response is signed with the secret, and names the key_id, of the request it answers. Both hosts read the same pair, sign with the configured label, and reject a response that names another. Setting only one of the two is a configuration error. The OpenCode plugin raises it from each hook rather than from its factory, because a factory throw unloads the plugin and leaves every tool ungoverned. Signed-off-by: Jason Crittenden <jrcrittenden@gmail.com>
…hello from failing open Three places where the keyed host still failed open under `proceed`, from the 10-29 review: - A reply whose signature fails verification, or that answers another request (its JSON-RPC id or result.request_id does not match), is now its own failure kind, signature_invalid. It blocks the step whatever the posture, as issue #308 rules, and becomes an acs.decision.failure with class signature_invalid. A stripped signature, a wrong key and a replayed earlier allow each end in deny. - The one retry after REPLAY_DETECTED replaces the refusal only when a decision arrives, as the -32003 retry already does. A retry that times out leaves the refusal standing. - A verified ServerHello that this signed host rejects for lacking acs-core or HMAC-SHA256 keeps the posture it declared. A hello that fails verification carries no posture this host can trust, so every failure in that session blocks instead of falling to the ACS default. The Guardian README says why -32003 and the -32000 capacity refusal are recorded under the request's ids: both come after the signature. The tree README now carries the three lines asked for on 10-13: the agent's shell can read the secret with printenv, neither host sends the rest of the minimum hook set, and the section 10.3 nonce is not checked. Signed-off-by: Jason Crittenden <jrcrittenden@gmail.com>
PR #334 makes the Guardian answer -32600 Invalid Request for a JSON-RPC frame it cannot read. That code sat outside the refusal range, so the host applied its posture, and under `proceed` the step ran: on a keyless host, `rm -rf /` came back allow. isRefusalCode now counts -32600 with -32700 and the -32000..-32099 range, so the step blocks. Signed-off-by: Jason Crittenden <jrcrittenden@gmail.com>
…32603 A host that holds an HMAC key and gets a JSON-RPC error for its handshake/hello has no verified ServerHello and so no posture. Its session is now untrusted: every failure in it blocks, rather than falling back to the default proceed. A wrong key against a Guardian that declares deny used to allow a step the Guardian did not answer. D-040: every JSON-RPC error is a refusal except a signed -32603. The client passes an unsigned error of any code through as a refusal and throws GuardianInternalError for a -32603 whose signature verified, which is the one error that follows the posture. -32601 and -32602 no longer run the step under proceed. isRefusalCode is gone: no code decides it. Signed-off-by: Jason Crittenden <jrcrittenden@gmail.com>
The TypeScript Guardian now refuses to start without an HMAC key and refuses an unsigned step or one outside a handshaken session, so record-ts-cases.sh could not record. The script makes a key for the run, and the recorder sends each case as an Observed Agent does: a hello, then signed steps, with every answer's signature verified. Re-recorded at this tree. Every decision now carries metadata.evaluator. command_not_a_string and fetch_url_not_a_string are denied, so aheadOfTypeScript is empty and removed. An unregistered tool is denied with tool_unregistered, where the Go Guardian still answers AGT's runtime_error:tool_unknown: behindTypeScript names those two cases and docs/differences.md records it. Signed-off-by: Jason Crittenden <jrcrittenden@gmail.com>
The host checks the signature on a Guardian reply, and that reply is peer
input. The check could throw instead of returning invalid: String() on a
signature algorithm of {toString: 0}, a result nested too deep to
canonicalise, or a body of JSON null. The throw was filed as a transport
failure, so the posture answered and, under proceed, the step ran. On the
hello it left the session trusted.
post() now turns any throw from the check into GuardianSignatureError, and
the algorithm in the reason is named without calling String() on it. Two
posture tests cover the step reply and the hello, and both fail on the
old code.
Signed-off-by: Rock Lambros <rock@rockcyber.com>
rocklambros
requested review from
GangGreenTemperTatum,
Lrd0036,
afogel,
artmaro,
bar-capsule,
e2hln,
fewdisc,
mamicidal and
sclintonowasp
as code owners
December 2, 2026 22:36
The earlier tests reached the old String() throw, which the same commit removed, so they never exercised the new catch. New posture tests send a reply body of JSON null to the step and the hello, a step reply nested too deep to canonicalise, and unsigned errors whose message or id is nested too deep to print. Each one blocks now and followed the posture before. printable no longer throws on a value nested too deep, and the two correlation errors build their messages with it. The signature reason names only the type of the peer's algorithm value, so its text never reaches the audit entry or the agent's deny reason. Signed-off-by: Rock Lambros <rock@rockcyber.com>
11 of 18 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed
The host checks the signature on every Guardian reply, and that reply comes from the network, so it can hold any value. The check could throw an error instead of returning "invalid". Three inputs did it: a signature algorithm of
{"toString":0}, a result nested too deep to canonicalise, and a reply body of JSONnull. The host filed that throw as a transport failure. So the failure posture decided the step, and underproceedthe step ran. On thehandshake/helloreply, the throw also left the session marked as trusted.This PR changes four things:
post()inpackages/host-adapter/src/guardian-client.tsnow turns any throw from the signature check intoGuardianSignatureError. A reply that can't be verified is now a bad signature, and a bad signature always blocks the step.printablein the same file no longer throws on a value nested too deep, and the two correlation errors now build their messages with it. Before this, an unsigned error whosemessageoridwas nested very deep made the error printer throw, so the step followed the posture. D-040 says every unsigned error blocks the step.verifyResponseSignatureinpackages/host-adapter/src/sign-envelope.tsno longer callsString()on the algorithm value from the reply, becauseString()itself can throw.Six new tests in
hosts/claude-code/test/posture.test.tscover a non-string algorithm, a JSONnullbody, a reply nested too deep to canonicalise, and unsigned errors nested too deep to print, on the step reply and on the hello reply. All six fail on the code from PR #229. The AGT suite passes (1512 pass, 1 skip, 0 fail), andbun run typecheckis clean.This PR is built on PR #229 (ACS-Core wire safeguards), because the code it fixes comes from PR #229. It will merge in the same batch as PR #229.
Which issue does this implement
Refs #184
Base branch
integration, because this touches the specification, schemas, a reference implementation, an adapter, tests, or CIType of change