Add centralized authorization module and fix security vulnerabilities #6
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "fix/authorization-security-refactor"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
This PR introduces a centralized authorization system and fixes critical security vulnerabilities in Castle's API endpoints. The changes improve security, reduce code duplication, and establish consistent patterns for access control.
Problem Statement
The previous authorization implementation had several issues:
wallet.wallet.id(wallet ID) vswallet.wallet.user(user ID)Security Vulnerabilities Fixed
CRITICAL - Previously Unprotected Endpoints
These endpoints had zero authentication and exposed sensitive data to anyone:
GET /api/v1/accounts/{id}GET /api/v1/accounts/{id}/balanceGET /api/v1/accounts/{id}/transactionsGET /api/v1/entriesGET /api/v1/balance/{user_id}GET /api/v1/balances/allHIGH - Admin Endpoints Without Super User Check
These endpoints used
require_admin_keybut didn't verifysuper_userstatus, allowing any user with an admin key to access them:/api/v1/users,/api/v1/admin/castle-users)/api/v1/user-wallet/{user_id})Changes
New File:
auth.pyCentralized authorization module providing:
Modified:
views_api.pyBefore:
After:
Fixed: wallet_id vs user_id
Changed 5 occurrences of
wallet.wallet.idtowallet.wallet.user:Impact
Testing Checklist
Related Issues
Addresses security concerns identified in authorization/roles review.
Closing — this work landed on
mainvia merge commit5eb007b("Merge branch 'fix/authorization-security-refactor'"), bringing inca0cee7("Add centralized authorization module and fix security vulnerabilities").Verified locally:
auth.pyexists withAuthContext,require_authenticated,require_authenticated_write,require_super_user,can_access_account,require_account_access,can_access_user_data,require_user_data_accessviews_api.pyendpoints use the centralized dependenciesNo further action needed.
Pull request closed