← Back to Pull requests

fix: prevent replay attacks in Django trust middleware #3782

Closed
unknown closed this pull request without merging on Aug 19, 2026 21:25 UTC
View on GitHub
unknown unknown commented on Aug 18, 2026 20:29 UTC
Author

Related Issue


Fixes #3781

Problem & Solution

Problem: AgentTrustMiddleware verified 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:

  • Agent DID

  • Service audience

  • ISO-8601 timestamp

  • Cryptographically random nonce

  • HTTP method

  • Request path and query string

  • Content type

  • SHA-256 request-body digest
  • 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_AUDIENCE and a shared replay cache with atomic add() 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|timestamp was 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


  • Bug fix (non-breaking change that fixes an issue)

  • New feature (non-breaking change that adds functionality)

  • Breaking change (fix or feature that would cause existing functionality to change)

  • Documentation update

  • Maintenance (dependency updates, CI/CD, refactoring)

  • Security fix
  • Package(s) Affected

    Core & runtime:

  • agent-governance-toolkit-core

  • agent-primitives

  • agent-os

  • agent-mesh

  • agent-runtime

  • agent-sre

  • agent-compliance
  • Governance & security:

  • agent-mcp-governance

  • agent-rag-governance

  • agent-sandbox

  • agent-discovery

  • agt-policies

  • policy-engine
  • Platform & tooling:

  • agent-hypervisor

  • agent-lightning

  • agent-marketplace

  • agent-governance-toolkit-cli

  • agent-governance-toolkit-integrations

  • agent-governance-toolkit-protocols

  • agentmesh-integrations (framework integrations)
  • CLI plugins:

  • agent-governance CLI plugins (copilot-cli / claude-code / opencode / antigravity-cli)
  • Shared / other:

  • schemas

  • action (GitHub Action)

  • examples

  • docs / root
  • 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:

  • Valid request-bound Ed25519 signatures

  • Immediate nonce replay rejection

  • Stale and excessively future-dated timestamps

  • Missing, malformed, undersized, and oversized nonces

  • Rejection of legacy bare-DID signatures

  • Method, path, query-string, body, and audience binding

  • Replay-cache failure with fail-closed behavior

  • Rejection of unsafe local-memory caches without development opt-in

  • Missing audience and invalid replay-window startup configuration

  • Existing per-view trust thresholds and exemption behavior
  • 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

    Diff: 558 lines (+418 / -140) across 6 files Reviewer: prayagupa Review duration: 1495m
    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
    0.48
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 48.2% (MEDIUM) · Higher = larger blast radius
    48.2%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 19% · Safe to merge
    19%