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

Hardware-Enforced Device-Bound Session Credentials (DBSC) Invariant

Enforces strict implementation of Device-Bound Session Credentials (DBSC) by binding HTTP sessions to client-side hardware security modules (TPM or Secure Enclave). Eliminates infostealer malware attack vectors by mandating cryptographic proof-of-possession, ephemeral challenge verification, and short-lived cookie lifetimes on all session refresh operations.

Prohibited Anti-Pattern: Exposing Unbound Long-Lived Bearer Sessions Susceptible to Token Exfiltration

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Hardware-Enforced Device-Bound Session Credentials (DBSC) Invariant - Enforces strict implementation of Device-Bound Session Credentials (DBSC) by binding HTTP sessions to client-side hardware security modules (TPM or Secure Enclave). Eliminates infostealer malware attack vectors by mandating cryptographic proof-of-possession, ephemeral challenge verification, and short-lived cookie lifetimes on all session refresh operations.
globs: src/auth/**/*.{ts,tsx}, src/middleware/**/*.{ts,tsx}, src/server/auth/**/*.{ts,js}, src/services/session/**/*.{ts,tsx}
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/device-bound-session-credentials-dbsc-standard"
---

# Hardware-Enforced Device-Bound Session Credentials (DBSC) Invariant

> **Severity**: CRITICAL | **Category**: security
> **Anti-Pattern Warning**: Exposing Unbound Long-Lived Bearer Sessions Susceptible to Token Exfiltration

## System Constraints
You are a Principal Security Architect enforcing the Device-Bound Session Credentials (DBSC) protocol standard. You must prevent session hijacking by strictly mandating that all sensitive and refreshable HTTP sessions are anchored to TPM or Secure Enclave key pairs. Enforce hardware-backed proof-of-possession headers, server-driven cryptographic challenges, replay protection with single-use nonces, and short-lived cookie renewal pipelines.

## Strict Guidelines
- Engineers MUST ALWAYS verify the client's DBSC proof-of-possession signature (`Sec-Session-Response`) against the hardware-backed public key registered during initial authentication.
- Engineers MUST ALWAYS validate single-use, cryptographically random challenge nonces with strict expiration (maximum 60 seconds) prior to re-issuing session cookies.
- Engineers MUST NOT issue unbound, long-lived session cookies; primary authentication cookies must have a strict, short lifespan (recommended <= 15 minutes).
- Services MUST issue a `Sec-Session-Challenge` response header upon initial registration or whenever a session renewal requires a fresh proof.
- Services MUST bind the DBSC session identifier (`session_id`) permanently to the client's hardware public key and reject any attempt to modify or reuse the key across differing client contexts.
- Components NEVER store private signing keys in software runtimes, localStorage, or accessible browser storage; key operations must remain isolated in TPM, Secure Enclave, or native platform authenticators.

## Bad vs Good Implementations
### DBSC Refresh Endpoint Implementation

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: The session refresh solely depends on an exfiltrable bearer refresh cookie. Infostealers reading browser cookie databases can replicate this call from an attacker's machine without hardware verification.
```typescript
import { Request, Response } from 'express';
import { verifyToken, issueSessionCookie } from './token-utils';

// Flawed: Standard bearer refresh token without hardware binding
export async function refreshSession(req: Request, res: Response) {
  const refreshToken = req.cookies['refresh_token'];
  if (!refreshToken) {
    return res.status(401).json({ error: 'Missing refresh token' });
  }

  const payload = await verifyToken(refreshToken);
  if (!payload) {
    return res.status(401).json({ error: 'Invalid refresh token' });
  }

  // Infostealer malware can exfiltrate this cookie and refresh sessions indefinitely
  const newSessionToken = issueSessionCookie(payload.userId);
  res.cookie('session_id', newSessionToken, { httpOnly: true, secure: true });
  return res.status(200).json({ status: 'refreshed' });
}
```

#### Production Standard (Correct)
> **Standard**: Requires hardware-backed cryptographic proof (`Sec-Session-Response`) signed by the client's TPM/Enclave key, verifies an ephemeral challenge nonce with replay protection, and limits session cookie longevity to 15 minutes.
```typescript
import { Request, Response } from 'express';
import * as crypto from 'crypto';
import { importJWK, jwtVerify } from 'jose';
import { sessionStore, challengeStore } from './dbsc-store';

export async function handleDbscRefresh(req: Request, res: Response) {
  const sessionId = req.headers['sec-session-id'] as string;
  const proofToken = req.headers['sec-session-response'] as string;

  if (!sessionId || !proofToken) {
    const newChallenge = crypto.randomBytes(32).toString('base64url');
    await challengeStore.issueNonce(sessionId ?? 'anonymous', newChallenge, 60);
    res.setHeader('Sec-Session-Challenge', `"${newChallenge}"`);
    return res.status(401).json({ error: 'DBSC proof required' });
  }

  const session = await sessionStore.findSession(sessionId);
  if (!session || !session.publicKeyJwk) {
    return res.status(403).json({ error: 'Invalid DBSC session registration' });
  }

  const clientKey = await importJWK(session.publicKeyJwk, 'ES256');
  
  let payload;
  try {
    const result = await jwtVerify(proofToken, clientKey, {
      algorithms: ['ES256'],
      audience: 'https://auth.example.com/dbsc/refresh'
    });
    payload = result.payload;
  } catch {
    return res.status(401).json({ error: 'Hardware signature verification failed' });
  }

  const validNonce = await challengeStore.consumeNonce(sessionId, payload.jti as string);
  if (!validNonce) {
    return res.status(403).json({ error: 'Stale or replayed challenge nonce' });
  }

  const newCookieValue = crypto.randomBytes(32).toString('base64url');
  await sessionStore.updateSessionCookie(sessionId, newCookieValue, 900); // 15 mins

  res.cookie('session_token', newCookieValue, {
    httpOnly: true,
    secure: true,
    sameSite: 'strict',
    maxAge: 15 * 60 * 1000
  });

  return res.status(200).json({ status: 'bound_session_refreshed' });
}
```

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

Hardware-Enforced Device-Bound Session Credentials (DBSC) Invariant defines an industrial-grade behavioral standard for security engineering. Enforces strict implementation of Device-Bound Session Credentials (DBSC) by binding HTTP sessions to client-side hardware security modules (TPM or Secure Enclave). Eliminates infostealer malware attack vectors by mandating cryptographic proof-of-possession, ephemeral challenge verification, and short-lived cookie lifetimes on all session refresh operations. 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: Exposing Unbound Long-Lived Bearer Sessions Susceptible to Token Exfiltration 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 DriftExposing Unbound Long-Lived Bearer Sessions Susceptible to Token ExfiltrationCritical
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 client's DBSC proof-of-possession signature (`Sec-Session-Response`) against the hardware-backed public key registered during initial authentication.

Engineers MUST ALWAYS verify the client's DBSC proof-of-possession signature (`Sec-Session-Response`) against the hardware-backed public key registered during initial authentication.

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 validate single-use, cryptographically random challenge nonces with strict expiration (maximum 60 seconds) prior to re-issuing session cookies.

Engineers MUST ALWAYS validate single-use, cryptographically random challenge nonces with strict expiration (maximum 60 seconds) prior to re-issuing session cookies.

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 unbound, long-lived session cookies

Engineers MUST NOT issue unbound, long-lived session cookies; primary authentication cookies must have a strict, short lifespan (recommended <= 15 minutes).

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 issue a `Sec-Session-Challenge` response header upon initial registration or whenever a session renewal requires a fresh proof.

Services MUST issue a `Sec-Session-Challenge` response header upon initial registration or whenever a session renewal requires a fresh proof.

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 bind the DBSC session identifier (`session_id`) permanently to the client's hardware public key and reject any attempt to modify or reuse the key across differing client contexts.

Services MUST bind the DBSC session identifier (`session_id`) permanently to the client's hardware public key and reject any attempt to modify or reuse the key across differing client contexts.

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

Components NEVER store private signing keys in software runtimes, localStorage, or accessible browser storage

Components NEVER store private signing keys in software runtimes, localStorage, or accessible browser storage; key operations must remain isolated in TPM, Secure Enclave, or native platform authenticators.

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

Enforces strict implementation of Device-Bound Session Credentials (DBSC) by binding HTTP sessions to client-side hardware security modules (TPM or Secure Enclave). Eliminates infostealer malware attack vectors by mandating cryptographic proof-of-possession, ephemeral challenge verification, and short-lived cookie lifetimes on all session refresh operations. 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 (Exposing Unbound Long-Lived Bearer Sessions Susceptible to Token Exfiltration) 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

Hardware-Enforced