This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
securitycritical PriorityID: rfc-9449-dpop-sender-constrained-token-rotation

RFC 9449 OAuth DPoP Sender-Constrained Token Rotation & Verification Invariant

Enforces strict RFC 9449 Demonstrating Proof-of-Possession (DPoP) verification across all microservice boundaries and edge ingress proxies. Mandates cryptographic thumbprint binding (`jkt`) in access tokens, asymmetric ephemeral key signature verification, strict HTTP method/URI claims matching, and distributed nonce-based replay prevention.

Prohibited Anti-Pattern: Accepting Bearer Tokens with Unbound DPoP Proofs or Forwarding Ingress DPoP Proofs Downstream

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: RFC 9449 OAuth DPoP Sender-Constrained Token Rotation & Verification Invariant - Enforces strict RFC 9449 Demonstrating Proof-of-Possession (DPoP) verification across all microservice boundaries and edge ingress proxies. Mandates cryptographic thumbprint binding (`jkt`) in access tokens, asymmetric ephemeral key signature verification, strict HTTP method/URI claims matching, and distributed nonce-based replay prevention.
globs: src/auth/**/*.ts, src/middleware/**/*.ts, src/gateway/**/*.ts, src/security/**/*.ts
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/rfc-9449-dpop-sender-constrained-token-rotation"
---

# RFC 9449 OAuth DPoP Sender-Constrained Token Rotation & Verification Invariant

> **Severity**: CRITICAL | **Category**: security
> **Anti-Pattern Warning**: Accepting Bearer Tokens with Unbound DPoP Proofs or Forwarding Ingress DPoP Proofs Downstream

## System Constraints
You are a Principal Security Architect enforcing RFC 9449 OAuth 2.0 Demonstrating Proof-of-Possession (DPoP) at the Application Layer. You must ensure that every inbound resource request validates asymmetric DPoP proof JWTs against the access token's `cnf.jkt` claim, enforces fresh single-use nonces, validates `htm` and `htu` claims without wildcard matching, and strictly forbids downstream propagation of raw client DPoP proofs across microservice boundaries.

## Strict Guidelines
- Services MUST extract the ephemeral public key from the `DPoP` header JWT `jwk` parameter and verify that its SHA-256 JWK Thumbprint precisely matches the `cnf.jkt` claim of the bound Access Token.
- Services MUST reject requests if the Authorization scheme is not `DPoP` or if the `typ` header in the DPoP proof is not exactly `dpop+jwt`.
- Services MUST validate that the DPoP proof's `htm` (HTTP method) and `htu` (HTTP URI without query or fragment) strictly match the incoming request envelope.
- Services MUST enforce server-provided DPoP nonces using a distributed atomic store (e.g., Redis cluster) with a strict TTL (<= 90 seconds) to neutralize replay attacks, rejecting expired or reused `jti` identifiers.
- Services MUST NEVER propagate incoming client DPoP proof JWTs to downstream services; internal inter-service calls MUST mint distinct, mutual TLS or service-to-service DPoP tokens using internal service identity keys.

## Bad vs Good Implementations
### Verifying RFC 9449 DPoP Proof Against Access Token Invariants

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Fails to compute and match the JWK thumbprint (jkt) of the DPoP proof against the access token's `cnf.jkt`, omits cryptographic signature verification, fails to validate the exact `htu` (HTTP URI), ignores nonce freshness/replay validation, and leaks client DPoP material downstream.
```typescript
import { Request, Response, NextFunction } from 'express';
import jwt from 'jsonwebtoken';

export async function insecureAuthMiddleware(req: Request, res: Response, next: NextFunction) {
  const authHeader = req.headers.authorization;
  const dpopHeader = req.headers['dpop'] as string | undefined;
  
  if (!authHeader?.startsWith('DPoP ')) {
    return res.status(401).json({ error: 'invalid_token' });
  }
  
  const token = authHeader.split(' ')[1];
  const decodedToken = jwt.decode(token) as { sub: string; cnf?: { jkt?: string } };
  
  // CRITICAL VULNERABILITY: Validates DPoP JWT existence but skips JWK thumbprint verification
  // and fails to bind `htm`, `htu`, and server nonce against the request.
  if (dpopHeader) {
    const decodedProof = jwt.decode(dpopHeader) as { htm?: string; htu?: string };
    if (decodedProof.htm !== req.method) {
      return res.status(401).json({ error: 'invalid_dpop_proof' });
    }
  }

  // Forwarding client proof downstream leaks replay material
  req.headers['x-forwarded-dpop'] = dpopHeader;
  next();
}
```

#### Production Standard (Correct)
> **Standard**: Implements full RFC 9449 compliance: cryptographically asserts that the DPoP ephemeral public key thumbprint precisely matches the access token's `cnf.jkt`, verifies asymmetric digital signatures, checks `htm` and normalized `htu` claims without query params, ensures single-use nonce validation against replay, and strips raw proofs prior to microservice dispatch.
```typescript
import { Request, Response, NextFunction } from 'express';
import { calculateJwkThumbprint, exportJWK, importJWK, jwtVerify } from 'jose';
import crypto from 'node:crypto';

interface NonceStore {
  consumeNonce(nonce: string, jti: string): Promise<boolean>;
  generateNonce(): Promise<string>;
}
declare const nonceStore: NonceStore;

export async function verifyDPoPRequest(
  req: Request,
  res: Response,
  next: NextFunction,
  trustedAuthServerKey: crypto.KeyObject
) {
  const authHeader = req.headers.authorization;
  const dpopHeader = req.headers['dpop'];

  if (!authHeader?.startsWith('DPoP ') || typeof dpopHeader !== 'string') {
    res.setHeader('WWW-Authenticate', 'DPoP error="invalid_token"');
    return res.status(401).json({ error: 'invalid_dpop_token' });
  }

  const rawAccessToken = authHeader.substring(5).trim();

  try {
    // 1. Verify Access Token integrity and extract confirmation thumbprint
    const { payload: tokenClaims } = await jwtVerify(rawAccessToken, trustedAuthServerKey);
    const cnfJkt = (tokenClaims.cnf as { jkt?: string } | undefined)?.jkt;
    if (!cnfJkt) {
      throw new Error('Access token missing cnf.jkt claim');
    }

    // 2. Decode and verify DPoP header using embedded JWK
    const [headerB64] = dpopHeader.split('.');
    const header = JSON.parse(Buffer.from(headerB64, 'base64url').toString('utf8'));
    if (header.typ !== 'dpop+jwt' || !header.jwk) {
      throw new Error('Invalid DPoP header typ or missing jwk');
    }

    // 3. Assert JWK thumbprint matches access token binding
    const computedJkt = await calculateJwkThumbprint(header.jwk, 'sha256');
    if (!crypto.timingSafeEqual(Buffer.from(computedJkt), Buffer.from(cnfJkt))) {
      throw new Error('DPoP public key thumbprint does not match token cnf.jkt');
    }

    // 4. Verify cryptographic proof signature
    const publicKey = await importJWK(header.jwk, header.alg);
    const expectedUri = `${req.protocol}://${req.get('host')}${req.baseUrl}${req.path}`;
    
    const { payload: proofClaims } = await jwtVerify(dpopHeader, publicKey, {
      algorithms: ['ES256', 'ES384', 'ES512', 'EdDSA', 'PS256'],
      maxTokenAge: '90s'
    });

    // 5. Invariant enforcement: htm, htu, and replay protection
    if (proofClaims.htm !== req.method || proofClaims.htu !== expectedUri) {
      throw new Error('DPoP method or URI mismatch');
    }

    const nonceValid = await nonceStore.consumeNonce(proofClaims.nonce as string, proofClaims.jti as string);
    if (!nonceValid) {
      const freshNonce = await nonceStore.generateNonce();
      res.setHeader('DPoP-Nonce', freshNonce);
      res.setHeader('WWW-Authenticate', 'DPoP error="use_dpop_nonce"');
      return res.status(401).json({ error: 'use_dpop_nonce' });
    }

    // Strip raw DPoP headers before potential internal dispatch
    delete req.headers['dpop'];
    return next();
  } catch (err) {
    res.setHeader('WWW-Authenticate', 'DPoP error="invalid_dpop_proof"');
    return res.status(401).json({ error: 'invalid_dpop_proof' });
  }
}
```

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 OAuth DPoP Sender-Constrained Token Rotation & Verification Invariant

RFC 9449 OAuth DPoP Sender-Constrained Token Rotation & Verification Invariant defines an industrial-grade behavioral standard for security engineering. Enforces strict RFC 9449 Demonstrating Proof-of-Possession (DPoP) verification across all microservice boundaries and edge ingress proxies. Mandates cryptographic thumbprint binding (`jkt`) in access tokens, asymmetric ephemeral key signature verification, strict HTTP method/URI claims matching, and distributed nonce-based replay prevention. 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 Bearer Tokens with Unbound DPoP Proofs or Forwarding Ingress DPoP Proofs Downstream 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 Bearer Tokens with Unbound DPoP Proofs or Forwarding Ingress DPoP Proofs DownstreamCritical
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

Services MUST extract the ephemeral public key from the `DPoP` header JWT `jwk` parameter and verify that its SHA-256 JWK Thumbprint precisely matches the `cnf.jkt` claim of the bound Access Token.

Services MUST extract the ephemeral public key from the `DPoP` header JWT `jwk` parameter and verify that its SHA-256 JWK Thumbprint precisely matches the `cnf.jkt` claim of the 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.
2

Services MUST reject requests if the Authorization scheme is not `DPoP` or if the `typ` header in the DPoP proof is not exactly `dpop+jwt`.

Services MUST reject requests if the Authorization scheme is not `DPoP` or if the `typ` header in the DPoP proof is not exactly `dpop+jwt`.

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

Services MUST validate that the DPoP proof's `htm` (HTTP method) and `htu` (HTTP URI without query or fragment) strictly match the incoming request envelope.

Services MUST validate that the DPoP proof's `htm` (HTTP method) and `htu` (HTTP URI without query or fragment) strictly match the incoming request envelope.

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 enforce server-provided DPoP nonces using a distributed atomic store (e.g., Redis cluster) with a strict TTL (<= 90 seconds) to neutralize replay attacks, rejecting expired or reused `jti` identifiers.

Services MUST enforce server-provided DPoP nonces using a distributed atomic store (e.g., Redis cluster) with a strict TTL (<= 90 seconds) to neutralize replay attacks, rejecting expired or reused `jti` identifiers.

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

Services MUST NEVER propagate incoming client DPoP proof JWTs to downstream services

Services MUST NEVER propagate incoming client DPoP proof JWTs to downstream services; internal inter-service calls MUST mint distinct, mutual TLS or service-to-service DPoP tokens using internal service identity keys.

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 OAuth DPoP Sender-Constrained Token Rotation & Verification Invariant critical for AI coding assistants?

Enforces strict RFC 9449 Demonstrating Proof-of-Possession (DPoP) verification across all microservice boundaries and edge ingress proxies. Mandates cryptographic thumbprint binding (`jkt`) in access tokens, asymmetric ephemeral key signature verification, strict HTTP method/URI claims matching, and distributed nonce-based replay prevention. 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 Bearer Tokens with Unbound DPoP Proofs or Forwarding Ingress DPoP Proofs Downstream) 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