Skip to content

Security policy

Reporting a vulnerability

Please report privately through GitHub: Security tab > "Report a vulnerability" (https://github.com/MiguelCarrascoB/clef/security/advisories/new). Do not open a public issue for security problems. Include the version (clef version), the backend, and steps to reproduce. You can expect an acknowledgement within a few days; this is a one-maintainer project, so there is no formal SLA.

Supported version: the latest release (3.1.x).

Threat model

clef runs a model on your own hardware and exposes an HTTP API. It is designed for a single trusted operator and, at most, trusted callers on a local network.

  • Local by default. CLEF_HOST defaults to 127.0.0.1. Binding any other address without API keys logs a loud warning at startup.
  • API keys. Two kinds protect every /v1/* route and the Hugging Face compatibility routes (/hf/models/*). Env keys (CLEF_API_KEY or CLEF_API_KEYS, named, from a list or a file) are full admin with no quota: treat them as break-glass credentials, and note that every env-key holder sees every job and may change every saved classifier, so env keys are not isolated from each other. A managed key whose name equals an env key's is refused (401, startup warning), so it cannot inherit that env key's ownership; the server is the authority on this, since the env seen by clef keys can differ. Managed keys (clef keys create, the console or /v1/admin/keys) belong to a principal with scopes (classify, jobs, classifiers, ops, admin, urgent; a missing scope is 403), an optional daily record quota and rate limit, expiry and revocation. A managed key is clef_live_<id>_<secret>; only its SHA-256 is stored, so it cannot be recovered, and the secret is shown once (create / rotate). A rotated principal keeps up to five keys; the old ones expire after a grace period (default 24 h). Daily quotas are counted in the memory of the one server process; they rely on the one-server-per-database rule (a Postgres advisory lock refuses a second server), so do not run two servers on one database. Auth is on when an env key exists or any managed key ever existed, and never turns off by itself (revoking the last managed key does not open the server). /v1/admin/* always needs an admin key, even when auth is off. clef keys works directly on the database (that is how the first admin key is made, with the server stopped, as the OS user who can read the state directory), so access to the state directory is access to key management; protect it like the keys file. The OpenAI-compatible routes read the same keys as Authorization: Bearer, so the official SDKs work unchanged. Keys are compared in constant time (managed keys by their hash), and only the principal name is recorded in the request log and stats. Key changes are audited (who, what, when, IP; never a secret). Keep the keys file out of version control and readable only by you (chmod 600). The SSE endpoint /v1/events also accepts ?key= for plain EventSource clients, which puts the key in the URL; do not use it across untrusted networks without TLS. The console sends the X-API-Key header instead.
  • Rate limit and quota. CLEF_RATE_LIMIT limits inference requests per minute per key (per IP when auth is off) and returns 429 with Retry-After; a managed key can have its own limit. A managed key can also have a daily quota of records per UTC day (computed records only; cache hits are free; a job is charged at submit and refunded for what it did not process), refused with 429 and Retry-After. It is a safety net against accidents and noisy clients, not a DDoS defence.
  • Rate limit scope. Besides the classification routes, POST /v1/chat/completions, POST /hf/models/*, POST /v1/evaluate and POST /v1/jobs count against the limit. POST /v1/evaluate/metrics runs no inference and is not counted.
  • CORS is off unless CLEF_CORS_ORIGINS is set. Do not embed API keys in browser code.
  • SSRF guard. Fetching media from http(s) URLs is off by default (CLEF_ALLOW_URL_FETCH=0). When enabled, hosts are resolved and any non-global address (private, loopback, link-local, multicast) is refused, redirects are not followed, and downloads are size-capped (CLEF_URL_FETCH_MAX_MB) with a total timeout. Data URLs are the default way to send media.
  • Input limits. Body size, token count, images, videos, pixels, frames, labels, questions and batch size are all capped and validated (CLEF_MAX_*). Evaluation and jobs add their own caps: CLEF_MAX_EVAL_ROWS (500 rows per /v1/evaluate call), CLEF_MAX_JOB_EVAL_ROWS (100000), CLEF_MAX_JOB_ITEMS (100000 items per job), CLEF_MAX_JOBS (100 queued or running jobs, then 409) and a 16 KB limit on job metadata. Errors are generic 500s with a request id; tracebacks stay in the server log.
  • Webhooks and SSRF. A webhook makes the server send a request to an address chosen by the API caller, so the feature is off until the operator sets CLEF_WEBHOOK_ALLOW (hosts, *.suffix patterns, IPs or CIDRs). The list is checked when the job is submitted and again on every delivery attempt: the hostname is resolved at that moment, every returned address must be public or inside a listed IP / CIDR, and the connection is pinned to the checked address, so a DNS answer that changes later (rebinding) is refused. Link-local (cloud metadata), multicast, unspecified and reserved addresses are refused even when a CIDR covers them. IPv6 addresses that embed an IPv4 address (NAT64 64:ff9b::/96 and 64:ff9b:1::/48, 6to4, Teredo) are judged by that IPv4 address, and site-local IPv6 is refused, so a translated address cannot reach a private host. Redirects are never followed, environment proxies are ignored, credentials in the URL are rejected and API keys are never sent. Deliveries are signed (X-Clef-Signature, HMAC-SHA256 over "<timestamp>.<body>"); receivers should verify it and check the timestamp. Use https for anything that leaves your machine. The TLS path has not been tested against a real TLS server yet. POST /v1/jobs/{id}/webhook/redeliver resends a failed delivery only to the job's stored URL, needs the owner's key, is rate limited and re-runs every check above. Details: docs/jobs.md.
  • Jobs: ownership, retention, disk. With keys configured, a job belongs to the principal that submitted it; other non-admin keys get 404 and do not see it in the list. Admin keys (all env keys included) see every job. This is a convenience between cooperating callers, not tenant isolation, and jobs or classifiers created while auth was off (no owner) become admin-only once auth is on: non-admin keys get 404 for such a job, 403 when changing or deleting such a classifier, and may still run it. Jobs are stored in the database (clef.db in the state directory, or CLEF_DATABASE_URL): the submitted payload of every job (your input texts), its result rows and webhook secrets are stored in clear text (HMAC needs the secret; evaluate rows also keep the input and gold label). Finished jobs are deleted CLEF_JOB_TTL_HOURS after they finish (default 168; 0 keeps them forever) or on DELETE /v1/jobs/{id}. Protect the state directory like the API keys file, and delete clef.db (with the server stopped) to drop everything.
  • Database files and URLs. A new clef.db is created readable by its owner only (0600 on POSIX), and so are the copies clef backup writes to <state dir>/backups/; a clef.db copied from a v3.1 jobs.db is 0600 too, but the original kept as jobs.db.migrated keeps its old permissions (delete it once you are happy). With Postgres, everyone who can read that database reads the same payloads and secrets: give clef its own database and role, and use TLS (?sslmode=require) to a remote server. CLEF_DATABASE_URL carries the password: clef never logs it, and /health, clef doctor and the clef db commands show it as ***. Prefer a systemd EnvironmentFile or a compose .env with tight permissions over the command line. The audit log (audit_log: saved-classifier changes, key changes, job cancel / delete; GET /v1/admin/audit) records who, what and when, never a secret or request content; it has no purge. Job results exported as CSV neutralise cells that start with =, +, - or @, so opening them in a spreadsheet does not run formulas.
  • No secrets in logs. Request state (the text you classify) is not logged unless CLEF_LOG_STATE=1, but jobs do store it on disk (see above). clef's own logs never contain a key: headers are not logged, and the values of the key, api_key and token query parameters are replaced with REDACTED in the uvicorn access log (also with CLEF_LOG_FORMAT=json). A reverse proxy in front of clef keeps its own logs; see Keys in proxy logs. Saved classifier names are validated and never used to build paths from raw input.
  • Console and vendored code. The console is a zero-build app served by the server with no runtime CDN calls. Its three vendored libraries (Preact, htm, uPlot) and their licences are listed in THIRD_PARTY_NOTICES.md.
  • Model and dependencies. Weights come from the pinned Hugging Face revision; CLEF_MODEL_PATH should point only at files you trust (the model code in the release directory is imported and executed). Dependencies are pinned in requirements/.

Out of scope / not provided: TLS (use a reverse proxy, see docs/remote-access.md), per-user authorization beyond the scopes above (all keys that may run the model have the same access to it; job and saved classifier ownership only scope visibility and changes), multi-tenant isolation, protection against a malicious model directory.

Keys in proxy logs

clef masks keys in its own logs, but a reverse proxy writes its own access log. Keep the key out of it too: drop the X-API-Key and Authorization headers and mask (or drop) the query string.

Caddy logs every request header when a log directive is on, and redacts only Authorization, Cookie and Proxy-Authorization by default, so X-Api-Key would be written in clear text:

clef.example.com {
    log {
        format filter {
            request>uri query {
                replace key REDACTED
                replace api_key REDACTED
                replace token REDACTED
            }
            request>headers>X-Api-Key delete
        }
    }
    reverse_proxy 127.0.0.1:8910
}

nginx logs no request headers by default (do not add $http_x_api_key or $http_authorization to a log_format), but the default combined format logs $request, which includes the query. Log $uri (the path without the query) instead:

log_format clef '$remote_addr - $remote_user [$time_local] "$request_method $uri $server_protocol" '
                '$status $body_bytes_sent "$http_referer" "$http_user_agent"';
access_log /var/log/nginx/clef.access.log clef;