phoenix-authorization-patterns
Installation
SKILL.md
Phoenix Authorization Patterns
RULES — Follow these with no exceptions
- Always authorize on the server in event handlers — UI-only checks (hiding buttons) are not security; always verify in
handle_event/3 - Verify resource ownership by comparing
current_scope.user.idagainst the resource'suser_id— never trust client-sent user IDs - Use policy modules for complex authorization — don't inline permission checks in LiveViews or controllers
- Add
data-confirmattribute for destructive UI actions — client-side confirmation before server round-trip - Test both authorized and unauthorized paths — every
handle_eventthat mutates data needs an authz test proving unauthorized access is rejected - Scope queries to the current user in contexts —
where(user_id: ^user_id)prevents IDOR vulnerabilities
Server-Side Authorization in LiveViews
UI checks prevent accidental clicks. Server checks prevent attacks. You need both.