This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
securitycritical PriorityID: rfc-9449-dpop-replay-window-bound-guardrail

RFC 9449 DPoP Ephemeral Proof Replay Window & Distributed Nonce Bound

Enforces strict RFC 9449 Demonstrating Proof-of-Possession (DPoP) verification standards across distributed microservices. Mandates sub-second clock drift validation, cryptographically bound HTTP request context (htm, htu, ath), and distributed atomic single-use nonce/jti verification via storage-layer race-condition-safe primitives to guarantee zero-replay tolerance of ephemeral proof tokens.

Prohibited Anti-Pattern: Accepting DPoP Proofs with Wide Clock Skew, Process-Local Nonce Validation, or Unchecked JTI Uniqueness

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: RFC 9449 DPoP Ephemeral Proof Replay Window & Distributed Nonce Bound - Enforces strict RFC 9449 Demonstrating Proof-of-Possession (DPoP) verification standards across distributed microservices. Mandates sub-second clock drift validation, cryptographically bound HTTP request context (htm, htu, ath), and distributed atomic single-use nonce/jti verification via storage-layer race-condition-safe primitives to guarantee zero-replay tolerance of ephemeral proof tokens.
globs: src/**/auth/**/*.{ts,js}, src/**/middleware/**/*.{ts,js}, src/**/security/**/*.{ts,js}, src/**/gateway/**/*.{ts,js}
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/rfc-9449-dpop-replay-window-bound-guardrail"
---

# RFC 9449 DPoP Ephemeral Proof Replay Window & Distributed Nonce Bound

> **Severity**: CRITICAL | **Category**: security
> **Anti-Pattern Warning**: Accepting DPoP Proofs with Wide Clock Skew, Process-Local Nonce Validation, or Unchecked JTI Uniqueness

## System Constraints
You are a Principal Security Architect enforcing RFC 9449 OAuth 2.0 Demonstrating Proof-of-Possession (DPoP) at the API Gateway and service boundaries. You must reject any DPoP proof handling implementation that permits loose clock drift windows, in-memory jti caching in distributed environments, omission of access token hash (ath) verification, or malleable HTTP URI/method parsing.

## Strict Guidelines
- Engineers MUST ALWAYS validate the DPoP JWT header for exact typ matching 'dpop+jwt' and reject standard 'JWT' or mismatched header parameters.
- Services MUST verify the cryptographic signature of the DPoP proof against the embedded public JWK ('jwk' claim) and verify that the token was signed with an approved asymmetric algorithm (e.g., ES256, EdDSA).
- Engineers MUST bound proof creation time ('iat') within a strict time-skew window (maximum ±5 seconds from verification time) to prevent delayed reuse window exploitation.
- Services MUST atomically claim and mark the DPoP unique token identifier ('jti') as consumed in a distributed lock-free cache (e.g., Redis via atomic SET NX with TTL) matching the maximum allowable clock skew window.
- Engineers MUST strictly match the 'htm' (HTTP method) and 'htu' (HTTP target URI stripped of query and fragment) claims against the incoming normalized request.
- Engineers MUST calculate and compare the SHA-256 hash of the presented access token against the 'ath' claim when DPoP proofs are accompanied by a bearer-bound access token.
- Components NEVER store or check DPoP 'jti' uniqueness in process-local memory (e.g., native Maps or Sets) when deployed across multi-replica or serverless fleets.
- Services MUST issue a 'use_dpop_nonce' error and supply a cryptographically secure, server-generated 'DPoP-Nonce' header whenever rotating nonces are enforced.

## Bad vs Good Implementations
### Distributed Atomic DPoP Proof Verification with RFC 9449 Strict Invariants

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Uses process-local memory for replay tracking which fails across multi-node services. Permits an insecure 300-second time-skew window. Skips header typ enforcement, cryptographic JWK signature verification, and mandatory HTTP method/URI/ath matching.
```typescript
import { Request, Response, NextFunction } from 'express';
import jwt from 'jsonwebtoken';

const seenJtis = new Set<string>(); // Flaw: Process-local memory leak and replica desync

export async function badDpopMiddleware(req: Request, res: Response, next: NextFunction) {
  const dpopHeader = req.headers['dpop'] as string;
  if (!dpopHeader) return res.status(401).send('Missing DPoP header');

  // Flaw: Unverified decode before signature check, no typ validation
  const decoded = jwt.decode(dpopHeader) as any;
  
  // Flaw: 5-minute clock drift window allows massive replay attack vulnerability
  const now = Math.floor(Date.now() / 1000);
  if (Math.abs(now - decoded.iat) > 300) {
    return res.status(401).send('Expired proof');
  }

  // Flaw: Non-atomic race condition & local state fails in clustered deployment
  if (seenJtis.has(decoded.jti)) {
    return res.status(401).send('Replayed proof');
  }
  seenJtis.add(decoded.jti);

  // Flaw: Missing htm, htu, and ath verification against active request
  next();
}
```

#### Production Standard (Correct)
> **Standard**: Implements full RFC 9449 compliance: strictly validates the 'typ' header as 'dpop+jwt', verifies the asymmetric signature using the embedded JWK, tightly bounds clock drift to 5 seconds, guarantees atomic distributed replay protection via Redis SET NX, and verifies both 'htm'/'htu' exact match and 'ath' access token SHA-256 bindings.
```typescript
import { Request, Response, NextFunction } from 'express';
import crypto from 'crypto';
import { importJWK, jwtVerify } from 'jose';
import { Redis } from 'ioredis';

const redis = new Redis(process.env.REDIS_URL!);
const MAX_CLOCK_DRIFT_SEC = 5; // Strict RFC 9449 bounded window

export async function verifyDpopProof(req: Request, res: Response, next: NextFunction) {
  const dpopProof = req.headers['dpop'];
  if (typeof dpopProof !== 'string') {
    return res.status(401).json({ error: 'invalid_dpop_proof', error_description: 'Missing DPoP header' });
  }

  try {
    // 1. Decode header to extract ephemeral public key and enforce typ
    const [headerB64] = dpopProof.split('.');
    const header = JSON.parse(Buffer.from(headerB64, 'base64url').toString('utf8'));
    
    if (header.typ !== 'dpop+jwt') {
      return res.status(401).json({ error: 'invalid_dpop_proof', error_description: 'Invalid typ header' });
    }
    if (!header.jwk || header.jwk.kty !== 'EC' && header.jwk.kty !== 'OKP') {
      return res.status(401).json({ error: 'invalid_dpop_proof', error_description: 'Unsupported or missing JWK' });
    }

    const publicKey = await importJWK(header.jwk, header.alg);
    const { payload } = await jwtVerify(dpopProof, publicKey, {
      algorithms: ['ES256', 'EdDSA'],
      clockTolerance: `${MAX_CLOCK_DRIFT_SEC}s`
    });

    // 2. Strict HTTP context binding verification
    const expectedHtu = `${req.protocol}://${req.get('host')}${req.baseUrl}${req.path}`;
    if (payload.htm !== req.method.toUpperCase()) {
      return res.status(401).json({ error: 'invalid_dpop_proof', error_description: 'HTTP method mismatch' });
    }
    if (payload.htu !== expectedHtu) {
      return res.status(401).json({ error: 'invalid_dpop_proof', error_description: 'HTTP URI mismatch' });
    }

    // 3. Ath (Access Token Hash) validation when bearer token exists
    const authHeader = req.headers['authorization'];
    if (authHeader?.startsWith('DPoP ')) {
      const rawToken = authHeader.slice(5).trim();
      const expectedAth = crypto.createHash('sha256').update(rawToken).digest('base64url');
      if (payload.ath !== expectedAth) {
        return res.status(401).json({ error: 'invalid_dpop_proof', error_description: 'Access token hash mismatch' });
      }
    }

    // 4. Atomic distributed JTI consumption with exact drift window TTL
    const jtiKey = `dpop:jti:${payload.jti}`;
    const acquired = await redis.set(jtiKey, '1', 'EX', MAX_CLOCK_DRIFT_SEC * 2, 'NX');
    if (!acquired) {
      return res.status(401).json({ error: 'use_dpop_nonce', error_description: 'DPoP proof token replayed' });
    }

    res.locals.dpopJwkThumbprint = await import('jose').then(m => m.calculateJwkThumbprint(header.jwk));
    return next();
  } catch (err) {
    return res.status(401).json({ error: 'invalid_dpop_proof', error_description: 'DPoP verification failed' });
  }
}
```

Recommended MCP Servers (mcp-serverlist.com)

Equip agent with system tools to verify code for this stack.

Recommended Agent Skills (askills.dev)

Ready-to-use executable skill functions tailored to this stack.

Architectural Specification & Invariant Rationale

Architectural Invariant Design: RFC 9449 DPoP Ephemeral Proof Replay Window & Distributed Nonce Bound

RFC 9449 DPoP Ephemeral Proof Replay Window & Distributed Nonce Bound defines an industrial-grade behavioral standard for security engineering. Enforces strict RFC 9449 Demonstrating Proof-of-Possession (DPoP) verification standards across distributed microservices. Mandates sub-second clock drift validation, cryptographically bound HTTP request context (htm, htu, ath), and distributed atomic single-use nonce/jti verification via storage-layer race-condition-safe primitives to guarantee zero-replay tolerance of ephemeral proof tokens. Modern software architectures require strict adherence to deterministic patterns to guarantee high availability, maintainability, and zero security vulnerabilities.

Framework Paradigm Shift & Drift MechanicsLLMs are trained on millions of open-source repositories containing outdated code, legacy idioms, and unpatched antipatterns. When coding assistants generate implementations for this stack, they default to common statistical tokens: Accepting DPoP Proofs with Wide Clock Skew, Process-Local Nonce Validation, or Unchecked JTI Uniqueness Without an explicit system instruction file, developers spend hours debugging silent failures.
Failure Modes & Production Blast Radius

Hazard Analysis: What Breaks Without This Rule

The following failure modes have been cataloged from hundreds of hours of production code reviews where AI assistants produced non-compliant implementations:

Failure ModeAI Symptom (The Anti-Pattern)SeverityProduction Impact & Remedy
AI Hallucination & Deprecation DriftAccepting DPoP Proofs with Wide Clock Skew, Process-Local Nonce Validation, or Unchecked JTI UniquenessCritical
Violating this industrial standard introduces regression bugs, security risks, and unexpected runtime failures in production.
Enforce explicit behavioral system directives across all AI coding assistants in your repository.
Silent Architecture InconsistencyAI assistants produce mixed paradigms across files, creating fragmented codebase conventions.Medium
Increases cognitive load during code reviews and leads to maintenance debt across engineering teams.
Pin project conventions in .cursor/rules, CLAUDE.md, and AGENTS.md so all team agents follow identical guardrails.
Architectural Directives in Detail

Step-by-Step Production Directives

Each rule constraint below is injected into the AI agent's system prompt to establish deterministic boundaries:

1

Engineers MUST ALWAYS validate the DPoP JWT header for exact typ matching 'dpop+jwt' and reject standard 'JWT' or mismatched header parameters.

Engineers MUST ALWAYS validate the DPoP JWT header for exact typ matching 'dpop+jwt' and reject standard 'JWT' or mismatched header parameters.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
2

Services MUST verify the cryptographic signature of the DPoP proof against the embedded public JWK ('jwk' claim) and verify that the token was signed with an approved asymmetric algorithm (e.g., ES256, EdDSA).

Services MUST verify the cryptographic signature of the DPoP proof against the embedded public JWK ('jwk' claim) and verify that the token was signed with an approved asymmetric algorithm (e.g., ES256, EdDSA).

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
3

Engineers MUST bound proof creation time ('iat') within a strict time-skew window (maximum ±5 seconds from verification time) to prevent delayed reuse window exploitation.

Engineers MUST bound proof creation time ('iat') within a strict time-skew window (maximum ±5 seconds from verification time) to prevent delayed reuse window exploitation.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
4

Services MUST atomically claim and mark the DPoP unique token identifier ('jti') as consumed in a distributed lock-free cache (e.g., Redis via atomic SET NX with TTL) matching the maximum allowable clock skew window.

Services MUST atomically claim and mark the DPoP unique token identifier ('jti') as consumed in a distributed lock-free cache (e.g., Redis via atomic SET NX with TTL) matching the maximum allowable clock skew window.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
5

Engineers MUST strictly match the 'htm' (HTTP method) and 'htu' (HTTP target URI stripped of query and fragment) claims against the incoming normalized request.

Engineers MUST strictly match the 'htm' (HTTP method) and 'htu' (HTTP target URI stripped of query and fragment) claims against the incoming normalized request.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
6

Engineers MUST calculate and compare the SHA-256 hash of the presented access token against the 'ath' claim when DPoP proofs are accompanied by a bearer-bound access token.

Engineers MUST calculate and compare the SHA-256 hash of the presented access token against the 'ath' claim when DPoP proofs are accompanied by a bearer-bound access token.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
7

Components NEVER store or check DPoP 'jti' uniqueness in process-local memory (e.g., native Maps or Sets) when deployed across multi-replica or serverless fleets.

Components NEVER store or check DPoP 'jti' uniqueness in process-local memory (e.g., native Maps or Sets) when deployed across multi-replica or serverless fleets.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
8

Services MUST issue a 'use_dpop_nonce' error and supply a cryptographically secure, server-generated 'DPoP-Nonce' header whenever rotating nonces are enforced.

Services MUST issue a 'use_dpop_nonce' error and supply a cryptographically secure, server-generated 'DPoP-Nonce' header whenever rotating nonces are enforced.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
Technical Questions & Answers

Frequently Asked Technical Questions

Common questions developers face when configuring AI coding assistants for this stack:

Q:Why is RFC 9449 DPoP Ephemeral Proof Replay Window & Distributed Nonce Bound critical for AI coding assistants?

Enforces strict RFC 9449 Demonstrating Proof-of-Possession (DPoP) verification standards across distributed microservices. Mandates sub-second clock drift validation, cryptographically bound HTTP request context (htm, htu, ath), and distributed atomic single-use nonce/jti verification via storage-layer race-condition-safe primitives to guarantee zero-replay tolerance of ephemeral proof tokens. Without explicit behavioral boundaries, AI coding assistants (Cursor, Claude Code, Windsurf, Codex) rely on training data averages, which frequently produce deprecated, inefficient, or vulnerable code patterns.

Q:How does adopting this rule prevent AI hallucinations?

This rule explicitly declares what the AI must avoid (Accepting DPoP Proofs with Wide Clock Skew, Process-Local Nonce Validation, or Unchecked JTI Uniqueness) and prescribes verified positive examples. Grounding the LLM with negative and positive pairs eliminates guesswork.

Q:Which AI coding environments are supported?

This specification is multi-platform compatible: Cursor (.cursor/rules/*.mdc & .cursorrules), Anthropic Claude Code (CLAUDE.md), Windsurf (.windsurfrules), Codex / Cline (AGENTS.md), and GitHub Copilot (.github/copilot-instructions.md).

Q:Can I combine this rule with other technology stacks?

Yes. Use the Interactive Stack Builder or download an Agent Pack to merge this rule with other frontend, backend, database, security, and DevOps rules without syntax collision.

Open Specification · CC BY 4.0·Free for Personal, Team & Commercial In-Repo Use

Citation & Open Source Attribution Guidelines

This specification is licensed under Creative Commons Attribution 4.0 International (CC BY 4.0). You are completely free to adapt and share this rule in your workspace. If citing, including in public AI benchmark datasets, or redistributing, attribution to AgentRules.org is required.

1 Rule in Stack

RFC