Skip to content

Security

root edited this page Dec 4, 2026 · 5 revisions

Security Model

🌐 English · 简体中文

This page documents Trizano's identity authentication, device pairing, session tickets, proxy isolation, Node channel permissions, and threat model. It is intended for operators evaluating self-hosted exposure and troubleshooting auth issues. Trizano is a personal self-hosted tool: its security model favors clear, auditable boundaries without heavy external dependencies—stating explicitly what it defends against and what it does not.

Hub Identity Key and Hello Pinning

Each Hub generates a long-term ECDSA P-256 identity private key on first startup, stored in <data>/identity.pem (PKCS#8 PEM, mode 0600; see server/hub/auth/auth.go). The first 16 hex characters of the SHA-256 of its SPKI DER public key form its instance_id.

The Hub proves possession of this key via the public RPC AuthService.Hello(nonce): it signs "trizano-hello-v1\n" || b64(nonce) || "\n" || ts with its identity private key and returns its public key, millisecond timestamp, and signature.

  • Android and desktop: During initial pairing, the client verifies the Hello signature and pins the Entry's public key. Thereafter, before sending a session ticket to any Entry for the first time in a process, it calls Hello and requires the returned public key to match the pinned key (or that Entry's key in the Roster) with a timestamp within 5 minutes of local time. If verification fails, the ticket is never sent.
  • Browser: Relies on HTTPS same-origin enforcement and the browser TLS certificate store rather than Hello key pinning.

Device Pairing and 6-Digit Codes

Device pairing three-step flow

New devices cannot self-register; every device must be explicitly approved by you via a 6-digit verification code before entering the Roster (server/hub/auth/pairing.go):

  1. The client calls AuthService.StartPairing with a device name and credential type (passkey or device_key), receiving a pairing ID, a random 6-digit code, and proof parameters (WebAuthn creation options or a 32-byte challenge).
  2. The client completes the local proof and submits its signature or passkey credential via AuthService.FinishPairing. Only proven pairings (proven = true) can be approved. The Hub logs the source IP, the 6-digit code, and the approval command trizano-carbon approve <code>.
  3. You click Approve on the pairing card in any already-signed-in device, or run trizano-carbon approve <code> on the Hub host.
  4. The client long-polls AuthService.AwaitPairing (up to 25 s per poll) to collect SignIn. The device is signed into the Roster only at the moment it claims the login result—an approved pairing that is never claimed expires cleanly without leaving a Roster entry.

Rate limits and anti-phishing differences between device pairing and Node/Entry enrollment:

Dimension Device Pairing (server/hub/auth/pairing.go) Node / Entry Enrollment (server/hub/enrollment.go)
Lifetime 3 minutes 3 minutes
Concurrency & rate limits Up to 3 pending concurrently; up to 10 starts per 10 minutes Up to 5 proven pending, 20 global per 10 minutes; up to 64 unproven in memory, 10 per IP per 10 minutes; 8 KiB body cap
6-digit code visibility Returned on the approval UI so you can compare and click Approve Public ListNodeEnrollments and the event stream never return the 6-digit code—you must type the code displayed in the Node terminal manually into the web/Android approval card (invalidated after 5 consecutive wrong guesses) to prevent misclicks and phishing approvals; only local admin.sock returns the code for trizano-carbon pairings
Code collision prevention Device pairings and enrollments share deduplication checks so active codes never collide Same

Two Device Sign-In Methods

After a paired device's ticket expires or you sign out, you can sign back in with the original credential (StartLogin challenges expire in 2 minutes) without re-pairing:

  • Browser Passkey (WebAuthn): Both registration and login enforce ResidentKey = required and UserVerification = required (verified via Touch ID, fingerprint, Windows Hello, or another platform authenticator). Each passkey represents a separate device (user handle is the device ID), login uses discoverable credentials with no username prompt, and the Roster stores a frozen copy of the credential JSON without updating sign counts on subsequent logins. WebAuthn RPID is derived from the --origin hostname and requires a secure context that is not a bare IP address—so local browser access must use http://localhost:<port> (not 127.0.0.1), and remote access must use HTTPS with --origin configured.
  • Device Key Signature (Android and desktop): Uses a local P-256 key pair, signing trizano-pair-v1\n{pairing}\n{b64(challenge)} during pairing and trizano-login-v1\n{login}\n{b64(challenge)} on login. Android stores the private key in the Android Keystore requiring BIOMETRIC_STRONG or DEVICE_CREDENTIAL via BiometricPrompt for every signature. Desktop stores the private key in device_key.pem inside its application data directory (without biometric gating).

Session Tickets, Renewal, Logout, and Revocation

After pairing or sign-in succeeds, the Entry signs a self-contained trizano.roster.v1.Ticket with its identity.pem (server/internal/roster/ticket.go, server/hub/auth/auth.go):

  • Format and lifetime: Encoded as tt1.<base64url(body)>.<base64url(sig)>, containing the device ID, issuing Entry public key, issued-at and expiry timestamps, and a 16-byte random ID, valid for 30 days. Clients send it via Authorization: Bearer <ticket> or the browser cookie trizano_session (HttpOnly; SameSite=Strict, plus Secure over direct TLS or when a reverse proxy sets X-Forwarded-Proto: https).
  • Automatic renewal: Once an authenticated request verifies a ticket older than 24 hours, the serving Entry automatically mints a fresh ticket and returns it in the X-Trizano-Token response header (and a refreshed Set-Cookie when authenticated via cookie). Event streams and WebSockets deliver renewed tickets in their handshake response headers. Android and the desktop local proxy automatically persist renewed tickets from X-Trizano-Token. Legacy 32-byte random tokens remain accepted during transition and are upgraded to tt1. tickets via X-Trizano-Token on every request.
  • Logout (AuthService.Logout): Records the ticket's 16-byte random ID in the current Entry's hub.db ticket_logouts table (retained until the ticket's expiry and pruned on Hub startup) and clears the browser cookie. Logout applies only to the current Entry and is not replicated to other Entries.
  • Revocation (RevokeDevice / trizano-carbon revoke): Signs a Roster Remove statement for the device. Once removed:
    1. The local Entry deletes any legacy tokens for that device and calls Auth.Cut to cancel all of its active request contexts, immediately closing event streams and terminal/preview/browser WebSockets; all future requests with its tickets return Unauthenticated.
    2. As soon as the Roster syncs to other Entries, they run the exact same cutoff logic.

Additionally, server/hub/webui/webui.go serves static frontend /assets/* with Cache-Control: private, max-age=31536000, immutable and index.html with no-cache to prevent shared proxy caching. Source IP extraction (clientAddr) inspects the rightmost valid IP in X-Forwarded-For only when the TCP peer is loopback (a local reverse proxy or tunnel), ignoring forwarding headers on non-loopback peers. Source IPs are used strictly for logging and rate limiting—never for authorization.

Unauthenticated Endpoints and Proxy Security Boundaries

The Hub auth middleware (server/hub/hub.go) is default-deny: except for explicitly exempted public paths, every /trizano.* and /nodes/* request must carry a valid device ticket.

Unauthenticated Paths

Path Purpose & built-in protections
/trizano.hub.v1.AuthService/* Hello, pairing, login, logout, and Me (Me validates the ticket internally)
/trizano.hub.v1.NodeEnrollmentService/* Reverse Node and new Entry enrollment plus connect handshakes; 8 KiB body cap with per-IP and global rate limits
/trizano.hub.v1.EntryService/* Entry-to-Entry SyncRoster; 4 MiB body cap, ±5 min timestamp check, P-256 signature bound to the receiver's public key, and active ROLE_ENTRY Roster membership check
GET /nodes-connect Reverse Node WebSocket endpoint; atomically consumes a one-time challenge before upgrade (30 s TTL, caps of 8 per Node, 1024 global, 60/min per IP) and verifies the Node signature, then runs mutual TLS 1.3 pinned to both P-256 keys inside the WebSocket (ALPN trizano-node-h2)
Paths outside /trizano. and /nodes/ Embedded static Web UI assets

Proxy 403 Deny List and Node Response Isolation

Every client request routed to /nodes/{node}/<procedure> passes through two isolation layers in server/hub/nodes/registry.go:

  1. Blocked external paths (always return 403):

    • /nodes/{node}/internal/* (prevents clients from impersonating agents calling internal orchestration endpoints)
    • SystemService/Shutdown (restricted strictly to the Node's local owner channel run/node.sock)
    • SystemService/OpenControlBridge (restricted to the Hub itself for cross-Node control bridges)
    • SystemService/SyncRoster (restricted to the Hub itself for Roster synchronization)
    • SystemService/InstallBuild (restricted to the Hub itself for pushing builds to Reverse Nodes)
  2. Credential stripping and response sandboxing:

    • Before forwarding any request to any Node (local, SSH, or Reverse), the Hub strips Authorization and Cookie headers so a compromised Node cannot steal device tickets or session cookies.
    • On responses returning from a Node, the Hub strips Set-Cookie and X-Trizano-Token (preventing a malicious Node from tampering with sessions or injecting forged tickets) and overwrites three security headers:
      • X-Content-Type-Options: nosniff
      • Content-Security-Policy: sandbox; default-src 'none'; img-src 'self' data:; media-src 'self'; style-src 'unsafe-inline'
      • Cross-Origin-Resource-Policy: same-origin

    This ensures that even a compromised Node serving malicious HTML/JS over /raw or /media cannot execute script in the Hub's origin.

Local and Agent Channel Isolation

  • Hub management channel: <data> is created with mode 0700 and holds admin.sock, relying on OS user isolation instead of a static admin password.
  • Node dual-socket isolation (server/node/daemon.go):
    • Owner channel ~/.trizano/node/run/node.sock (0600): Serves attach, stop, and trizano-h3 admin. Only requests arriving on this socket carry the owner marker required for SystemService.Shutdown or initially setting the Roster root.
    • Agent orchestration channel ~/.trizano/node/orch/s.sock (0600): A separate OrchHandler() exposes only POST /internal/orch/{method} (2 MiB body cap); neither the owner socket nor Reverse connections mount this route. At startup, the daemon copies itself to orch/trizano-h3 (0700) so sandboxed agents only need orch/ mounted to invoke the orchestration CLI—with no access to run/node.sock, state.db, or node_key.pem.
  • Per-session HMAC tokens (server/node/session/token.go): On every startup, the Node generates a 32-byte in-memory secret and issues mc_<base64url(session|hop)>.<HMAC-SHA256> via TRIZANO_SESSION_TOKEN to each agent process. Every /internal/orch/* request is verified in constant time, preventing a subprocess from spoofing another Session's identity or altering its cross-Node hop count (capped at MaxCrossNodeHops = 1). Read-only Sessions and Discussion Room participants are also blocked from write orchestration calls.
  • Desktop local proxy: 127.0.0.1:47801 permits only matching Host and Origin headers (blocking DNS rebinding and cross-site requests), and /_desktop/* control endpoints require the per-launch random X-Trizano-Desktop-Secret.

Threat Model: What It Defends Against and What It Does Not

Understanding these boundaries matters more than stacking complex defenses.

Defends Against

  • Unauthorized external access and brute-force pairing: No Node or Session data is reachable without a valid ticket. Pairings and enrollments have 3-minute lifetimes plus concurrency and rate limits, and Node/Entry enrollments additionally require manually copying the 6-digit code.
  • Cross-site requests and DNS rebinding: Browser cookies use HttpOnly; SameSite=Strict, WebSockets enforce Origin, and the desktop local proxy enforces Host, Origin, and a per-launch random secret.
  • Eavesdropping on Reverse Nodes by outer proxies or plain-HTTP LANs: Reverse Nodes wrap traffic in mutual TLS 1.3 pinned to both P-256 public keys inside the WebSocket. Even over a third-party tunnel or --allow-insecure-http, intermediaries cannot decrypt or tamper with Node traffic.
  • A compromised Node stealing credentials or attacking the Hub origin: Nodes never see device tickets; the Hub strips auth headers on requests, enforces CSP sandboxing on Node responses, and confines each Node to a single backend slot.
  • Prompt-injected sandboxed agents escaping to take over the Node: A sandboxed agent sees only orch/, cannot reach run/node.sock, cannot shut down the daemon, cannot forge another Session ID, and cannot recurse indefinitely across Nodes.

Does Not Defend Against

  1. Entries are fully trusted by browsers: A malicious Entry can serve arbitrary frontend code to a browser and perform any action as the signed-in user. Deploy Entries only on machines you trust.
  2. Entries trust each other in a multi-Entry group: Every Entry in the Roster can admit new devices/Nodes and issue valid tickets. If an Entry is compromised, remove it from another Entry; if you suspect it admitted unauthorized members, run trizano-carbon roster reset on the root Entry to start a new epoch.
  3. Unsandboxed agents have the same privileges as the Node's OS user: Both the Node daemon and agents run under your regular OS user account. An agent running without a sandbox can read/write local files and connect to run/node.sock directly; orch/ isolation protects against sandboxed agents escalating privileges.
  4. Every signed-in device is an administrator: There is no multi-tenancy or role-based access control. Any signed-in device can approve pairings, revoke devices, add/approve Nodes, and edit model pricing.
  5. Approving a Node trusts its cross-Node delegation capability: Any approved Node can initiate a one-hop delegation call to itself or any other online Node over its control bridge (MaxCrossNodeHops = 1 prevents loops, not single-hop target selection).
  6. SSH connections can be reused by the same OS user: Non-Windows Hubs enable ControlMaster=auto / ControlPersist=10m, so other processes running as the same OS user on the Hub machine can reuse control sockets under <data>/ssh/.
  7. Session tickets are 30-day bearer credentials: A stolen ticket can be used until it expires. To cut it off everywhere, revoke the device on any Entry (calling Logout only invalidates the ticket on that single Entry).
  8. The Roster is eventually consistent: During a network partition, an isolated Entry learns of a device or Node removal only after connectivity returns and Roster sync completes, at which point it immediately cuts active connections.

Reporting Vulnerabilities

If you discover a security vulnerability, please do not open a public issue. Report it privately through GitHub's Private vulnerability reporting on the repository. Security fixes are provided for the latest released version.

Clone this wiki locally