fix critical and high severity security vulnerabilities (#3060)

This commit is contained in:
ACX
2026-02-26 22:34:01 -07:00
committed by GitHub
parent 3cbb3372c9
commit 46d744318d
6 changed files with 38 additions and 10 deletions
@@ -29,7 +29,8 @@ public class GlobalExceptionHandler {
@ExceptionHandler(HttpMessageNotReadableException.class)
public ResponseEntity<ErrorResponse> handleHttpMessageNotReadableException(HttpMessageNotReadableException ex) {
ErrorResponse errorResponse = new ErrorResponse(HttpStatus.BAD_REQUEST.value(), "Request body is missing or malformed: " + ex.getMostSpecificCause().getMessage());
log.warn("Malformed request body: {}", ex.getMessage());
ErrorResponse errorResponse = new ErrorResponse(HttpStatus.BAD_REQUEST.value(), "Request body is missing or malformed.");
return new ResponseEntity<>(errorResponse, HttpStatus.BAD_REQUEST);
}
@@ -58,7 +59,8 @@ public class GlobalExceptionHandler {
@ExceptionHandler(DataIntegrityViolationException.class)
public ResponseEntity<ErrorResponse> handleDataIntegrityViolation(DataIntegrityViolationException ex) {
ErrorResponse errorResponse = new ErrorResponse(HttpStatus.BAD_REQUEST.value(), ex.getMessage());
log.warn("Data integrity violation: {}", ex.getMessage());
ErrorResponse errorResponse = new ErrorResponse(HttpStatus.BAD_REQUEST.value(), "A data conflict occurred. The operation could not be completed.");
return new ResponseEntity<>(errorResponse, HttpStatus.BAD_REQUEST);
}
@@ -114,8 +116,8 @@ public class GlobalExceptionHandler {
@ExceptionHandler(Exception.class)
public ResponseEntity<ErrorResponse> handleGenericException(Exception ex) {
ErrorResponse errorResponse = new ErrorResponse(HttpStatus.INTERNAL_SERVER_ERROR.value(), ex.getMessage());
log.error(ex.getMessage(), ex);
log.error("Unhandled exception: {}", ex.getMessage(), ex);
ErrorResponse errorResponse = new ErrorResponse(HttpStatus.INTERNAL_SERVER_ERROR.value(), "An unexpected error occurred.");
return new ResponseEntity<>(errorResponse, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@@ -110,8 +110,17 @@ public class BookService {
public List<Book> getBooksByIds(Set<Long> bookIds, boolean withDescription) {
BookLoreUser user = authenticationService.getAuthenticatedUser();
boolean isAdmin = user.getPermissions().isAdmin();
List<BookEntity> bookEntities = bookQueryService.findAllWithMetadataByIds(bookIds);
if (!isAdmin) {
Set<Long> userLibraryIds = getUserLibraryIds(user);
bookEntities = bookEntities.stream()
.filter(book -> userLibraryIds.contains(book.getLibrary().getId()))
.toList();
}
Set<Long> entityIds = bookEntities.stream().map(BookEntity::getId).collect(Collectors.toSet());
Map<Long, UserBookProgressEntity> progressMap =
@@ -363,7 +372,15 @@ public class BookService {
@Transactional
public ResponseEntity<BookDeletionResponse> deleteBooks(Set<Long> ids) {
BookLoreUser user = authenticationService.getAuthenticatedUser();
List<BookEntity> books = bookQueryService.findAllWithMetadataByIds(ids);
if (!user.getPermissions().isAdmin()) {
Set<Long> userLibraryIds = getUserLibraryIds(user);
books = books.stream()
.filter(book -> userLibraryIds.contains(book.getLibrary().getId()))
.toList();
}
List<Long> failedFileDeletions = new ArrayList<>();
for (BookEntity book : books) {
for (BookFileEntity bookFile : book.getBookFiles()) {