Skip to content

Commit

Permalink
check the logId's match before attempting to retrieve old log entry
Browse files Browse the repository at this point in the history
  • Loading branch information
shroffk committed Jul 17, 2023
1 parent 459c9b8 commit 68bf84b
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/main/java/org/phoebus/olog/LogResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,10 @@ public Log updateLog(@PathVariable String logId,
@RequestBody Log log,
@AuthenticationPrincipal Principal principal) {

// In case a client sends a log record where the id does not match the path variable, return HTTP 400 (bad request)
if (!logId.equals(Long.toString(log.getId()))) {
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Log entry id does not match path variable");
}

Optional<Log> foundLog = logRepository.findById(logId);
if (foundLog.isPresent()) {
Expand All @@ -390,10 +394,6 @@ public Log updateLog(@PathVariable String logId,
persistedLog.setOwner(principal.getName());
}

// In case a client sends a log record where the id does not match the path variable, return HTTP 400 (bad request)
if (!logId.equals(Long.toString(log.getId()))) {
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Log entry id does not match path variable");
}
persistedLog.setLevel(log.getLevel());
persistedLog.setProperties(log.getProperties());
persistedLog.setModifyDate(Instant.now());
Expand Down

0 comments on commit 68bf84b

Please sign in to comment.