Skip to content

Treat a Guardian reply whose signature check throws as a bad signature - #757

Merged
rocklambros merged 18 commits into
integrationfrom
fix/verify-throw-signature-error
Dec 3, 2026
Merged

rocklambros merged 18 commits into
integrationfrom
fix/verify-throw-signature-error

Conversation

@rocklambros

@rocklambros rocklambros commented Dec 2, 2026 •

Copy link
Copy Markdown
Collaborator

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 JSON null. The host filed that throw as a transport failure. So the failure posture decided the step, and under proceed the step ran. On the handshake/hello reply, the throw also left the session marked as trusted.

This PR changes four things:

  1. post() in packages/host-adapter/src/guardian-client.ts now turns any throw from the signature check into GuardianSignatureError. A reply that can't be verified is now a bad signature, and a bad signature always blocks the step.
  2. printable in 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 whose message or id was nested very deep made the error printer throw, so the step followed the posture. D-040 says every unsigned error blocks the step.
  3. verifyResponseSignature in packages/host-adapter/src/sign-envelope.ts no longer calls String() on the algorithm value from the reply, because String() itself can throw.
  4. The signature reason now names only the type of that algorithm value, so text from the reply never reaches the audit entry or the deny reason the agent sees.

Six new tests in hosts/claude-code/test/posture.test.ts cover a non-string algorithm, a JSON null body, 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), and bun run typecheck is 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 CI

Type of change

  • Reference implementation or adapter

jrcrittenden and others added 17 commits December 2, 2026 02:04
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>
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>
@rocklambros rocklambros mentioned this pull request Dec 3, 2026
11 of 18 tasks
@rocklambros
rocklambros merged commit 6080299 into integration Dec 3, 2026
30 checks passed
@github-project-automation github-project-automation Bot moved this from Needs triage to Done in ACS Project Tracker Dec 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants