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.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.