The vulnerability allows unauthenticated users to access notes and assets within a public book even after the book has been soft-deleted. This is a bypass of access controls (CWE-285).
The root cause is twofold:
- Incomplete Deletion Logic: When a book is deleted via
BooksService.DeleteBookByID, the operation is a soft-delete (setting the deleted_at field). However, the book's is_public status was not being changed. This meant the book was still considered 'public' in the database, even though the owner intended to make it inaccessible.
- Improper Data Access Queries: Functions responsible for fetching notes and assets (e.g.,
NotesService.GetNoteByID) used raw SQL JOIN statements. These raw queries did not respect GORM's automatic soft-delete filtering. The queries checked if a book was public (is_public = true) but failed to check if the book had been soft-deleted (books.deleted_at IS NULL).
During exploitation, an unauthenticated attacker can request a note or asset using its ID or slug. The backend functions would query the database, and since the is_public check passes and the soft-delete check is missing, the data is returned to the attacker.
The provided patch addresses the first point by modifying DeleteBookByID to explicitly set is_public to false within the same transaction as the soft-delete. This effectively revokes public access upon deletion, mitigating the issue by preventing the vulnerable state from being created.