fix(auth): Add admin-level auth to LibraryController 'delete', 'update' and 'delete items with issues' #4027
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Brief summary
This PR addresses a security vulnerability in the LibraryController by enforcing admin-level authorization for critical endpoints that were previously accessible to non-admin users. Specifically, it restricts access to library settings updates, library issue removal, and library deletion to only admin users.
Which issue is fixed?
No issue reported (security fix).
In-depth Description
This PR implements admin-level authorization checks in the
LibraryController
for the following methods:PATCH /api/libraries/:id
(update method): Previously, any authenticated user could potentially modify library settings. This change adds a check at the beginning of theupdate
method to ensure that only users withisAdminOrUp
privileges can proceed with updating library settings.DELETE /api/libraries/:id/issues
(removeLibraryItemsWithIssues method): Similarly, this endpoint for removing library items with issues was not properly protected. This PR adds anisAdminOrUp
check at the start of theremoveLibraryItemsWithIssues
method to restrict its use to administrators.DELETE /api/libraries/:id
(delete method): This PR also adds anisAdminOrUp
check to thedelete
method to ensure that only admin users can delete libraries. Deleting a library is a highly sensitive operation that should be restricted to administrators.These changes ensure that sensitive library management operations are only accessible to authorized admin users, enhancing the overall security and access control of the application.
How have you tested this?
Test Steps:
curl
commands to directly interact with the API endpoints.PATCH /api/libraries/:id
:curl
commands were used with both Admin and Non-Admin JWTs to attempt updating library settings.DELETE /api/libraries/:id/issues
:curl
commands were used with both Admin and Non-Admin JWTs to attempt removing library issues.DELETE /api/libraries/:id
:curl
commands were used with both Admin and Non-Admin JWTs to attempt deleting a library.