Input validation, access control, authentication, and sandboxing.
- Auth (
auth.rs) — JWT token generation/validation, API key management, session management with scopes - Pairing (
pairing.rs) — Device pairing and DM policy - Device Pairing (
device_pairing.rs) — Challenge-based device pairing with QR codes and setup URLs - Allowlist (
allowlist.rs) — Multi-dimensional allowlist matching with compiled cache - Tailscale Auth (
tailscale.rs) — Tailscale whois verification with caching - Trusted Proxy (
trusted_proxy.rs) — IP whitelist/CIDR, required headers, user extraction - Runtime Audit (
runtime_audit.rs) — Audit logging for auth and security events - Content Filter (
content_filter.rs) — Secret scanning and PII detection in outputs - Sliding Window (
sliding_window.rs) — Rate limit tracking with lockout
NameValidator— Tool name length, character set, prefix rulesSchemaValidator— JSON Schema structure (type: object, properties required)SecurityValidator— Path traversal and command injection detection
pub struct AuthManager {
users: Arc<RwLock<HashMap<UserId, User>>>,
sessions: Arc<RwLock<HashMap<String, Session>>>,
pairing_required: bool,
audit_log: Option<Arc<dyn AuditLogger>>,
}
pub struct User {
pub id: UserId,
pub name: String,
pub created_at: chrono::DateTime<chrono::Utc>,
pub is_admin: bool,
pub scopes: Vec<String>,
pub metadata: HashMap<String, String>,
}
pub struct Session {
pub token: String,
pub user_id: UserId,
pub created_at: chrono::DateTime<chrono::Utc>,
pub expires_at: chrono::DateTime<chrono::Utc>,
pub device_fingerprint: Option<String>,
pub scopes: Vec<String>,
}- Auth mode ambiguity detection — fails fast when both
shared_tokenand OAuth are configured butauth_modeis not set - Tailscale authentication —
TailscaleAuthenticatorwith whois verification via CLI, caching, and tailnet-based authorization - Full allowlist system with multi-dimensional matching — 10 match sources (Id, Username, Name, Tag, E164, PrefixedId, PrefixedUser, PrefixedName, Slug, Localpart), compiled
HashSetcache, wildcard*support, account-scoped storage with file locking - SecretRef resolution system — three providers (
env,file,exec) withSecretResolver::resolve() - Multi-scope rate limiting —
MultiTierRateLimiterincludesglobal/per_user/per_ip/per_endpoint/shared_secret/device_token/hook_auth/control_plane_writetiers, lockout tracking, attempt serialization, and loopback exemption - Device pairing challenge —
DevicePairingStoregenerates 8-character unambiguous codes, enforces a max pending limit, produces QR codes andsyscity://pair/{code}URIs, and supports base64url setup URLs - Secret resolution cache —
SecretResolverkeeps per-provider payload caches (env, file, exec) and a per-reference result cache with TTL, plusrefresh()andrefresh_reference()for manual invalidation - Audit logging for auth events —
AuditEventTypeincludesLogin,Logout, andTokenValidation;AuthManageremits events via an attachedAuditLoggeroncreate_session,validate_session, andrevoke_session - Trusted proxy authentication — IP whitelist/CIDR, required headers, user extraction, allowUsers whitelist, audit logging
- Credential precedence —
env_firstvsconfig_firstfor token/password sources.CredentialPrecedenceenum applied indaemon.rs:apply_env_security_overrides()andapply_env_provider_overrides() - Secret scanning in tool outputs —
ContentFilterwithSecretScannerandPiiDetectorwired intoToolRegistryduringGateway::new() - Kernel write fences for workspace-only command tools —
shell/process/code_execattach aWriteFence(workspace root + allowed paths) to theProcessRequestwhenworkspace_onlyis set (src/tools/process_runner.rs), turning the parent-side path check into a kernel-enforced deny of all file writes outside the workspace: macOS Seatbelt (argv wrapped behind/usr/bin/sandbox-exec, plus process-group kill so the forked sandboxed grandchild can't outlive a timeout), Linux Landlock (in-placerestrict_selfviapre_exec, write rights only — reads/exec/network stay unrestricted), Windows AppContainer + Job object (src/tools/win_appcontainer.rs— Low-integrity token, DACL grant + mandatory Low label on the workspace,KILL_ON_JOB_CLOSEwhole-tree termination). All three fail closed withProcessError::Sandboxwhen the platform sandbox is unavailable - Canonical secret masking —
src/secrets/mask.rs(mask_json_value/mask_secret) is the single walker behind every config-describe surface (REST config handler, theconfig.get/config.schema.lookupgateway tools,models.list), so provider keys, channel credentials, andsecurity.shared_tokenare never returned in plaintext; WSconfig.setsupportsbase_revisioncompare-and-swap (REVISION_CONFLICTon stale writes) - JWT session management with scope-based access control
- User registration and lookup with admin flag support