Skip to content

Latest commit

 

History

History
291 lines (248 loc) · 20.9 KB

reference.md

File metadata and controls

291 lines (248 loc) · 20.9 KB

API Reference

Base URLs:

  • Through the web service (recommended): https://<host>/api or https://localhost:8443/api
  • Directly to the backend, from the host only: http://127.0.0.1:5001/api

Every route needs HTTP Basic, JWT bearer, API token or session cookie authentication (see Authentication) except POST /api/auth/login, POST /api/auth/refresh, GET /api/health, GET /api/client-setup, GET /api/client-setup/ca.crt, GET /api/ready, GET /health, GET /livez, GET /readyz and GET /metrics. The WebSocket authenticates with a single-use token (see WebSocket). A running backend lists every registered route at GET /api/docs (authenticated).

OpenAPI

GET /api/openapi.json (authenticated) is an OpenAPI 3.1 description of every route the running backend registers, built from its router: paths, methods, summaries, which routes need authentication, and in x-spm-token-scope the scope an API token needs (read, write, or none when no token may call it). The lists, settings and access-log routes carry request and response schemas; the others are described without schemas for now.

A write operation either carries a request body schema or says x-spm-body: none, so a client can tell "takes nothing" from "not described"; the request schemas are tested against the handlers both ways (a body valid by its schema is not refused as malformed, and one without a required field is), and a field the schema does not know is refused exactly when the schema is closed (additionalProperties: false, where the handler decodes strictly). Every write operation is described; a new one that is not fails the build.

x-spm-surfaces names where each operation can be reached: always api, and ui, cli and mcp when the dashboard, the spm command or the MCP server offer it. x-spm-api-only, when present, says why only the API offers an operation (a health probe, a call the WAF makes, a retired route), and x-spm-not-in-ui why the dashboard deliberately leaves one to the command and the MCP server. Tests hold the dashboard and the MCP server to the list: an operation marked ui that the dashboard does not call, or one it calls that is not marked, fails the build.

The same document is published with this site at openapi.json, for client generators and API explorers. It leaves out the runtime profiles (/debug/pprof), which the live document includes.

Most successful responses are {"status": "success", "data": ...}. The authentication endpoints (/api/auth/login, /api/auth/refresh, /api/ws-token, /api/logout, /api/change-password) return a flat object with status and the payload fields at the top level. Errors are {"status": "error", "code": "...", "detail": "..."}: detail says what went wrong in words, and code is one of a fixed list for a client to branch on. A 500 carries a generic detail, with the cause in the backend log.

code Status
invalid_request 400
unauthorized 401
forbidden 403 (a cross-site request with the session cookie, a route no token may call)
token_scope 403: the API token's scope does not allow the call
not_found 404
conflict 409
gone 410: a retired route; detail names the one to use
too_large 413
unprocessable 422
rate_limited 429
internal_error 500
upstream_unreachable 502: the WAF or another service did not answer
unavailable 503
trigger_write_failed, reload_failed, clear_cache_failed 500: the proxy reload or cache clear named failed

A few errors carry more: errors (the refused fields of a settings save), data (a failed reload's exit codes) or waf_status. The Error schema of the OpenAPI document lists every field and code.

Dry run

The 21 operations that remove or reset something take ?dry_run=true: they answer 200 with data.dry_run: true and what they would do, and change nothing (no row, no list export, no audit line, no configuration snapshot). Any dry_run but true or false answers 400 invalid_request.

Operation The preview says
DELETE /api/{list}/clear-all, POST /api/{list}/bulk-delete removed: the entries that would go
DELETE /api/{list}/sources/{id} removed and kept: the entries that would go, and those another source lists too
POST /api/logs/clear, POST /api/logs/clear-old removed: the log lines that would go
POST /api/counters/reset logs_cleared, and waf_reset: what the WAF would be asked
POST /api/maintenance/restore-config the counts of the restore (restored, skipped, restored_settings, ...) and not_in_backup
POST /api/maintenance/clear-cache would: what the proxy would do
DELETE /api/client-groups/{id} removed (the group's name), members, lists
DELETE /api/tokens/{id} revoked: the token's name; 404 for one not in use

The counts are the ones the real call would answer: the source removal and the restore run their own statements in a transaction that is rolled back. The OpenAPI document declares the parameter on each of these operations.

An operation that changes the configuration takes a configuration snapshot first, except for a request that carries dry_run. Those that have no preview (a settings change or save, the WAF policy, its exceptions and log-only rules, a default-deny allowlist addition or removal by id, a client group added or edited) answer 400 invalid_request to a dry_run other than false or empty, and change nothing.

A server before 3.40.0 does not know dry_run: it ignores the parameter and runs the call. Before asking an unknown server for a preview, check that its GET /api/openapi.json declares dry_run on the operation, as spm does.

Collections

Endpoints that return a collection put it under data and the pagination under meta:

{
  "status": "success",
  "data": [ ... ],
  "meta": { "total": 1234, "limit": 100, "offset": 0 }
}

total, limit and offset are also emitted at the top level. They are deprecated; read meta.

Contract version

Every response carries an X-API-Version header: the version of the request and response shapes, 1 at this commit. It changes only when a shape a client depends on changes, unlike version in /api/health, which is the release.

Authentication and health

Method Path Description
POST /api/auth/login Check credentials, return an access and a refresh JWT, or with X-SPM-Session: cookie set the HttpOnly session cookie (no auth)
POST /api/auth/refresh Exchange a refresh token for a new pair (no auth)
POST /api/logout Revoke the bearer or session-cookie token of the request (clearing the cookie), and the refresh token in an optional {"refresh_token": ...} body
POST /api/change-password Change the admin password
GET /api/ws-token Issue a single-use WebSocket token
GET /api/session Who is signed in, how (cookie, bearer, basic) and expires_at
GET /api/health Status, version, commit (no auth)
GET /api/client-setup What a device needs (the /setup page): proxy_ip, proxy_auth, inspection (bump, peek, off) and ca (sha256, not_after, or null) (no auth)
GET /api/client-setup/ca.crt The SSL-bump CA certificate as secure-proxy-ca.crt, 404 until the proxy has one; nginx also serves it at /ca.crt on ports 8011 and 8443 (no auth)
GET /api/ready, /readyz 200 when the database answers, 503 otherwise (no auth)
GET /health, /livez 200 while the process runs (no auth)
GET /metrics Prometheus metrics (no auth; nginx does not proxy it)
GET /api/docs The list of registered routes

Client groups

Method Path Description
GET /api/client-groups Every client group
POST /api/client-groups Create a group (Client groups)
GET /api/client-groups/{id} One group
PUT /api/client-groups/{id} Replace a group
DELETE /api/client-groups/{id} Delete a group
PUT /api/ip-blacklist/sources/{id}/scope, /api/domain-blacklist/sources/{id}/scope Whether a source applies to every client (global) or only to the groups that use it (groups)

Lists

{list} is one of ip-blacklist, domain-blacklist, ip-whitelist, domain-whitelist. Details: Blacklist and exception API.

Method Path Description
GET /api/{list} List entries (limit 1 to 1000, default 100; offset; search)
POST /api/{list} Add an entry
DELETE /api/{list}/{id} Delete an entry
POST /api/{list}/bulk-delete Delete entries by ID ({"ids": [...]}, 1 to 1000; data.removed)
DELETE /api/{list}/clear-all Delete every entry (data.removed)
GET /api/{list}/sources Where the entries came from, one row per source
DELETE /api/{list}/sources/{id} Delete the entries one source added ({id} or unrecorded)
GET /api/{list}/export Every entry, one per line, as text
POST /api/blacklists/import Import into the IP or domain blacklist from a URL or pasted content
POST /api/blacklists/import-geo Import countries' IPv4 blocks into the IP blacklist
POST /api/ip-whitelist/import, /api/domain-whitelist/import Add a pasted list to IP exceptions or Domain exceptions as one pasted-list source
GET /api/blacklists/enforcement What enforces each list, from the proxy's records
POST /api/ip-blacklist/import, /api/domain-blacklist/import Retired: 410 Gone, use /api/blacklists/import

Default-deny allowlist

The UI's Default-deny allowlist; the API path is egress-allowlist. Used only while the egress_default_deny setting is true (default false); the setting is changed through POST /api/settings. See Default-deny allowlist and Egress provider lists.

Method Path Description
GET /api/egress-allowlist List manual entries
POST /api/egress-allowlist Add a manual entry ({"entry": "<ip, cidr or domain>", "include_subdomains": <optional, domains only>, "description": "<optional>"})
DELETE /api/egress-allowlist/{id} Delete a manual entry
POST /api/egress-allowlist/bulk-delete Delete manual entries by ID
DELETE /api/egress-allowlist/clear-all Delete every manual entry
GET /api/egress-providers List built-in catalog and custom URL egress provider lists
PUT /api/egress-providers/{name} Enable or disable a provider list (confirm_shared: true required to enable a shared network)
POST /api/egress-providers/url Add and fetch a custom URL provider list ({"label": "...", "url": "..."})
DELETE /api/egress-providers/url/{id} Delete a custom URL provider list and its prefixes
POST /api/egress-providers/{name}/refresh Fetch and validate the provider list now
POST /api/egress-providers/{name}/apply-held Apply a held update for a provider list

Logs and analytics

Details: Logs and Analytics API.

Method Path Description
GET /api/logs Access log rows, with filters (source, outcome, rule, destination, internal traffic) and a cursor
GET /api/logs/export The same rows as streamed CSV
GET /api/logs/stats Total, blocked and direct-IP counts, blocks by rule
GET /api/logs/timeline Requests and blocks per hour (hours, default 24) of the zone tz (default UTC)
POST /api/logs/clear Delete every log row (data.removed)
POST /api/logs/clear-old Delete rows older than days (query parameter, 1 to 3650, default 30; data.removed)
POST /api/counters/reset Delete every log row and reset the WAF's counters
GET /api/status Proxy reachability, version, today's request count, Squid version, CVE count (squid_cves) and whether that major version has an advisory table (cves_checked), update availability
GET /api/dashboard/summary The dashboard's data in one call (top_clients aggregated by network and recent_blocks masked when gdpr_mode is on)
GET /api/clients/statistics Top 50 clients (or /24 and /64 networks when gdpr_mode is on), then the internal sources
GET /api/clients/{ip}/details One client's or /24 / /64 network CIDR's totals, top domains and recent requests; ?window=7d for the last 7 days, all (default) for every request
GET /api/analytics/shadow-it Requests of the last 7 days to known services (file sharing, messaging, AI, social)
GET /api/analytics/user-agents Requests of the last 7 days by method and kind of service
GET /api/analytics/file-extensions Requests of the last 7 days by file extension
GET /api/analytics/top-destinations The 20 hosts the clients asked for most in the last 7 days, internal sources left out, each with requests, blocked, and on_blocklist when the proxy enforces the name from the domain blacklist now (exact name, not on the allowed list)
GET /api/analytics/blocked-by-day Blocked requests per day by rule, today and the 6 days before (tz, default UTC)
GET /api/analytics/cache-by-day What the cache did with the client requests of each day, today and the 6 days before (tz, default UTC): requests and bytes sent per outcome (hit, revalidated, miss, tunnel, refused, other), every outcome present, and the 7 days' totals
GET /api/analytics/coverage Which protections are switched on now: list sizes, WAF rules, HTTPS inspection, alerts and the other access settings
GET /api/audit-log Audit log, newest first, 50 a page (limit up to 200). category = all, changes or signins and q (text in the user, action, target or details) filter on the server; meta.retention_days is 365
GET /api/security/score Retired: 410 Gone
GET /api/security/cve The Squid version (version), whether its major version has an advisory table (cves_checked) and the advisories matched to it (cves)
GET /api/waf/stats WAF statistics (from the WAF)
GET /api/waf/status What the WAF runs: engine, block threshold, regex engine, policy mode, rule counts
GET /api/waf/categories WAF rule categories and whether each is on
POST /api/waf/categories/toggle Turn a category on or off in the running WAF
GET /api/waf/heuristics The heuristics the running WAF applies, or available: false with the reason
POST /api/waf/test-rule Match a Go regular expression against the destinations of recent requests (at most 10,000 read)
GET /api/waf/events/{id} What the WAF reported about one block, by the event_id of its access log row: rules, the ones that added to a score (scoring_rules), categories, host, path, blocked_by (spm or crs), scores and, for a Core Rule Set block, the argument each rule matched (crs_targets). 404 once pruned with the access log
GET /api/waf/policy The WAF policy file, its sha256, and the policy the WAF has in force (waf, in_force)
PUT /api/waf/policy Replace the policy file with {policy, sha256}, sha256 being the digest GET returned; 409 when the file changed since
POST /api/waf/policy/exceptions Add one exception {rule, host?, path?, target?, comment?}
POST /api/waf/policy/observe-rules Leave one rule {rule} to log only
GET /api/waf/trajectories Client trajectories that closed in the last days (1 to 90, default 7), latest first: client_ip, rule (order or breadth), start, closed (when the pattern was complete), end, phases, categories, hosts, signals
GET /api/waf/trajectories/{id} One trajectory and the client's signals in its window (start to 24 hours later), each with at, category, phase, host, rule, observed (Log only) and blocked; at most 500, truncated when there were more

Settings and maintenance

Details: Settings and Maintenance API.

Method Path Description
GET /api/settings Every setting; secrets are write-only
PUT /api/settings/{name} Set one value and write the proxy file it needs
POST /api/settings Store several values and write the proxy files they drive
GET /api/database/size Database size (size_bytes, size_mb)
GET /api/database/stats Row count per table
GET /api/database/export Every table as JSON, password, secret and token columns redacted; client addresses in proxy_logs are unmasked (contains_unmasked_addresses: true when gdpr_mode is on)
POST /api/database/optimize VACUUM and REINDEX
POST /api/database/reset Delete every row of every table except users ({"confirm": "RESET"})
GET /api/cache/statistics Squid cache statistics as the proxy last collected them
POST /api/maintenance/reload-config Export the lists, ask the proxy to regenerate and reload, and report what it did
POST /api/maintenance/reload-dns Export every list again and ask dnsmasq to reload; says how many domain entries the DNS sinkhole got
POST /api/maintenance/clear-cache Clear the Squid cache (see Settings and Maintenance)
GET /api/maintenance/backup-config The settings, the five lists with each entry's sources, the client groups and the WAF policy, as a backup
POST /api/maintenance/restore-config Add what a backup holds
GET /api/maintenance/check-cert-security Whether the CA certificate and the certificate database exist, and whether the CA key is out of /config
GET /api/security/download-ca The SSL-bump CA certificate (/config/ssl_cert.pem)
GET /api/security/rate-limits Failed-login counts per address
DELETE /api/security/rate-limits/{ip} Clear one address's count
GET /api/config/snapshots Configuration history, newest first; current marks the snapshot that holds the configuration in force
POST /api/config/snapshots Take a snapshot now ({note} optional); created is false when the newest already holds it
GET /api/config/snapshots/{id}/diff What restoring the snapshot would change; a secret is named, never shown
POST /api/config/snapshots/{id}/restore Make the configuration the snapshot's exactly, after a snapshot of the one in force (undo_snapshot)
POST /api/log-forward/test Send one test event to the saved log forwarding target now, whether forwarding is on or not; 502 with the reason when it did not go
POST /api/notifications/test Send one test alert to every channel that has all its settings (webhook, Gotify, Telegram, ntfy, Teams), outside the notification limits; data.channels reports each delivery
GET /api/notifications/status For each channel used since the backend started (since, kept in memory): last_attempt, last_delivered, last_error and last_error_at (why the last failed delivery failed, without the URL), last_failed, delivered, failed. Test alerts count

Internal

Method Path Description
POST /api/internal/alert WAF block notifications, on the backend's port only (backend:5000 inside the stack); the web container answers 404 for /api/internal/. With INTERNAL_ALERT_TOKEN set, only Authorization: Bearer <that token> is accepted; without it, normal admin authentication. The alerts pass the notification limits
POST /api/internal/signals The WAF's client signals (the categories in the client trajectory phases), stored and never sent to a channel. Same port and token as /api/internal/alert; the WAF's calls with the token are not counted by the per-address rate limit. Nothing is stored while gdpr_mode is on
POST /api/dns/detect Probe a subnet for Pi-hole or AdGuard instances (at most 2 scans at a time)
GET /debug/pprof/... Go runtime profiles (authenticated)

WebSocket

Path Description
/api/ws/logs Live log feed; offer the subprotocols spm.v1 and spm-ws-token.<token> with a token from /api/ws-token. See WebSocket