szn

Bug 378 — Server socket endpoint steal + permission hardening

378. Concurrent-start steal and umask-dependent permissions

File: src/server/socket.zig:43-58; src/socket_path.zig:34-50 Severity: MEDIUM Status: ✅ FIXED

Fix (applied)

  1. createListener probes the socket path with a unix connect first (connectProbeUnix): a successful connect means another live szn owns the endpoint and startup aborts with error.AddressInUse instead of stealing it; a refused connection means a stale socket from a dead server, safe to replace.
  2. The bound socket file is chmod 0700 after bind regardless of umask, closing the world-connectable /tmp/szn-{uid}.sock fallback hole.

Existing listener/socket tests all pass; probe behaviour exercised implicitly by every test that creates a listener.

Problem

  1. _ = c.unlink(path.ptr) runs unconditionally before bind: starting a second szn while the first is alive rebinds the path out from under the first server, stranding its clients.
  2. In $HOME/.szn or XDG_RUNTIME_DIR the 0700 directory saves us, but the /tmp/szn-{uid}.sock fallback creates the socket under the process umask; containers commonly run umask 000 → any local user can connect and issue command packets.

Fix (proposed)

Bind first and treat EADDRINUSE as “server already running” (probe with a ping before considering takeover); chmod the socket to 0700 explicitly regardless of umask.