Security and permissions

Principals, roles, secrets at rest, rate limits and the identifiers that are frozen on purpose.

Principals

Principal Credential Scope
admin DOT_ADMIN_API_KEY (env, ≥ 32 chars) every management route
tenant random key shown once, stored hashed, rotatable its own slug
member dot_sess_… session from a login, stored as SHA-256 its slug, filtered by role
widget HMAC-signed visitor session its slug + visitor id, web_widget only
webhook URL secret, constant-time compare POST /webhooks/chatwoot

Missing or invalid credentials get 401 with WWW-Authenticate: Bearer; a valid credential for the wrong tenant gets 403. CORS credentials are always off.

Self-service signup

POST /api/v1/signup creates a tenant, its first owner and a trial. It is rate-limited per IP (5 per hour), capped per day platform-wide (DOT_SIGNUP_DAILY_CAP) and validates every field with stable error codes. There is no email provider yet, so addresses are not verified: use DOT_SIGNUP_MODE=code (a shared signup code, compared in constant time) or closed on a host you do not want strangers to create workspaces on. A signup that fails after the tenant was created removes the tenant again.

Roles

owner, manager, agent, billing with default-deny RBAC on every tenant path. Chatwork Router routes follow the knowledge-base scopes: reads and routing previews need kb:read (owner, manager, agent), writes need kb (owner, manager). The last active owner cannot be removed or demoted (atomic guard). TOTP with single-use recovery codes; login lockout per (slug, email, ip) and per (slug, email).

Secrets at rest

Provider credentials, agent-bot tokens, commerce tokens and TOTP secrets are Fernet-encrypted with DOT_CREDENTIALS_KEY, which lives outside the database. No API returns a secret, a ciphertext, or any *_token, *_secret, *_api_key, *_password or *_enc field; logs redact ?token=, dot_sess_, dot_inv_ and dot_rst_.

Response headers

Every response carries X-Request-ID (the caller’s, when well-formed, or a generated one), X-Content-Type-Options: nosniff and Referrer-Policy: no-referrer. HTML pages add X-Frame-Options: DENY and a restrictive Permissions-Policy; /api/* is Cache-Control: no-store.

Outbound safety

Tenant MCP URLs and Chatwork Router source URLs must be https and resolve to public addresses (private, loopback, link-local and reserved ranges are refused). Public X replies are cut to 280 characters, sent with an 8–20 s human delay and back off for 30 minutes on 402/429.

Frozen identifiers

Some names are locked by docs/INVARIANTS.md because customers or data depend on them: Redis key prefixes (diamond:dot:*), the widget globals (window.DiamondDotWidget, diamond_dot_visitor_id), the /health service id, and the MCP tool names. The brand is Chatwork; these identifiers are plumbing and stay as they are.

Reporting a vulnerability

See SECURITY.md in the repository. Please do not open public issues for security reports.

Type a keyword to search titles, sections, headings and content.