#23719: Gateway: fail closed startup on insecure state/config permissions
gateway
size: M
trusted-contributor
## Summary
Reopening the startup fail-closed hardening as a fresh PR because #23438 could not be reopened via GitHub API.
- refuse startup when state/config/env/credential permissions are group/world readable
- provide actionable remediation path via `openclaw doctor --fix`
Supersedes: #23438
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Added startup permission safety check that prevents the gateway from starting when state/config/env/credential files have insecure group or world read/write permissions. The check runs early in the gateway startup sequence (after config validation but before plugin auto-enable) and throws a descriptive error with remediation instructions pointing to `openclaw doctor --fix`. The implementation reuses the existing `inspectPathPermissions` and permission auditing infrastructure from `src/security/audit-fs.ts`, and recursively scans all credentials directory contents. Tests cover the happy path (secure permissions), world-readable config, and group-readable credentials scenarios on POSIX systems.
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge with minimal risk
- The implementation follows established patterns in the codebase, reuses well-tested permission checking infrastructure, includes proper test coverage, and provides clear error messages with actionable remediation. The fail-closed approach is conservative and appropriate for security hardening. The integration point in server startup is correct (after config validation, before plugin processing), and the doctor --fix command already supports permission fixes.
- No files require special attention
<sub>Last reviewed commit: e688d32</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#23780: Gateway: fail closed on insecure state directory permissions
by bmendonca3 · 2026-02-22
93.4%
#23364: Gateway: add risk-ack interlock for dangerous Control UI flags
by bmendonca3 · 2026-02-22
80.7%
#11455: fix(gateway): default gateway.mode to local when unset
by AnonO6 · 2026-02-07
78.4%
#21120: Security/Gateway: guard dangerous HTTP /tools/invoke re-enables
by bmendonca3 · 2026-02-19
78.4%
#21100: Security/Gateway: require explicit break-glass env for Control UI b...
by bmendonca3 · 2026-02-19
78.2%
#12234: gateway: incident tracking, recover command, and ciao ERR_SERVER_CL...
by levineam · 2026-02-09
77.5%
#23814: Gateway: block unauthenticated tool-invocation HTTP surfaces
by bmendonca3 · 2026-02-22
76.1%
#9460: fix(gateway): clean up lock file on service stop
by zenchantlive · 2026-02-05
75.9%
#8478: Security: remove --allow-unconfigured from default Dockerfile CMD
by uttej-badwane · 2026-02-04
75.8%
#8260: fix(macOS): gateway readiness detection + reversible Configure later
by xksteven · 2026-02-03
75.7%