Skip to content

fix(security): bind agent request signatures to query and body (v2 challenge) - #897

Merged
fclairamb merged 4 commits into
mainfrom
fix/security-agent-sig-coverage
Nov 16, 2026
Merged

fclairamb merged 4 commits into
mainfrom
fix/security-agent-sig-coverage

Conversation

@fclairamb

Copy link
Copy Markdown
Owner

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|nonce only (agents.SignatureChallenge). It was designed for the WebSocket reconnect (no body, no query) but now also authenticates plain HTTP calls that carry both:

  • attachment uploads: POST /api/v1/agent/attachments?topic=<topic> with the capture blob (screenshot / path trace) — neither topic nor the blob was signed;
  • worker-task claim/step/finish/fail POSTs — the JSON bodies were not signed.

httpBaseURL explicitly supports ws:// → 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

  • New canonical message: 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). The v2| prefix makes the two formats unambiguous: a v1 signature can never verify as v2 or the reverse (no downgrade).
  • New header 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).
  • Legacy v1 still accepted when the header is absent, with a deprecation warning per request (the ServiceTokenBypass pattern), so the rollout is a fleet migration, not a lockstep restart. Unknown versions are refused.
  • The v2 body read in agentauth is capped at 4 MiB (mirrors attachments.MaxAttachmentBytes) and happens before verification — no uncapped pre-auth buffering (the finding-3 class of bug, not reintroduced here).
  • Docs updated: 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.
  • New 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).
  • Agent-side ws_capture_test.go / ws_trace_test.go now verify the upload signature against the v2 challenge over query + body.

go test green on agents, agentauth, agentws, agenttasks, attachments, checkworker/backend; golangci-lint 0 issues on all touched packages; go build ./... OK.

Refs #892

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

codecov Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.54839% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.74%. Comparing base (c4da4c5) to head (f8e70b7).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
server/internal/agents/crypto.go 86.66% 2 Missing ⚠️
server/internal/handlers/agentauth/agentauth.go 92.30% 2 Missing ⚠️
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           
Files with missing lines Coverage Δ
server/internal/checkworker/backend/ws.go 83.16% <100.00%> (+1.06%) ⬆️
server/internal/checkworker/backend/ws_capture.go 88.70% <100.00%> (+7.04%) ⬆️
server/internal/checkworker/backend/ws_tasks.go 80.82% <100.00%> (+0.26%) ⬆️
server/internal/handlers/agentws/handler.go 84.39% <100.00%> (+0.28%) ⬆️
server/internal/agents/crypto.go 83.33% <86.66%> (+0.57%) ⬆️
server/internal/handlers/agentauth/agentauth.go 95.74% <92.30%> (-4.26%) ⬇️

... and 13 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@fclairamb
fclairamb merged commit b63218c into main Nov 16, 2026
38 checks passed
@fclairamb
fclairamb deleted the fix/security-agent-sig-coverage branch November 16, 2026 01:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant