Files
honk/.agents/rules/security.md
T

8.9 KiB

Security considerations

Read with: AGENTS.md (Runtime invariants: Bypass mark, Netns discipline, NFQUEUE ownership); deployment.md; configuration.md for the settings named here.

  • Root/privileged execution: honk-core requires root for the operations listed under deployment.md.
  • Clash API secret: when experimental.clash_api is enabled, set a strong secret; the REST/WS API has no TLS of its own — bind to localhost or front it with a reverse proxy.
  • Native API: credentials and HTTP boundaries are independent of Clash. Every API request needs a credential, including same-origin UI requests, except discovery (GET /api) and, in password mode, POST /api/v1/auth/setup and /auth/login. The credential is the configured bearer secret, or in password mode (password_auth, empty secret) a session issued by setup or login; anonymous mode must be explicitly enabled on loopback with an empty secret, and never accepts invalid credentials. An admitted request, bearer, session or explicit anonymous loopback, is an administrator and reads the same data. Setup admits only loopback and private (RFC 1918, ULA, link-local) peers taken from the accepted socket, never from forwarded headers; do not proxy setup from a public network. Passwords are stored only as PBKDF2-HMAC-SHA256 in the state db's admin row (strict: a corrupt db refuses startup; first setup is an INSERT that never replaces, and a failed write blocks login until restart), and honk-core admin reset deletes the row only while no process holds the shared lock on state/; sessions are kept as digests in memory and never logged. Host/Origin allowlists use canonical authorities and explicit origins, not forwarded headers. Public UI assets still require the deployment boundary. Native HTTP has no TLS; do not expose anonymous loopback via a proxy or call non-loopback plaintext bearer secure. API request logs contain templates, method/status/time and generated IDs, never raw paths, queries, tokens, bodies or engine errors. Credential state locks never span KDF/SQLite; the single blocking job retains admission and outcome after HTTP cancellation and is joined on shutdown. Indeterminate writes cannot reopen setup. Admin reset takes the exclusive directory lock before database absence checks.
  • Native source writes: whole-source administration is privileged and requires a nonempty configured secret or password login. An admitted request reads configuration content, rule values, provider and geodata URLs and file paths in the clear; only listener-secret values (native_api.secret, clash_api.secret) are masked by value, and masked content is never offered as editable text. Writes refuse content holding a value from the same set the listing masks; values shorter than eight bytes are neither masked nor refused. Native settings, Clash secret and credential-source membership/bytes cannot be changed through API writes. Stored geodata URLs are the exception to reading in the clear: they need an authenticated caller to change, the anonymous loopback principal reads them without userinfo, query or fragment, as does every reader of fetched_url_redacted. Probes, geodata and shared downloads use configured targets without an address or port allowlist. Whoever can write the configuration or control subscription content decides those targets; provider content is trusted configuration. Native probes use only accepted configuration targets; preserve resolution, normalization, selected-IP pinning, configured Host/SNI and the refusal of caller URLs and redirects. Open parents/files without symlink traversal; retain the parent FD, preserve mode, write/fsync an exclusive temporary, recheck target identity/hash and dependency topology/bytes after candidate validation, then renameat and fsync the directory. External editors remain uncoordinated between the final check and rename. Distinguish pre-rename failure from visible-but-not-durable replacement; never claim rollback after rename. Keep accepted operations daemon-owned across HTTP cancellation and replay retained idempotency keys before disk preconditions. Database startup and API import compare fresh source parses after reconciling only generated group/provider UUIDs and parse timestamps. Derived node IDs and all configured dial, group and fetch values remain checked; do not replace this with runtime-node rebasing or weaken the secret-stripping comparison.
  • State db: <data_dir>/state/honk.db (state.rs) is a 0600 regular file in a 0700 directory, both owned by the euid and opened without following symlinks; the SQLite path is checked against the opened inode, and the checks use an O_PATH descriptor because closing any other descriptor of the file drops every POSIX lock the process holds on it, SQLite's included, and SQLite gives -wal/-shm the file's mode. A daemon holds a shared flock on state/ while the db is open. Listener secrets never enter revisions, responses, the API export or logs, and store errors log only the SQLite result code. Import and every write refuse a source whose content or name still carries a masked listener secret value, one of eight bytes or more. The CLI export reads the db through a query_only connection that is read-write without create, so a hot rollback journal can be rolled back, and sets SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE, so closing never checkpoints or deletes the -wal; it publishes a complete 0600 file by hard link, never replacing an existing one. Sync the state directory's parent before strict writes can acknowledge creation or remove imported originals. Subscription enabled-set publication is fenced through body eviction/deletion commit; release that fence before vacuum. Native catalog and counter displays use the canonical accepted-source listener-secret mask, including shadowed declarations; never mask opaque IDs or serialize unmasked snapshot pages.
  • Native diagnostics and logs: probes use accepted configuration targets without address or port policy checks and pin the resolved address through marked transport admission. Never fall back around a typed refusal or report discarded health publication as accepted. Native logs capture structured audited fields, withholding untrusted message/Debug/Display values rather than formatting and trying to redact them. Group source ETags are accepted configuration revisions, not disk-content hashes; recheck them under reload publication ownership.
  • Native entry management: entry creation/deletion is main-source administration, never a mutable registry shortcut. Preserve exact-source permission, candidate validation, revision/byte fences and truthful post-rename errors. Geo updates use credential-free final HTTP(S) URLs from configuration, stored overrides or built-in sources; all bytes are validated before replacements and passed immutably into activation. Preserve original no-symlink FD authority before canonical identity comparison. Partial multi-asset replacement is possible and must be reported, not rolled back or labeled unwritten. Geo HTTP drivers are explicitly joined and sockets marked; no system resolver fallback or redirects. Embedded UI is pinned licensed static content, not an unaudited runtime download; retain matching source and dependency/font notices with distributions.
  • Config trust: treat config/BPF objects as privileged input. honk-core writes /proc/sys directly and loads configured/CLI BPF paths. Netns/link/routes/rules use rtnetlink and an FD-owned namespace, requiring no external ip/nsenter.
  • Bypass mark discipline: use the effective process global.so_mark_from_dae (zero selects DAE_BYPASS_MARK, 0x100) on originated sockets and transparent listeners. Nonzero direct rules use their low-30-bit mark plus CLASSIFIED_MARK, never the global bypass value; WAN bypass accepts exact configured marks or classified-without-pending marks. Policy routing must mask user marks with 0x3fffffff. Missing marks loop gateway traffic.
  • NFQUEUE ownership: host-netns firewall automation must honor crates/honk-nfqueue's exact-name/no-bypass rules while enabled. Mutation can fail closed or violate held-skb lifecycle assumptions.
  • Subscription store trust: bodies live in the state db (subscription/store.rs, put_body is the only write path and enforces the 32 MiB total). The one-time .sub import reads a legacy directory through a validated directory FD: reject foreign-owned or group/other-writable directories and files, open them without following the final symlink, validate ownership and regular-file type on the opened FD, and unlink through the same FD after the instance lock. Never replace descriptor-relative operations with fresh pathname resolution. Native dependency labels such as state/honk.db#subscription/<key> identify rows, not openable files. Keep subscription byte/reader recapture before geodata replacement; never apply filesystem inode guards to those labels or drop them from the final dependency comparison.