Repository navigation
fix(security): bind agent request signatures to query and body (v2 challenge) - #897
Merged
Merged
Conversation
The agent Ed25519 challenge signed method|path|timestamp|nonce only — neither the query string nor the body. Attachment uploads (?topic= + capture blob) and worker-task calls (claim/step/finish/fail JSON) were authenticated but not integrity-protected, and plain HTTP is a supported agent transport: an on-path attacker could rewrite monitoring evidence or task results inside a validly signed, nonce-fresh request. Add a v2 challenge: v2|method|requestURI|timestamp|nonce|sha256(body), advertised via X-Sp-Signature-Version: 2. Both server verification paths (agent HTTP calls, WS reconnect) accept v2 and still verify legacy v1 with a deprecation warning until the fleet migrates; unknown versions are refused and a v2 signature cannot be downgraded to the v1 verifier. The v2 body read in agentauth is capped (4 MiB) before verification. Refs #892 (finding 2)
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #897 +/- ##
=======================================
Coverage 90.73% 90.74%
=======================================
Files 1370 1370
Lines 140857 140908 +51
=======================================
+ Hits 127801 127860 +59
+ Misses 13047 13039 -8
Partials 9 9
🚀 New features to boost your workflow:
|
fclairamb
enabled auto-merge (squash)
November 16, 2026 00:15
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
Fixes finding 2 of the security review #892 (agent HTTP request signatures cover neither the body nor the query string).
The agent's Ed25519 scheme signed
method|path|timestamp|nonceonly (agents.SignatureChallenge). It was designed for the WebSocket reconnect (no body, no query) but now also authenticates plain HTTP calls that carry both:POST /api/v1/agent/attachments?topic=<topic>with the capture blob (screenshot / path trace) — neithertopicnor the blob was signed;claim/step/finish/failPOSTs — the JSON bodies were not signed.httpBaseURLexplicitly supportsws://→http://, i.e. plain HTTP is a supported agent configuration. An on-path attacker there could rewrite the topic or swap the body of a validly signed, nonce-fresh request: the nonce guard stops replay but not in-flight tampering. Impact: integrity of monitoring evidence and worker-task results.Fix — a versioned v2 challenge, mirroring the servicesig migration pattern
v2|method|requestURI|timestamp|nonce|hex(sha256(body))— full request URI (path and query) plus the exact body bytes (empty-slice hash for bodyless calls). Thev2|prefix makes the two formats unambiguous: a v1 signature can never verify as v2 or the reverse (no downgrade).X-Sp-Signature-Version: 2(agents.HeaderSignatureVersion), set by the agent on all three signing sites (WS reconnect, attachment upload, worker-task calls) and dispatched on by both server verification paths (agentauth.Authenticate,agentws.serveReconnect).ServiceTokenBypasspattern), so the rollout is a fleet migration, not a lockstep restart. Unknown versions are refused.agentauthis capped at 4 MiB (mirrorsattachments.MaxAttachmentBytes) and happens before verification — no uncapped pre-auth buffering (the finding-3 class of bug, not reintroduced here).wiki/features/deported-agents.md,web/docs/docs/features/private-locations.md. Historical specs left untouched.Rollout note
Servers must upgrade before agents: a new agent talking to an old server would fail verification (the old server ignores the version header and checks the v1 challenge). Old agents keep working against new servers via the legacy path. Removing v1 acceptance is a one-line follow-up once the fleet has migrated (watch the deprecation warnings go quiet).
Tests
agents/crypto_test.go: v2 round-trip (with body + bodyless); tamper matrix (rewritten body, rewritten query, dropped query, path, nonce, method, key all refused); cross-version rejection both directions.agentauth/agentauth_test.go(the package had no tests): v2 happy path with body restored byte-for-byte; tampered body refused; query rewritten in transit refused; oversized body refused; legacy v1 accepted; unknown version refused; v2-without-header downgrade refused; replayed nonce refused; revoked agent refused.agentws/handler_test.go: v2 reconnect works; downgrade and unknown version → 401. Existing v1 reconnect test stays green (legacy path).ws_capture_test.go/ws_trace_test.gonow verify the upload signature against the v2 challenge over query + body.go testgreen onagents,agentauth,agentws,agenttasks,attachments,checkworker/backend;golangci-lint0 issues on all touched packages;go build ./...OK.Refs #892