Issue: Kind 1 events were being accepted even though the policy whitelist only contained kind 4678.
The relay had TWO critical bugs in the policy system that worked together to create a security vulnerability:
return true in checkKindsPolicy()Location: `pkg/policy/policy.go:1010`
// BEFORE (BUG):
// No specific rules (maybe global rule exists) - allow all kinds
return true
// AFTER (FIXED):
// No specific rules (maybe global rule exists) - fall back to default policy
return p.getDefaultPolicyAction()
Problem: When no whitelist, blacklist, or rules were present, the function returned true unconditionally, ignoring the default_policy configuration.
Impact: Empty policy configurations would allow ALL event kinds.
Location: `pkg/policy/policy.go:363-378`
// BEFORE (BUG):
if err := policy.LoadFromFile(configPath); err != nil {
log.W.F("failed to load policy configuration from %s: %v", configPath, err)
log.I.F("using default policy configuration")
}
// AFTER (FIXED):
if err := policy.LoadFromFile(configPath); err != nil {
log.E.F("FATAL: Policy system is ENABLED (ORLY_POLICY_ENABLED=true) but configuration failed to load from %s: %v", configPath, err)
log.E.F("The relay cannot start with an invalid policy configuration.")
log.E.F("Fix: Either disable the policy system (ORLY_POLICY_ENABLED=false) or ensure %s exists and contains valid JSON", configPath)
panic(fmt.Sprintf("fatal policy configuration error: %v", err))
}
Problem: When policy was enabled but policy.json failed to load:
Impact: Critical security vulnerability - misconfigured policy files would silently allow all events.
When a relay operator:
ORLY_POLICY_ENABLED=true)policy.json fileThe relay would:
return true (Bug #1)default_policy SettingChanged checkKindsPolicy() to return p.getDefaultPolicyAction() instead of hardcoded true.
Result: When no whitelist/rules exist, the policy respects the default_policy configuration (either "allow" or "deny").
Changed NewWithManager() to panic immediately if policy is enabled but config fails to load.
Result: Relay refuses to start with invalid configuration, forcing operator to fix it.
Policy System: ENABLED ✅
Config File: MISSING ❌
Logs: "failed to load policy configuration" (warning)
Result: Allow ALL events 🚨
Policy System: ENABLED ✅
Config File: { "whitelist": [4678] } ✅
Logs: "policy allowed event" for kind 1
Result: Allow kind 1 event 🚨
Policy System: ENABLED ✅
Config File: MISSING ❌
Result: PANIC - relay refuses to start 🛑
Policy System: ENABLED ✅
Config File: { "whitelist": [4678] } ✅
Logs: "policy rejected event" for kind 1
Result: Reject kind 1 event ✅
Error Message:
FATAL: Policy system is ENABLED (ORLY_POLICY_ENABLED=true) but configuration failed to load
panic: fatal policy configuration error: policy configuration file does not exist
Resolution Options:
`bash
mkdir -p ~/.config/ORLY
cat > ~/.config/ORLY/policy.json << 'EOF'
{
"default_policy": "allow",
"kind": {
"whitelist": [1, 3, 4, 5, 6, 7]
},
"rules": {}
}
EOF
`
`bash
# In your systemd service file:
Environment="ORLYPOLICYENABLED=false"
sudo systemctl daemon-reload
sudo systemctl restart orly
`
Severity: 🔴 CRITICAL
CVE-Like Description:
When ORLY_POLICY_ENABLED=true is set but the policy configuration file fails to load (missing file, permission error, or malformed JSON), the relay silently bypasses all policy checks and allows events of any kind, defeating the intended access control mechanism.
Affected Versions: All versions prior to this fix
Fixed Versions: Current HEAD after commit [TBD]
CVSS-like: Configuration-dependent vulnerability requiring operator misconfiguration
To verify the fix is working:
`bash
# Should start normally
ORLYPOLICYENABLED=true ./orly
# Logs: "loaded policy configuration from ~/.config/ORLY/policy.json"
`
`bash
# Should panic immediately
mv ~/.config/ORLY/policy.json ~/.config/ORLY/policy.json.bak
ORLYPOLICYENABLED=true ./orly
# Expected: FATAL error and panic
`
`bash
# Create whitelist with only kind 4678
echo '{"kind":{"whitelist":[4678]},"rules":{}}' > ~/.config/ORLY/policy.json
# Try to send kind 1 event
# Expected: "policy rejected event" or "event blocked by policy"
`
Bug Reported By: User via client relay (relay1.zenotp.app)
Root Cause Analysis: Deep investigation of policy evaluation flow
Fix Verified: All tests passing, including reproduction of original bug scenario