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

W3C Device Bound Session Credentials (DBSC) Hardware-Bound Attestation Guardrail

Enforces W3C Device Bound Session Credentials (DBSC) to bind HTTP sessions to platform hardware security modules (Apple Secure Enclave, Windows TPM, Android StrongBox). Neutralizes session cookie exfiltration (infostealers, AiTM proxies) by requiring cryptographic proof-of-possession (PoP) signatures for session establishment, sensitive operations, and cookie refresh cycles. Rejects any session renewal or high-privilege action that relies purely on bearer cookies without verifying asymmetric hardware key signatures and nonce freshness.

Prohibited Anti-Pattern: Unvalidated Bearer Token Refresh Permitting Exfiltrated Cookie Reuse Without Hardware Key Proof-of-Possession

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: W3C Device Bound Session Credentials (DBSC) Hardware-Bound Attestation Guardrail - Enforces W3C Device Bound Session Credentials (DBSC) to bind HTTP sessions to platform hardware security modules (Apple Secure Enclave, Windows TPM, Android StrongBox). Neutralizes session cookie exfiltration (infostealers, AiTM proxies) by requiring cryptographic proof-of-possession (PoP) signatures for session establishment, sensitive operations, and cookie refresh cycles. Rejects any session renewal or high-privilege action that relies purely on bearer cookies without verifying asymmetric hardware key signatures and nonce freshness.
globs: src/auth/**/*.{ts,tsx,js,jsx}, src/middleware/**/*.{ts,tsx,js,jsx}, src/security/**/*.{ts,tsx,js,jsx}, src/routes/auth/**/*.{ts,tsx,js,jsx}
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/w3c-dbsc-hardware-bound-session-attestation-guardrail"
---

# W3C Device Bound Session Credentials (DBSC) Hardware-Bound Attestation Guardrail

> **Severity**: CRITICAL | **Category**: security
> **Anti-Pattern Warning**: Unvalidated Bearer Token Refresh Permitting Exfiltrated Cookie Reuse Without Hardware Key Proof-of-Possession

## System Constraints
You are a Principal Security Architect enforcing W3C Device Bound Session Credentials (DBSC) and hardware-backed proof-of-possession invariants. Modern web architectures must mitigate AitM (Adversary-in-the-Middle) phishing and infostealer malware by binding session tokens to platform TPMs and Secure Enclaves. Reject any implementation that treats authentication cookies as ambient bearer tokens for session establishment, refresh, or high-privilege mutations. Mandate strict cryptographic verification of the `Sec-Session-Response` header against the client's registered public key, enforce strict nonce challenge freshness to defeat replay attacks, and terminate sessions when hardware attestation fails or keys mutate without re-authentication.

## Strict Guidelines
- Services MUST initiate DBSC registration by returning a `Sec-Session-Registration` header containing the session identifier, refresh URL, supported algorithms (e.g., ES256), and an ephemeral server challenge.
- Engineers MUST ALWAYS verify the asymmetric signature in incoming `Sec-Session-Response` headers using the hardware-backed public key previously registered for that specific session ID.
- Engineers MUST NOT issue new short-lived session cookies on refresh endpoints without validating a fresh Proof-of-Possession (PoP) signature containing the exact server-generated challenge.
- Authentication middleware MUST enforce single-use, cryptographically secure nonces with maximum 60-second time-to-live (TTL) to block replay attacks on DBSC response payloads.
- Storage layers MUST persist client public keys in an immutable, tamper-evident format tied to the primary account ID and device fingerprint; public keys MUST NEVER be mutable via client-controlled update endpoints.
- Services MUST downgrade or terminate sessions immediately if `Sec-Session-Response` validation fails, alerting telemetry systems of potential credential exfiltration.

## Bad vs Good Implementations
### Verifying Hardware-Bound Proof-of-Possession in Session Refresh Middleware

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: The session refresh handler assumes cookie possession proves client identity. An infostealer trojan or proxy can harvest the refresh cookie and authenticate from an attacker-controlled machine because no hardware cryptographic binding is validated.
```typescript
import { Request, Response, NextFunction } from 'express';
import jwt from 'jsonwebtoken';

// ANTI-PATTERN: Refreshing session cookies solely based on bearer refresh cookie.
// If an infostealer extracts `refreshToken`, it can renew the session indefinitely from any device.
export async function handleSessionRefresh(req: Request, res: Response): Promise<void> {
  const refreshToken = req.cookies['__Host-refresh_token'];
  if (!refreshToken) {
    res.status(401).json({ error: 'Missing refresh token' });
    return;
  }

  try {
    const payload = jwt.verify(refreshToken, process.env.JWT_SECRET!) as { userId: string };
    const newAccessToken = jwt.sign({ userId: payload.userId }, process.env.JWT_SECRET!, { expiresIn: '15m' });
    
    res.cookie('__Host-access_token', newAccessToken, { httpOnly: true, secure: true, sameSite: 'strict' });
    res.status(200).json({ status: 'refreshed' });
  } catch (err) {
    res.status(401).json({ error: 'Invalid token' });
  }
}
```

#### Production Standard (Correct)
> **Standard**: Validates the `Sec-Session-Response` header against the TPM/Secure Enclave hardware public key registered during session initialization. Enforces strict audience checking and single-use challenge consumption, rendering exfiltrated cookies completely useless to attackers without physical access to the device's hardware key.
```typescript
import { Request, Response } from 'express';
import * as crypto from 'crypto';
import * as jose from 'jose';
import { getStoredDBSCSession, consumeChallenge, revokeSession } from './dbsc-session-store';

interface DBSCProofClaims extends jose.JWTPayload {
  sub: string;
  aud: string;
  jti: string;
  iat: number;
}

// PRODUCTION INVARIANT: W3C DBSC Hardware-Bound Attestation.
// Session renewal requires verifying a cryptographic PoP signature produced by the client TPM/Secure Enclave.
export async function handleDBSCSessionRefresh(req: Request, res: Response): Promise<void> {
  const sessionId = req.headers['sec-session-id'] as string;
  const responseToken = req.headers['sec-session-response'] as string;

  if (!sessionId || !responseToken) {
    res.status(401).json({ error: 'DBSC header missing: hardware binding required' });
    return;
  }

  const session = await getStoredDBSCSession(sessionId);
  if (!session) {
    res.status(401).json({ error: 'DBSC session not found or revoked' });
    return;
  }

  try {
    // 1. Import client public key (registered during initial hardware enrollment)
    const publicKey = await jose.importJWK(session.hardwarePublicKeyJwk, 'ES256');

    // 2. Verify PoP JWT signed by Secure Enclave / TPM
    const { payload } = await jose.jwtVerify<DBSCProofClaims>(responseToken, publicKey, {
      audience: 'https://auth.internal.domain/v1/session/refresh',
      algorithms: ['ES256']
    });

    // 3. Enforce single-use challenge freshness to neutralize replays
    const isValidChallenge = await consumeChallenge(session.id, payload.jti);
    if (!isValidChallenge) {
      await revokeSession(session.id);
      res.status(401).json({ error: 'DBSC challenge expired or replayed' });
      return;
    }

    // 4. Issue new bound short-lived cookie
    const newAccessToken = crypto.randomBytes(32).toString('hex');
    res.cookie('__Host-access_token', newAccessToken, {
      httpOnly: true,
      secure: true,
      sameSite: 'strict',
      path: '/'
    });

    // 5. Issue next challenge for subsequent rotation
    const nextChallenge = crypto.randomUUID();
    res.setHeader('Sec-Session-Challenge', nextChallenge);
    res.status(200).json({ status: 'refreshed' });
  } catch (error) {
    await revokeSession(session.id);
    res.status(401).json({ error: 'Hardware attestation signature verification failed' });
  }
}
```

Architectural Specification & Invariant Rationale

Architectural Invariant Design: W3C Device Bound Session Credentials (DBSC) Hardware-Bound Attestation Guardrail

W3C Device Bound Session Credentials (DBSC) Hardware-Bound Attestation Guardrail defines an industrial-grade behavioral standard for security engineering. Enforces W3C Device Bound Session Credentials (DBSC) to bind HTTP sessions to platform hardware security modules (Apple Secure Enclave, Windows TPM, Android StrongBox). Neutralizes session cookie exfiltration (infostealers, AiTM proxies) by requiring cryptographic proof-of-possession (PoP) signatures for session establishment, sensitive operations, and cookie refresh cycles. Rejects any session renewal or high-privilege action that relies purely on bearer cookies without verifying asymmetric hardware key signatures and nonce freshness. 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: Unvalidated Bearer Token Refresh Permitting Exfiltrated Cookie Reuse Without Hardware Key Proof-of-Possession 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 DriftUnvalidated Bearer Token Refresh Permitting Exfiltrated Cookie Reuse Without Hardware Key Proof-of-PossessionCritical
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 initiate DBSC registration by returning a `Sec-Session-Registration` header containing the session identifier, refresh URL, supported algorithms (e.g., ES256), and an ephemeral server challenge.

Services MUST initiate DBSC registration by returning a `Sec-Session-Registration` header containing the session identifier, refresh URL, supported algorithms (e.g., ES256), and an ephemeral server 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.
2

Engineers MUST ALWAYS verify the asymmetric signature in incoming `Sec-Session-Response` headers using the hardware-backed public key previously registered for that specific session ID.

Engineers MUST ALWAYS verify the asymmetric signature in incoming `Sec-Session-Response` headers using the hardware-backed public key previously registered for that specific session ID.

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 NOT issue new short-lived session cookies on refresh endpoints without validating a fresh Proof-of-Possession (PoP) signature containing the exact server-generated challenge.

Engineers MUST NOT issue new short-lived session cookies on refresh endpoints without validating a fresh Proof-of-Possession (PoP) signature containing the exact server-generated 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.
4

Authentication middleware MUST enforce single-use, cryptographically secure nonces with maximum 60-second time-to-live (TTL) to block replay attacks on DBSC response payloads.

Authentication middleware MUST enforce single-use, cryptographically secure nonces with maximum 60-second time-to-live (TTL) to block replay attacks on DBSC response payloads.

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

Storage layers MUST persist client public keys in an immutable, tamper-evident format tied to the primary account ID and device fingerprint

Storage layers MUST persist client public keys in an immutable, tamper-evident format tied to the primary account ID and device fingerprint; public keys MUST NEVER be mutable via client-controlled update endpoints.

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

Services MUST downgrade or terminate sessions immediately if `Sec-Session-Response` validation fails, alerting telemetry systems of potential credential exfiltration.

Services MUST downgrade or terminate sessions immediately if `Sec-Session-Response` validation fails, alerting telemetry systems of potential credential exfiltration.

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) Hardware-Bound Attestation Guardrail critical for AI coding assistants?

Enforces W3C Device Bound Session Credentials (DBSC) to bind HTTP sessions to platform hardware security modules (Apple Secure Enclave, Windows TPM, Android StrongBox). Neutralizes session cookie exfiltration (infostealers, AiTM proxies) by requiring cryptographic proof-of-possession (PoP) signatures for session establishment, sensitive operations, and cookie refresh cycles. Rejects any session renewal or high-privilege action that relies purely on bearer cookies without verifying asymmetric hardware key signatures and nonce freshness. 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 (Unvalidated Bearer Token Refresh Permitting Exfiltrated Cookie Reuse Without Hardware Key Proof-of-Possession) 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