SECURITY
guide
8 min read

Scoped API Tokens, Hard Deny-Lists & Audit Logs

Automation clients and coding agents authenticate to /api/v1/* and /mcp using Personal Access Tokens (PATs) prefixed with od_pat_. Every token is bound to its owning CMS user role, constrained by explicit scopes, blocked from high-risk operational routes by a hard Bearer deny-list, and logged for audit.

Token Format, Hashing & Storage Caps

OpenDash generates random 64-character hex secrets formatted as od_pat_<64-hex>, accompanied by a lookup identifier tok_<24-hex>. Only the 15-character prefix and a SHA-256 hash are stored in SQLite; the plaintext secret is displayed once at creation and cannot be recovered later.

ConstraintValue in V1Enforcement Source
Token prefix & IDod_pat_ / tok_<24-hex>routes/auth_tokens.rs
Token name1..=80 charactersValidated on CLI and HTTP
Optional expiration1..=365 daysexpires_days query/flag
Active tokens per userMax 32 active tokensMAX_ACTIVE_TOKENS_PER_USER

Creating & Revoking Tokens (Admin UI, HTTP & CLI)

Tokens can be minted from the Connect AI modal in OpenDash Admin (#/users), via the cookie-authenticated Admin HTTP API (GET|POST /api/admin/tokens and DELETE /api/admin/tokens/{id}), or directly on the host with opendash token create.

mint-draft-token.sh bash
OPENDASH_SITE_ROOT=/var/lib/opendash opendash token create \
  --name "docs-assistant" \
  --preset safe_draft_assistant \
  --expires-days 30 \
  --json

9 Granular Scopes & Built-in Presets

opendash-core::api_auth defines 9 fine-grained scopes alongside a legacy admin scope (which defaults only when neither preset nor scopes is specified, and is explicitly rejected inside custom scope lists).

Scope / PresetGranted Capabilities
site:readRead site overview, themes, blocks, patterns, locales, and diagnostics
content:readList and inspect entries, revisions, terms, redirects, 404 logs, and SEO context
content:writeCreate/update draft entries, terms, redirects, SEO proposals, and sparse SEO metadata
content:publishTransition draft_publish entries between draft and published status
builder:writePatch Studio block trees (patch_page_blocks, compose_page_from_patterns, builder endpoints)
design:writeModify theme options, design tokens, template overrides, menus, reading settings, and Home SEO
media:writeUpload media assets and edit media title/alt metadata
schema:writeApply schema mutations and content structure updates
mcp:accessConnect to POST|GET|DELETE /mcp sessions (still gated per-tool by mutation scopes)

Available Presets: read_only (site:read, content:read), safe_draft_assistant (adds content:write, builder:write, media:write, mcp:access while omitting publish, design, and schema writes), full_site_builder (all 9 granular scopes), and custom (explicit non-empty list without duplicates or admin).

Bearer CSRF Exemption vs /mcp Origin & Rate Limits

REST requests authenticated with Authorization: Bearer od_pat_... bypass browser cookie CSRF tokens and Origin checks on /api/v1/*. In contrast, the Streamable HTTP endpoint at /mcp validates any supplied Origin header against the listener origin or trusted_public_origin, limits active sessions to 256 (3600s idle TTL), and caps requests at 120 requests/minute per token.

Hard Bearer Deny-List (forbid_bearer_token)

Inspecting Agent & Bearer Audit Logs

Every mutating API v1 or MCP request invokes record_bearer_audit, recording the token identity, HTTP/tool action, resource kind, and response status. Administrators inspect recent automation trails in the Admin UI or query GET /api/admin/tokens/audit-logs?limit=50 using a browser Admin session.

Edit Source URL:

Search OpenDash

Use Arrow keys & Enter to navigate Full search page →