This document summarizes the comprehensive fixes made to the ORLY policy system based on Issue #5 requirements and user feedback. The policy system now correctly implements relay access control with predictable, secure behavior.
Problem: The policy system was incorrectly checking if the EVENT AUTHOR was in the allow/deny lists.
Solution: Changed to check the loggedInPubkey (the authenticated user submitting/reading events), not ev.Pubkey (event author).
// Before (WRONG):
if utils.FastEqual(ev.Pubkey, allowedPubkey) {
// After (CORRECT):
if utils.FastEqual(loggedInPubkey, allowedPubkey) {
This correctly implements relay access control (who can authenticate and perform operations), not content validation.
Problem: The privileged flag was incorrectly being applied to both read and write operations.
Solution: Privileged flag now ONLY affects read operations. It allows parties involved in an event (author or p-tagged users) to read it, but doesn't restrict who can write such events.
Problem: When both read_allow and privileged were set, the allow list was overriding privileged access, blocking involved parties.
Solution: Implemented OR logic for read access - users can read if they are:
read_allow list, ORProblem: All kinds were allowed by default even when specific rules existed.
Solution: Kinds with defined rules are now implicitly whitelisted. If specific rules exist, only kinds with rules are allowed. This provides automatic kind filtering based on rule presence.
Problem: Unauthenticated users could access certain content.
Solution: Added blanket rejection of all unauthenticated requests at the beginning of policy evaluation. No authentication = no access, regardless of policy rules.
1. Authentication Check
- Reject if no authenticated pubkey
2. Global Rules (if configured)
- Skip if no global rules exist
3. Kind Whitelist/Blacklist
- Explicit whitelist/blacklist if configured
- Implicit whitelist based on rule presence
- Allow all if no rules defined
4. Script Execution (if configured and enabled)
5. Rule-based Filtering:
a. Universal Constraints (size, tags, timestamps)
b. Explicit Denials (highest priority)
c. Read Access (OR logic):
- With allow list: user in list OR (privileged AND involved)
- Without allow list but privileged: only involved parties
- Neither: continue to other checks
d. Write Access:
- Allow lists control submitters (not affected by privileged)
- Empty list = allow all
- Non-empty list = ONLY those users
e. Deny-Only Lists (if no allow lists, non-denied users allowed)
f. Default Policy
[]string{}): ALL authenticated users can perform the operationhasAnyRules() check to skip when no global rules configured[]string{}) being treated as "no one allowed"- Submitter-based access control (not author-based) - Privileged read-only behavior - OR logic for read access - Authentication requirement - Implicit kind whitelisting
/pkg/policy/policy.go - Core implementation fixes/pkg/policy/policy_test.go - Updated tests for correct behavior/pkg/policy/comprehensive_test.go - New test for all 5 requirements/pkg/policy/precedence_test.go - New test for evaluation order/pkg/policy/read_access_test.go - Updated for OR logic/pkg/policy/policy_integration_test.go - Updated for privileged behavior/docs/ - Comprehensive documentationThe policy system now provides:
All 5 requirements from Issue #5 are now correctly implemented and verified.