This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
securitycritical PriorityID: dbsc-cryptographic-session-binding-guardrail

W3C Device-Bound Session Credentials (DBSC) Cryptographic Invariant

Enforces cryptographic hardware-binding of HTTP application sessions using W3C Device-Bound Session Credentials (DBSC) specifications. Prevents token exfiltration and session replay attacks by asserting asymmetric TPM or Secure Enclave proof signatures on session initialization, refresh, and high-privilege transactional paths.

Prohibited Anti-Pattern: Unbound Bearer Cookie Replay and Missing Hardware-Attested DBSC Signature Proofs

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: W3C Device-Bound Session Credentials (DBSC) Cryptographic Invariant - Enforces cryptographic hardware-binding of HTTP application sessions using W3C Device-Bound Session Credentials (DBSC) specifications. Prevents token exfiltration and session replay attacks by asserting asymmetric TPM or Secure Enclave proof signatures on session initialization, refresh, and high-privilege transactional paths.
globs: src/auth/**/*.{ts,js}, src/middleware/**/*.{ts,js}, src/server/auth/**/*.{ts,js}, src/api/auth/**/*.{ts,js}
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/dbsc-cryptographic-session-binding-guardrail"
---

# W3C Device-Bound Session Credentials (DBSC) Cryptographic Invariant

> **Severity**: CRITICAL | **Category**: security
> **Anti-Pattern Warning**: Unbound Bearer Cookie Replay and Missing Hardware-Attested DBSC Signature Proofs

## System Constraints
You are a Principal Security Architect enforcing W3C Device-Bound Session Credentials (DBSC) invariants. You must ensure that authentication systems cryptographically bind session lifecycle transitions and high-privilege calls to hardware-backed client public keys (TPM/Secure Enclave), enforcing single-use challenge verification and signature checks to defeat session hijacking and cookie theft.

## Strict Guidelines
- Engineers MUST ALWAYS verify the `Sec-Session-Response` header against the registered hardware-backed public key during session creation, refresh, and privileged operations.
- Engineers MUST NEVER permit session renewal or sensitive state mutations solely based on bearer cookies without verifying single-use, cryptographically secure nonces issued via `Sec-Session-Challenge`.
- Services MUST invalidate the session immediately upon detection of a public key mismatch, invalid cryptographic proof, or replayed challenge nonce.
- Code SHOULD enforce standard cryptographic signature algorithms (ES256, RS256, Ed25519) specified in the DBSC session registration parameters.
- Components NEVER accept ambient cookie credentials when a session is flagged as hardware-bound, terminating requests that omit required DBSC challenge responses.

## Bad vs Good Implementations
### DBSC Hardware-Bound Session Refresh Verification

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Accepts a raw bearer refresh token without requiring or verifying DBSC proof headers (`Sec-Session-Response`), making the session vulnerable to infostealer malware, token replay, and cross-machine exfiltration.
```typescript
import { Request, Response } from 'express';
import { verifyJwt } from './jwt';
import { findSession } from './db';

export async function refreshSessionHandler(req: Request, res: Response) {
  const refreshToken = req.cookies['refresh_token'];
  if (!refreshToken) {
    return res.status(401).json({ error: 'Missing refresh token' });
  }

  // CRITICAL SECURITY FLAW: Vulnerable to cookie exfiltration/replay.
  // Fails to verify W3C DBSC hardware proof or challenge nonce.
  const payload = verifyJwt(refreshToken);
  const session = await findSession(payload.sessionId);
  if (!session || session.revoked) {
    return res.status(401).json({ error: 'Invalid session' });
  }

  const newAccessToken = generateAccessToken(session.userId);
  return res.json({ accessToken: newAccessToken });
}
```

#### Production Standard (Correct)
> **Standard**: Enforces W3C DBSC proof verification via `Sec-Session-Response`. Asserts that the client holds the TPM-backed private key registered during initialization, validates single-use server challenge nonces, and strictly binds the session identifier to the cryptographic assertion.
```typescript
import { Request, Response } from 'express';
import { subtle } from 'node:crypto';
import { findSession, consumeChallengeNonce } from './db';
import { decodeJwtHeader, importSpkiKey } from './crypto-utils';

interface DbscProofPayload {
  jti: string;
  iat: number;
  nonce: string;
  aud: string;
  sub: string;
}

export async function refreshSessionHandler(req: Request, res: Response) {
  const sessionId = req.cookies['session_id'];
  const dbscProof = req.header('Sec-Session-Response');

  if (!sessionId || !dbscProof) {
    // Mandate DBSC challenge flow if client omits cryptographic proof
    res.setHeader('Sec-Session-Challenge', `"${generateChallengeNonce()}"; id="${sessionId || ''}"`);
    return res.status(401).json({ error: 'Device binding proof required' });
  }

  const session = await findSession(sessionId);
  if (!session || session.revoked || !session.devicePublicKey) {
    return res.status(401).json({ error: 'Invalid or unbound session' });
  }

  // Verify hardware signature (DBSC Proof JWT signed by TPM/Secure Enclave)
  const [headerB64, payloadB64, signatureB64] = dbscProof.split('.');
  const payload: DbscProofPayload = JSON.parse(Buffer.from(payloadB64, 'base64url').toString('utf8'));

  // Invariant: Nonce must be fresh, single-use, and bound to this session
  const isNonceValid = await consumeChallengeNonce(session.id, payload.nonce);
  if (!isNonceValid || payload.sub !== session.id) {
    return res.status(403).json({ error: 'Invalid DBSC challenge or session binding' });
  }

  const publicKey = await importSpkiKey(session.devicePublicKey, session.keyAlgorithm);
  const dataBytes = new TextEncoder().encode(`${headerB64}.${payloadB64}`);
  const signatureBytes = Buffer.from(signatureB64, 'base64url');

  const isSignatureValid = await subtle.verify(
    { name: session.keyAlgorithm, hash: 'SHA-256' },
    publicKey,
    signatureBytes,
    dataBytes
  );

  if (!isSignatureValid) {
    return res.status(403).json({ error: 'Cryptographic device proof mismatch' });
  }

  const newAccessToken = generateAccessToken(session.userId);
  return res.json({ accessToken: newAccessToken });
}
```

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: W3C Device-Bound Session Credentials (DBSC) Cryptographic Invariant

W3C Device-Bound Session Credentials (DBSC) Cryptographic Invariant defines an industrial-grade behavioral standard for security engineering. Enforces cryptographic hardware-binding of HTTP application sessions using W3C Device-Bound Session Credentials (DBSC) specifications. Prevents token exfiltration and session replay attacks by asserting asymmetric TPM or Secure Enclave proof signatures on session initialization, refresh, and high-privilege transactional paths. 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: Unbound Bearer Cookie Replay and Missing Hardware-Attested DBSC Signature Proofs 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 DriftUnbound Bearer Cookie Replay and Missing Hardware-Attested DBSC Signature ProofsCritical
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 verify the `Sec-Session-Response` header against the registered hardware-backed public key during session creation, refresh, and privileged operations.

Engineers MUST ALWAYS verify the `Sec-Session-Response` header against the registered hardware-backed public key during session creation, refresh, and privileged operations.

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

Engineers MUST NEVER permit session renewal or sensitive state mutations solely based on bearer cookies without verifying single-use, cryptographically secure nonces issued via `Sec-Session-Challenge`.

Engineers MUST NEVER permit session renewal or sensitive state mutations solely based on bearer cookies without verifying single-use, cryptographically secure nonces issued via `Sec-Session-Challenge`.

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 invalidate the session immediately upon detection of a public key mismatch, invalid cryptographic proof, or replayed challenge nonce.

Services MUST invalidate the session immediately upon detection of a public key mismatch, invalid cryptographic proof, or replayed challenge nonce.

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

Code SHOULD enforce standard cryptographic signature algorithms (ES256, RS256, Ed25519) specified in the DBSC session registration parameters.

Code SHOULD enforce standard cryptographic signature algorithms (ES256, RS256, Ed25519) specified in the DBSC session registration 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.
5

Components NEVER accept ambient cookie credentials when a session is flagged as hardware-bound, terminating requests that omit required DBSC challenge responses.

Components NEVER accept ambient cookie credentials when a session is flagged as hardware-bound, terminating requests that omit required DBSC challenge responses.

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 W3C Device-Bound Session Credentials (DBSC) Cryptographic Invariant critical for AI coding assistants?

Enforces cryptographic hardware-binding of HTTP application sessions using W3C Device-Bound Session Credentials (DBSC) specifications. Prevents token exfiltration and session replay attacks by asserting asymmetric TPM or Secure Enclave proof signatures on session initialization, refresh, and high-privilege transactional paths. 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 (Unbound Bearer Cookie Replay and Missing Hardware-Attested DBSC Signature Proofs) 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

W3C