b29a268b1d
- Move completed plan files to .plans/done/ - Move 18 open plan files to .plans/open/ - Update .gitignore to exclude .verified_plans temp file - Verified all 18 open plans still describe unimplemented issues
2.1 KiB
2.1 KiB
Issue #211: Authorization Middleware Maintenance Burden
Problem
The AuthorizationMiddleware requires manual maintenance for each new controller and method:
-
When adding a new admin-only controller, it must be added to the
beforeControllerchain:if ($controller instanceof ImportController || $controller instanceof PermissionController || $controller instanceof AuditController || $controller instanceof DsgvoController || $controller instanceof BackupController // NEW: Must add here ) { ... } -
When adding an admin-only method, it must be added to a constant:
private const ADMIN_METHODS_MEMBER = ['revealAllergies', 'archive']; // NEW: Must add here -
When adding a read-only method, it must be added to:
private const READ_METHODS = [ 'index', 'show', 'search', 'preview', ... // NEW: Must add here ];
Impact
- Easy to forget to add a new controller/method to the right list
- Growing maintenance burden as the app expands
- Potential security issues if a write method is accidentally omitted
- Violates Open/Closed Principle
Solution
Use PHP 8 attributes to declare permissions directly on controller methods:
#[Attribute]
class RequirePermission {
public function __construct(string $level) { ... }
}
class MemberController {
#[RequirePermission('read')]
public function index(): JSONResponse { ... }
#[RequirePermission('write')]
public function create(): JSONResponse { ... }
#[RequirePermission('admin')]
public function revealAllergies(): JSONResponse { ... }
}
Middleware then reads attributes via reflection.
Tasks
- Create
RequirePermissionattribute class - Add
#[RequirePermission]attributes to all controller methods - Refactor
AuthorizationMiddleware::beforeController()to use reflection - Remove hardcoded controller and method lists
- Add tests to verify permission enforcement
- Document the new attribute-based approach
Labels
- refactoring
- backend
- security
- priority:medium
- architecture