# CASA controls

How opendesk meets each requirement of the App Defense Alliance CASA specification v2.1.1, and where in the code.

opendesk is assessed against the App Defense Alliance CASA specification v2.1.1. For each requirement, this page gives how opendesk meets it and where: the AL1 evidence a CASA self-assessment asks for. opendesk Cloud and a self-hosted install run the same code, so every control here holds in both. Paths are relative to the [opendesk repository](https://github.com/useopendesk/opendesk). The invariants behind these controls are summarised in [Security controls](/security/).

## 1 Authentication

| Requirement | How opendesk meets it | Where |
| --- | --- | --- |
| 1.1.1 Authentication is resistant to brute force attacks | opendesk runs its own sign-in, with Google, Microsoft, GitHub and OIDC sign-in as options. Every new or changed password must be 12 to 128 characters and is refused when it is on an embedded list of breached passwords. Password sign-in is rate limited per IP (30 tries in 15 minutes) and per account (10 tries in 15 minutes), counted in Postgres across every server. Two-factor codes have their own limits per account, at most 30 a day. With a Turnstile key set, as on opendesk Cloud, login, registration and password reset also need a Turnstile check or an App Attest proof from the iPhone app. Login answers the same, in the same time, for an unknown account and a wrong password. | `internal/auth/password.go` (`CheckPassword`, `DummyVerify`), `internal/core/auth.go` (`handleLogin`, `handleMFA`), `internal/core/appattest.go` (`humanCheck`), `internal/captcha/turnstile.go`, `internal/httpx/middleware.go` (`Limiter.Shared`) |
| 1.1.2 System generated initial passwords are random and expire after a short period | The only passwords opendesk generates are for test accounts an instance admin creates: 24 characters from `crypto/rand`, valid for one day by default and two days at most. An expired one reads as no password at sign-in, and signing in with one answers `change_password`, so the person sets their own. Accounts and invitations otherwise never carry a generated password. | `internal/admin/testworkspaces.go` (`GeneratePassword`, `DefaultPasswordDays`, `maxPasswordDays`), `internal/auth/password.go` (`PasswordHashSQL`), `internal/core/auth.go` (`handleLogin`) |
| 1.1.3 Passwords are stored in a form resistant to offline attacks | Passwords are hashed with Argon2id (64 MiB of memory, 3 iterations, 2 lanes, a 16-byte random salt per password) and compared in constant time. | `internal/auth/password.go` (`HashPassword`, `VerifyPassword`) |
| 1.2.1 No default credentials on public interfaces | opendesk ships no built-in accounts and no default passwords. The first account is registered by a person, and instance admin rights are granted from the command line to an account that already exists. The service does not start in production without its own generated secrets. | `cmd/opendesk/admin.go`, `internal/admin/admins.go` (`Grant`), `internal/config/config.go` (`Load`), `deploy/self-host/gen-env.sh` |
| 1.3.1 Out-of-band verifiers expire | A password reset link works for one hour, and an email confirmation link for 48 hours. Two-factor codes are TOTP codes with 30-second steps. | `internal/core/mail.go` (`resetTTL`, `verifyTTL`, `createOneTime`), `internal/core/totp.go` (`totpMatch`) |
| 1.3.2 Out-of-band verifiers are used once | A link token is marked used in the same statement that accepts it, and a password reset or change also retires every other reset link of the account. A TOTP code is accepted only for a time step after the last one used, and recovery codes work once. | `internal/core/mail.go` (`consumeOneTime`), `internal/core/auth.go`, `internal/core/totp.go` (`consumeTOTP`, `checkSecondFactor`) |
| 1.3.3 Out-of-band verifiers are securely random | Link tokens are 32 bytes (256 bits) from the operating system's secure random generator. Only their SHA-256 hash is stored. | `internal/crypto/crypto.go` (`RandomToken`, `HashToken`), `internal/core/mail.go` (`createOneTime`) |
| 1.3.4 Out-of-band verifiers resist brute force | Link tokens carry 256 bits of entropy. Reset requests are limited per IP and per address, link use per IP, and two-factor codes per IP and per account. | `internal/core/auth.go`, `internal/core/mail.go` |

## 2 Session management

| Requirement | How opendesk meets it | Where |
| --- | --- | --- |
| 2.1.1 No passwords or session tokens in URLs | Passwords travel only in request bodies. Access tokens and API keys travel in the `Authorization` header, refresh tokens in cookies (or the body for the iPhone app). The realtime gateway reads its token only from the WebSocket protocol header and ignores one in the URL. No API route reads a credential from the query string. | `internal/auth/middleware.go` (`resolve`), `realtime/lib/realtime_web/channels/socket_auth.ex`, `web/src/lib/api/client.ts` |
| 2.2.1 Logout and expiry invalidate sessions on the server | Logout revokes the session in the database, deletes its push devices and closes its live connections. Every request checks that the session behind its access token is still live, so a revoked or expired session stops working at once. Access tokens last 15 minutes and a session ends 30 days after sign-in at most. A refresh token rotates on every use, and a reused one ends its session. Admin panel sessions end after an hour without use and 12 hours after sign-in. The chat widget's shutdown ends the visitor session on the server. | `internal/core/auth.go` (`auth-logout`), `internal/core/sessions.go` (`endSession`, `rotateRefresh`, `SessionMaxAge`), `internal/auth/middleware.go` (`resolve`), `internal/admin/auth.go`, `internal/helpdesk/widget/public.go` (`widget-end-session`) |
| 2.2.2 Other sessions end after a password change or reset | A password change ends every other session of the account, its admin panel sessions and its connected apps, and closes their live connections. A password reset ends all of them. People can also see and end their sessions one by one. | `internal/core/me.go` (`change-password`), `internal/core/auth.go` (`auth-password-reset`), `internal/core/sessions.go` (`revokeOtherSessions`, `revoke-session`), `internal/core/oauthgrant` (`Revoke`) |
| 2.2.3 Stateless authentication tokens expire within 24 hours | Every signed token has an expiry, checked on every use. Access tokens last 15 minutes, admin panel tokens 10 minutes, realtime tokens 5 minutes, two-factor and passkey steps 5 minutes, sign-in state 10 minutes and MCP access tokens one hour. Refresh tokens, API keys and widget visitor tokens are stored on the server and can be revoked. An email's unsubscribe link carries a signed token that only turns off that member's notification emails from one workspace; it signs no one in and opens no data. | `internal/auth/tokens.go`, `internal/core/mcpserver/oauth.go` |
| 2.3.1 Session cookies are Secure | Session cookies are Secure whenever the API is on https, and the service refuses to start with insecure cookies on an https address. On https they carry the `__Host-` prefix. | `internal/core/sessions.go` (`refreshCookie`), `internal/core/accounts.go` (`refreshCookieName`), `internal/admin/auth.go` (`cookie`), `internal/config/config.go` |
| 2.3.2 Session cookies are HttpOnly | Every session cookie, and every cookie that binds a sign-in flow to the browser, is HttpOnly. | `internal/core/sessions.go` (`refreshCookie`), `internal/core/oauth.go` (`bindCookie`), `internal/admin/auth.go` (`cookie`) |
| 2.3.3 Session tokens rather than static secrets | Every sign-in creates a new session with a new random refresh token and short-lived access tokens. API keys are a separate, optional credential for integrations, limited by scope and revocable. | `internal/core/sessions.go` (`issueSession`, `tokenResponse`) |
| 2.3.4 Stateless tokens are signed and checked | Tokens are JSON Web Tokens signed with HS256 and a secret of at least 32 bytes. Verification accepts HS256 only (no `none`, no other algorithm), requires an expiry and checks the token's single purpose. The realtime gateway verifies the same way. | `internal/auth/tokens.go` (`Verify`), `realtime/lib/realtime/auth.ex`, `internal/config/config.go` |
| 2.4.1 Sensitive changes need a full session or re-authentication | Every account change needs a signed-in session. Changing a password needs the current password, and an account without one needs a sign-in within the last 12 hours. Deleting an account, managing two-factor and passkeys, deleting or transferring a workspace and rotating the widget secret need a recent sign-in, and owner operations also need two-factor. Admin panel changes need a fresh TOTP code. | `internal/core/me.go`, `internal/core/helpers.go` (`requireRecentLogin`), `internal/core/totp.go` (`requireMFA`), `internal/core/workspaces.go` (`rotateWidgetSecret`), `internal/admin/auth.go` (`stepUp`) |

## 3 Access control

| Requirement | How opendesk meets it | Where |
| --- | --- | --- |
| 3.1.1 Least privilege enforced on a trusted service layer | Every API route checks the caller on the server before it runs: signed-in members have a role (viewer, agent, admin, owner), API keys and connected apps have scopes, and widget visitors reach only their own conversations. Viewers read only, settings need an admin and owner operations need the owner. Tickets of a private team are visible only to its members. | `internal/auth/principal.go`, `internal/auth/middleware.go` (`RequireWorkspace`, `RequireUser`, `RequireVisitor`), `internal/domain/visibility.go` |
| 3.1.2 Access attributes cannot be changed by users | The workspace, role and scopes come from the verified session or API key on the server, never from the request body. A role changes only through the members routes, which an admin or owner calls. | `internal/auth/middleware.go` (`resolve`), `internal/core/members.go` |
| 3.1.3 Access controls fail securely | A caller that cannot be resolved has no principal, and every check refuses it. A failed check answers 401, 403 or, for a ticket the caller cannot see, 404. Unexpected errors answer a fixed message and never pass the check. | `internal/auth/middleware.go`, `internal/httpx/errors.go` (`Wrap`), `internal/domain/visibility.go` (`LoadVisibleTicket`) |
| 3.1.4 Protection against insecure direct object references | Every workspace record is read and written with the workspace of the authenticated principal. Referenced ids (contact, team, tag, mailbox, attachment) are checked to belong to the same workspace before use, uploads are attachable only by their uploader, and file downloads check the ticket's visibility. | `internal/helpdesk/hd/util.go` (`CheckRef`), `internal/helpdesk/hd/attachments.go` (`CheckAttachments`), `internal/helpdesk/widget/attachments.go` (`mayRead`), `internal/domain/visibility.go` (`CanSee`) |
| 3.1.5 Anti-CSRF for authenticated and unauthenticated functions | API calls authenticate with a bearer token in a header, which a browser never attaches by itself. Refresh cookies are SameSite and honoured only on requests from the app's own origin; the admin panel's auth routes accept only the panel's origin. Each OAuth flow is bound to the browser that started it with an HttpOnly cookie. Unauthenticated forms have the Turnstile check and rate limits. | `internal/core/helpers.go` (`readReqInfo`), `internal/admin/auth.go` (`checkOrigin`), `internal/core/oauth.go` (`bindCookie`) |
| 3.1.6 Directory browsing is disabled | The binary serves the web app and admin panel from embedded builds and answers only files, never a directory listing. The hosted app, site and docs are static Cloudflare Pages sites. | `internal/webui/webui.go`, `internal/adminui/adminui.go` |
| 3.2.1 Only secure OAuth 2.0 flows | Every OAuth flow, as a client and as a server, is the authorization code flow with PKCE (S256): sign-in with Google, Microsoft, GitHub and OIDC (with a nonce), mailbox and Collab connections, integrations and MCP tool servers. The MCP OAuth server offers only `response_type=code` and the `authorization_code` and `refresh_token` grants, and requires PKCE S256. | `internal/core/oauth.go`, `internal/email/api_oauth.go`, `internal/collab/oauth.go`, `internal/integrations/api.go` (`beginSignIn`), `internal/ai/mcp/oauth.go`, `internal/core/mcpserver/oauth.go` |
| 3.2.2 `redirect_uri` and `state` are validated | As a client, the redirect URI is fixed from the instance's API address, and `state` is a signed, single-purpose token that expires after 10 minutes, carries the sealed PKCE verifier and must match a nonce cookie of the browser that started the flow. The address to return to after sign-in must be a path on the app's own origin. As a server, the MCP OAuth server accepts only registered redirect URIs, matched exactly (loopback ports excepted, as RFC 8252 allows), refuses a repeated `redirect_uri`, shows errors on its own page rather than redirecting, and returns `state` unchanged. | `internal/core/oauth.go` (`oauthCallback`, `safeRedirectPath`), `internal/email/api_oauth.go` (`oauthCallback`), `internal/collab/connect.go` (`oauthCallback`), `internal/integrations/api.go` (`oauthCallback`), `internal/core/mcpserver/oauth.go` (`validRedirect`, `matchRedirect`) |
| 3.3.1 Administrative interfaces use multi-factor authentication | The instance admin panel asks for the password and a TOTP code at every sign-in, and only accounts with two-factor turned on can use it. It has its own sessions and audit log, accepts only its own origin, and manages the application only: there is no infrastructure access through it. | `internal/admin/auth.go` (`login`, `mfa`, `loadAdmin`), `internal/admin/admin.go` |

## 4 Communications

| Requirement | How opendesk meets it | Where |
| --- | --- | --- |
| 4.1.1 TLS for all connections, TLS 1.2 or later, secure ciphers | Every public endpoint is https: on opendesk Cloud through Cloudflare (minimum TLS 1.2, TLS 1.3 on, always https, and the TLS 1.2 cipher list limited to forward-secret AEAD suites with `edge_cipher_suites` on a zone with Advanced Certificate Manager) and the AWS load balancer (`ELBSecurityPolicy-TLS13-1-2-Res-2021-06`, port 80 redirects to https). Self-hosted installs use Caddy's automatic HTTPS. HSTS is set. The database connection uses TLS with the certificate verified, and mail connections require TLS 1.2 or later. | `deploy/terraform/modules/cloudflare/main.tf`, `deploy/terraform/modules/cloudflare-help/main.tf`, `deploy/terraform/modules/alb/main.tf`, `deploy/terraform/modules/planetscale/main.tf`, `deploy/caddy/Caddyfile`, `internal/httpx/middleware.go` (`SecurityHeaders`), `internal/email/netguard.go` |
| 4.1.2 Trusted TLS certificates | Public certificates come from AWS Certificate Manager and Cloudflare on opendesk Cloud, and from Let's Encrypt through Caddy on a self-hosted install. Cloudflare checks the origin certificate (strict mode). Outbound connections verify the server's certificate against trusted roots, and no client turns verification off. | `deploy/terraform/modules/alb/main.tf` (`aws_acm_certificate`), `deploy/terraform/modules/cloudflare/main.tf`, `deploy/caddy/Caddyfile`, `internal/email/netguard.go`, `internal/mailer/mailer.go` |
| 4.1.3 No weak cryptography | Passwords: Argon2id. Stored secrets (mailbox credentials, OAuth tokens, webhook secrets, TOTP secrets): AES-256-GCM with a 32-byte key (`CREDENTIALS_KEY`, kept in AWS Secrets Manager on opendesk Cloud) and a random 12-byte nonce per value. The key can be replaced: values decrypt with `CREDENTIALS_KEY` or a key in `CREDENTIALS_KEY_PREVIOUS`, and a background pass encrypts every registered sealed column again with the current key. Tokens: HMAC-SHA256 (HS256) with a secret of at least 32 bytes. Session, API key and link tokens: 32 random bytes, stored as SHA-256 hashes. Webhook signatures: HMAC-SHA256. TOTP follows RFC 6238. | `internal/auth/password.go`, `internal/crypto/crypto.go` (`Box`, `RandomToken`, `HashToken`, `HMACHex`), `internal/sealed`, `internal/auth/tokens.go`, `internal/core/totp.go` |
| 4.1.4 Cryptographic modules fail securely | AES-GCM is authenticated, so a changed or damaged value fails to open as a whole and returns one error; there is no padding to probe. Token checks fail closed and answer the same message whatever the cause. | `internal/crypto/crypto.go` (`Box.Open`), `internal/auth/tokens.go` (`Verify`) |

## 5 Data validation and sanitization

| Requirement | How opendesk meets it | Where |
| --- | --- | --- |
| 5.1.1 Protection against HTTP parameter pollution | Request input is bound by name into typed, declared parameters. The MCP OAuth server refuses a repeated `redirect_uri` or `resource`. Links and query strings are built with encoders, never by joining strings. | `internal/app/app.go`, `internal/core/mcpserver/oauth.go`, `web/src/lib/api/client.ts` |
| 5.1.2 Redirects go only to allowed destinations | After sign-in the app returns only to a path on its own origin. Server redirects go to the app's own pages, a registered OAuth redirect URI or a provider's fixed authorization address. | `internal/core/oauth.go` (`safeRedirectPath`), `web/src/components/auth/parts.tsx` (`safeNext`), `internal/core/mcpserver/oauth.go` (`matchRedirect`) |
| 5.1.3 No `eval` or dynamic code execution | No code is built or run from user input, on the server or in the browser. Customer-facing templates run on opendesk's own engine, which only fills values and evaluates fixed tags. | `internal/templates/engine.go` |
| 5.1.4 Protection against template injection | Customer-facing templates are filled in one pass from a fixed variable list, so a filled value is never read as template code. Templates are checked against the variable list when saved. Server-rendered HTML uses Go's context-aware `html/template`. | `internal/templates/engine.go` (`Render`), `internal/templates/catalog.go` (`Check`), `internal/helpdesk/helpsite/render.go` |
| 5.1.5 Protection against server-side request forgery | Every outbound connection to a user-chosen address (webhooks, picture fetches, knowledge sites, integrations, MCP servers, mail settings discovery, IMAP and SMTP hosts) is refused when the host resolves to a private, loopback, link-local, shared or metadata address, and HTTP requests must use https. The check runs again on the address actually connected to, so DNS rebinding cannot get around it, and redirects are not followed. | `internal/netsafe/netsafe.go` (`Guard`, `Client`), `internal/email/netguard.go`, `internal/core/ssrf.go` |
| 5.1.6 Protection against XPath and XML injection | opendesk runs no XPath queries. XML (mail settings files, documents for the knowledge base) is read with Go's `encoding/xml`, which does not resolve external entities. | `internal/email/mailhost/autoconfig.go`, `internal/ai/knowledge/files.go` |
| 5.1.7 Protection against cross-site scripting | React escapes text by default. Every HTML insertion in the browser takes sanitized input, and email and agent HTML is also sanitized with bluemonday before it is stored. Designed emails render in a sandboxed frame without scripts. A Content Security Policy blocks inline scripts on the app. | `web/src/lib/sanitize.ts`, `internal/helpdesk/hd/html.go`, `internal/email/kit.go` (`SanitizeHTML`), `web/src/components/tickets/detail/EmailFrame.tsx`, `deploy/cloudflare/pages/app/_headers` |
| 5.1.8 Protection against database injection | Every query binds values as parameters. Sort keys and table names come from fixed allowlists. | `internal/helpdesk/tickets/list.go` (`parseSort`), `internal/helpdesk/hd/util.go` (`CheckRef`), `internal/db` |
| 5.1.9 Protection against OS command injection | opendesk runs no operating system commands. | `internal`, `cmd/opendesk` |
| 5.1.10 Protection against file inclusion | Stored files use keys the server generates from ids, and storage refuses any key that leaves its directory. No file is loaded or run from a path or address a user names. | `internal/storage/storage.go` (`validKey`), `internal/helpdesk/hd/attachments.go` (`SaveUpload`) |
| 5.2.1 Protection against malicious file uploads | Uploads (ticket and chat attachments, imports) are capped at 25 MB. Programs and scripts are refused by extension and by their first bytes, and the stored type comes from the file's content; HTML, SVG, XML and JavaScript are stored as plain text or binary. Knowledge files accept only the document types the knowledge base reads, and pictures are decoded and re-encoded as PNG. Downloads are served as attachments with `nosniff` and `Content-Security-Policy: default-src 'none'; sandbox`; only raster images show inline. Files go to object storage or a data directory the web server does not serve. | `internal/helpdesk/hd/attachments.go` (`IsExecutable`, `DetectType`, `SaveUpload`, `InlineSafe`), `internal/helpdesk/widget/attachments.go` (`download`), `internal/collab/api_attachments.go`, `internal/ai/knowledge/files.go` (`detectFile`), `internal/images/http.go` (`ReadUpload`), `internal/storage/storage.go` |

## 6 Configuration

| Requirement | How opendesk meets it | Where |
| --- | --- | --- |
| 6.1.1 No components with known exploitable vulnerabilities | Dependabot watches Go, npm, Mix, Docker, GitHub Actions and Terraform. CI runs `govulncheck`, `pnpm audit`, `mix deps.audit`, Sobelow and CodeQL, and Trivy scans every container image; a production image with a fixable high or critical finding is not deployed. The scans also run weekly. | `.github/dependabot.yml`, `.github/workflows/security.yml`, `.github/workflows/deploy.yml` |
| 6.2.1 Debug modes are off in production | An instance runs in production unless it is set to development and reachable on localhost alone. Production refuses development secrets, insecure cookies on https, logged email bodies and a development Stripe address. There are no debug or profiling routes, production builds ship no source maps, and server errors answer a fixed message with a request id, never a stack trace. | `internal/config/config.go` (`Load`), `internal/httpx/errors.go` (`Install`), `web/vite.config.ts`, `admin/vite.config.ts`, `realtime/config/prod.exs` |
| 6.3.1 The Origin header is not used for authentication | Authentication is by token or cookie. Origin checks are an extra layer on top: credentialed CORS is allowed only for the configured app origins (the admin API only for the admin origin), and public routes allow any origin without credentials. | `internal/httpx/middleware.go` (`CORS`), `internal/auth/middleware.go`, `realtime/lib/realtime_web/endpoint.ex` |
| 6.4.1 Protection against subdomain takeover | opendesk Cloud's DNS records are managed in Terraform together with the resources they point to (the load balancer, the Pages projects, the help center target), so they are created and removed together. A custom help center domain is served only after its owner proves control with a TXT record, at most one help center holds a hostname, and hostnames no help center holds are removed from Cloudflare by a regular job. A self-hosted Caddy gets a certificate only for hosts opendesk confirms as active help centers. | `deploy/terraform/modules/cloudflare/main.tf`, `deploy/terraform/modules/cloudflare-help/main.tf`, `internal/helpdesk/helpdomains/check.go` (`Check`, `claim`, `Release`, `Reconcile`), `deploy/caddy/Caddyfile` |
| 6.5.1 No credentials or payment details in logs | Request logs record method, path, status, duration and request id, never query strings, bodies or headers. Log lines never include secrets, tokens, passwords or full connection strings, and a failed webhook delivery records its cause without the URL. Card details are entered on Stripe's pages and never reach opendesk, and the Stripe webhook logs only the event id and type. The realtime gateway filters token, password, secret and key parameters. | `internal/httpx/middleware.go` (`Logger`), `deploy/caddy/Caddyfile`, `internal/billing/webhook.go`, `realtime/config/config.exs` |
| 6.6.1 Browser storage is cleared at logout | The web app and admin panel keep access tokens in memory only, and refresh tokens are HttpOnly cookies the page cannot read. Their browser storage holds only ids and display preferences, never tokens or customer data. Signing out clears the in-memory tokens, the cached data and the analytics identity, and expires the refresh cookie. The chat widget's visitor token, kept in the host site's storage, is removed and ended on the server when the host page calls `opendesk("shutdown")` at its own sign-out. | `web/src/lib/session.ts` (`signOut`, `clearSession`), `web/src/lib/api/client.ts` (`forgetAllAccounts`), `web/src/app/useAccounts.ts`, `web/widget/src/controller.ts` (`shutdown`), `web/widget/src/storage.ts` |
| 6.7.1 Server-side secrets are stored securely | On opendesk Cloud, service secrets are generated by Terraform and kept in AWS Secrets Manager, encrypted with a KMS key, and given to the services at start by ECS; only the services' ECS roles may read them, and CloudTrail records every read. A self-hosted install generates them once into its `.env` file. Secrets the app stores (mailbox credentials, OAuth tokens, webhook secrets, TOTP secrets) are sealed with AES-256-GCM, and API keys, session and link tokens are stored only as hashes. | `deploy/terraform/modules/secrets/main.tf`, `deploy/terraform/modules/ecs-service/main.tf`, `deploy/self-host/gen-env.sh`, `internal/crypto/crypto.go` (`Box`) |

## 7 Webhook security

| Requirement | How opendesk meets it | Where |
| --- | --- | --- |
| 7.1.1 Webhooks travel only over HTTPS with TLS 1.2 or later | As a provider, opendesk refuses a webhook URL that is not https. As a consumer, its Stripe and inbound email endpoints are served only over https (TLS 1.2 or later), and plain http redirects to https. | `internal/core/webhooks.go` (`validateWebhookURL`), `internal/netsafe/netsafe.go` (`ValidateURL`), `deploy/terraform/modules/alb/main.tf`, `deploy/caddy/Caddyfile` |
| 7.1.2 Endpoint ownership is verified before delivery | A new webhook, or one whose URL changes, is unverified. opendesk sends its URL a signed `webhook.verification` event with a random challenge; the endpoint is verified when it answers with the challenge, or when an admin enters the challenge it received (valid for 24 hours). Events are queued only for verified webhooks, a delivery whose webhook is no longer verified is not sent, and test events need a verified webhook. | `internal/core/webhooks.go` (`challengeWebhook`, `enterWebhookCode`, `verify-webhook`, dispatch and delivery workers) |
| 7.2.1 Payloads are authenticated with HMAC-SHA256 | Outgoing webhooks carry `OD-Signature: t=<time>,v1=<hex HMAC-SHA256>` over the timestamp and the raw body, with a random secret per webhook. Incoming Stripe events are verified with the Stripe library against the raw body. Inbound email from the Cloudflare Email Worker is verified with `OD-Inbound-Signature`, an HMAC-SHA256 over the timestamp, recipient, envelope sender and raw message. Requests with a missing or wrong signature are refused. | `internal/core/webhooks.go` (`signWebhook`), `internal/billing/webhook.go`, `internal/email/inbound.go` (`inboundSignatureOK`, `SignInbound`), `deploy/cloudflare/email-worker/src/index.ts` |
| 7.2.2 Signatures are compared in constant time | Inbound email signatures are compared with `subtle.ConstantTimeCompare`, and Stripe signatures with `hmac.Equal` inside the Stripe library. | `internal/email/inbound.go` (`inboundSignatureOK`), `internal/billing/webhook.go` |
| 7.2.3 Replay protection with signed timestamps | The timestamp is part of the signed string in every direction. Inbound email and Stripe events older or newer than five minutes are refused, and each Stripe event is applied at most once. | `internal/core/webhooks.go` (`signWebhook`), `internal/email/inbound.go` (`inboundSignatureTolerance`), `internal/billing/webhook.go` (`webhookTolerance`, `handleEvent`) |
| 7.3.1 SSRF protection for user-supplied callback URLs | Webhook URLs must be https and resolve only to public addresses: private ranges (10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16), loopback, link-local and cloud metadata addresses (169.254.169.254, `fd00:ec2::254`, metadata host names) and other reserved ranges are refused. Deliveries dial only the checked address, so DNS rebinding is refused too, and redirects are not followed. | `internal/netsafe/netsafe.go` (`IsPublicIP`, `Guard`, `Client`), `internal/core/ssrf.go` (`webhookClient`) |
| 7.3.2 Signing secrets are not in source code | Each webhook gets its own random secret when it is created, shown once and stored sealed with AES-256-GCM. `STRIPE_WEBHOOK_SECRET` and `INBOUND_SECRET` come from AWS Secrets Manager on opendesk Cloud (the email worker's from a Cloudflare secret) and from the generated `.env` file on a self-hosted install. None is in the repository. | `internal/core/webhooks.go` (`create-webhook`), `deploy/terraform/modules/secrets/main.tf`, `deploy/cloudflare/email-worker/wrangler.toml`, `deploy/self-host/.env.template` |
