fix: prevent replay attacks in Django trust middleware #3782
All Vouch review confidence checks passed
Residual risk 0.19 = Change Risk (0.48) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.48 · 558 lines diff across 6 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.378
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #3782"
general
weight: 0.35
prayagupa
Related Issue
Fixes #3781
Problem & Solution
Problem:
AgentTrustMiddlewareverified Ed25519 signatures over only the agent DID. Because the signed value was static, a captured(X-Agent-DID, X-Agent-Signature)pair could be replayed indefinitely and reused across protected endpoints.Solution: This PR replaces bare-DID signatures with a versioned, canonical request envelope binding the signature to:
The middleware validates timestamp freshness and uses an atomic, shared Django cache to reject reused nonces. It fails closed when the replay cache is unavailable and rejects unsafe local-memory cache configuration unless explicitly enabled for development.
Legacy signatures over only the DID are intentionally rejected. The PR also exports a canonical payload helper so clients do not need to reproduce security-sensitive serialization logic.
Impact on Your Work
This closes a capture-replay authentication vulnerability in the Django AgentMesh integration. A captured static signature can no longer serve as an indefinite bearer credential or be reused unchanged against another method, path, query, body, content type, or service audience.
Deployments must configure a service-specific
AGENTMESH_AUDIENCEand a shared replay cache with atomicadd()semantics. Clients must send the new timestamp and nonce headers and sign the canonical request envelope.Timeline
As soon as practical due to the security impact and associated MSRC report.
Alternatives Considered
A minimal change signing
DID|timestampwas considered. It would limit replay duration but would still permit replay during the timestamp window and would not prevent cross-endpoint, cross-method, or body-substitution attacks.A timestamp-only approach was rejected in favor of a one-time nonce, shared replay state, service audience, and complete request binding.
An in-process nonce cache was also considered but rejected for production use because it cannot prevent replay across Django workers or application replicas.
Type of Change
Package(s) Affected
Core & runtime:
Governance & security:
Platform & tooling:
CLI plugins:
Shared / other:
Testing
The focused Django middleware test suite passes with 30 tests. Changed Python files also pass Ruff, editor diagnostics, and whitespace validation.
Unit Testing
Updated and added tests covering:
Manual Testing
Commands run:
```bash
python -m pytest agent-governance-python/agent-mesh/tests/test_django_middleware.py -q
python -m ruff check agent-governance-python/agent-mesh/tests/test_django_middleware.py
git diff --check