Skip to content

Commit f27d7bc

Browse files
MatusBekeclaude
andcommitted
Guard against null workflow item in the WORKFLOWITEM permission evaluator
WorkflowRestPermissionEvaluatorPlugin dereferenced the result of workflowItemService.find() without a null check, so an unknown id from an authenticated non-admin threw a NullPointerException (HTTP 500) instead of 404. The sibling PoolTask/ClaimedTask evaluators already guard this case; mirror them by returning true for a null item so the handler can produce the proper 404. Now reachable via the newly authorized /step subresource. Add a regression test asserting an unknown workflowitem /step id yields 404. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent ba6ba4a commit f27d7bc

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

dspace-server-webapp/src/main/java/org/dspace/app/rest/security/WorkflowRestPermissionEvaluatorPlugin.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ public boolean hasDSpacePermission(Authentication authentication, Serializable t
8181
}
8282
int dsoId = Integer.parseInt(targetId.toString());
8383
XmlWorkflowItem workflowItem = workflowItemService.find(context, dsoId);
84+
// If the workflow item is null then we give permission so we can throw another status code instead
85+
if (workflowItem == null) {
86+
return true;
87+
}
8488
// submitter can see their inprogress submission
8589
if (ePerson.equals(workflowItem.getSubmitter())) {
8690
return true;

dspace-server-webapp/src/test/java/org/dspace/app/rest/WorkflowStepLinkRepositoryIT.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,4 +148,21 @@ public void workflowItemStepEnforcesAuthorization() throws Exception {
148148
getClient(adminToken).perform(get(stepPath)).andExpect(status().isOk());
149149
}
150150

151+
@Test
152+
public void workflowItemStepWithUnknownIdIsNotFound() throws Exception {
153+
context.turnOffAuthorisationSystem();
154+
155+
EPerson ePerson = EPersonBuilder.createEPerson(context)
156+
.withEmail("lookup-step@example.com").withPassword(password).build();
157+
158+
context.restoreAuthSystemState();
159+
160+
String token = getAuthToken(ePerson.getEmail(), password);
161+
162+
// an authenticated (non-admin) user requesting an unknown workflow item id must get 404, not a 500
163+
// caused by an unchecked null in the WORKFLOWITEM permission evaluator
164+
getClient(token).perform(get("/api/workflow/workflowitems/" + Integer.MAX_VALUE + "/step"))
165+
.andExpect(status().isNotFound());
166+
}
167+
151168
}

0 commit comments

Comments
 (0)