#9040: fix(security): throw on config validation failure instead of returning empty config
stale
Cluster:
Gateway Hot-Reload Improvements
## Security Issue
Fixes #5052
When `loadConfig()` failed validation (e.g., due to invalid plugin references), it returned `{}` instead of propagating the error. This caused all security settings to fall back to permissive defaults:
- `dmPolicy` defaulted to `"pairing"` — any sender could get a pairing code
- `allowFrom` was ignored — allowlist protection bypassed
- `groupPolicy` was ignored — group restrictions bypassed
## Root Cause
```typescript
} catch (err) {
if (error?.code === "INVALID_CONFIG") {
return {}; // ← Security settings wiped
}
return {}; // ← Also on read errors
}
```
## Fix
Throw the error instead of returning empty config:
```typescript
} catch (err) {
if (error?.code === "INVALID_CONFIG") {
// SECURITY: Do not return {} on validation failure.
throw err;
}
// SECURITY: Do not return {} on read failure either.
throw err;
}
```
## Impact
**BREAKING CHANGE**: `loadConfig()` now throws on validation failure instead of returning `{}`.
- Gateway startup already handles this correctly (refuses to start with invalid config)
- Runtime callers must now handle the exception
- This is intentional — operating with no security is worse than crashing
## Compatibility with #9036
This pairs well with PR #9036 (systemd restart limits). If config is invalid:
1. Gateway throws and refuses to start
2. Systemd restarts it (up to 5 times in 5 minutes)
3. After hitting the limit, manual intervention required
This is the correct fail-closed behavior for a security-critical system.
Most Similar PRs
#19510: fix(config): preserve configured values on invalid config validatio...
by yash27-lab · 2026-02-17
71.7%
#22227: fix(security): harden gateway auth — audit logging, pairing, mode v...
by novalis133 · 2026-02-20
63.6%
#22720: fix: notify sessions on invalid config during hot-reload
by jayleekr · 2026-02-21
63.3%
#23779: fix(config): auto-repair invalid config keys from backup on load
by cintia09 · 2026-02-22
62.5%
#21931: feat(config): auto-rollback to last known-good backup on invalid co...
by Protocol-zero-0 · 2026-02-20
62.4%
#23719: Gateway: fail closed startup on insecure state/config permissions
by bmendonca3 · 2026-02-22
61.7%
#21100: Security/Gateway: require explicit break-glass env for Control UI b...
by bmendonca3 · 2026-02-19
61.4%
#19670: fix(config): guard config.apply against catastrophic key loss
by nabbilkhan · 2026-02-18
61.4%
#5823: fix(config): exit cleanly on invalid config instead of high CPU loop
by gavinbmoore · 2026-02-01
61.3%
#22766: fix(security): enable gateway auth rate limiting by default (CWE-307)
by brandonwise · 2026-02-21
61.2%