Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -859,22 +859,27 @@ private List<String> getExistingActors(ActorListFieldValue actorListFieldValue)
return null;
}
return actorListFieldValue.getActorValues().stream()
.filter(this::actorExists)
.map(ActorFieldValue::getId)
.filter(actorId -> {
AbstractUser user = userService.findById(actorId, null);
if (user != null) {
return true;
}
try {
groupService.findById(actorId);
return true;
} catch (IllegalArgumentException ignored) {
return false;
}
})
.collect(Collectors.toList());
}

private boolean actorExists(ActorFieldValue actorFieldValue) {
if (actorFieldValue == null || actorFieldValue.getId() == null) {
return false;
}
AbstractUser user = userService.findById(actorFieldValue.getId(), actorFieldValue.getRealmId());
if (user != null) {
return true;
}
try {
groupService.findById(actorFieldValue.getId());
return true;
} catch (IllegalArgumentException ignored) {
return false;
}
}
Comment on lines +867 to +881
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Catch invalid user IDs here instead of aborting task resolution.

Line 871 can still throw on blank or malformed ids because userService.findById(...) builds an ObjectId internally. That means one bad actor entry can fail the whole resolution path instead of being filtered out. Treat blank ids as missing and swallow IllegalArgumentException from the user lookup before falling back to groups.

Proposed fix
 private boolean actorExists(ActorFieldValue actorFieldValue) {
-    if (actorFieldValue == null || actorFieldValue.getId() == null) {
+    if (actorFieldValue == null || actorFieldValue.getId() == null || actorFieldValue.getId().isBlank()) {
         return false;
     }
-    AbstractUser user = userService.findById(actorFieldValue.getId(), actorFieldValue.getRealmId());
-    if (user != null) {
-        return true;
+    try {
+        AbstractUser user = userService.findById(actorFieldValue.getId(), actorFieldValue.getRealmId());
+        if (user != null) {
+            return true;
+        }
+    } catch (IllegalArgumentException ignored) {
+        // Not a valid user id, continue with group lookup.
     }
     try {
         groupService.findById(actorFieldValue.getId());
         return true;
     } catch (IllegalArgumentException ignored) {
         return false;
     }
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@application-engine/src/main/java/com/netgrif/application/engine/workflow/service/TaskService.java`
around lines 867 - 881, actorExists currently calls userService.findById(...)
which can throw IllegalArgumentException for blank/malformed ids and abort
resolution; update actorExists to treat null/blank actorFieldValue.getId() as
missing, wrap the userService.findById(...) call in a try/catch that catches
IllegalArgumentException and treats it like a non-existent user, then only if
the user lookup fails proceed to try groupService.findById(...) (also swallowing
IllegalArgumentException similarly) so a bad actor id is filtered out rather
than causing the whole resolution to fail; refer to the actorExists method and
the userService.findById and groupService.findById calls when making the change.


private Task createFromTransition(Transition transition, Case useCase) {
final Task task = com.netgrif.application.engine.adapter.spring.workflow.domain.Task.with()
.title(transition.getTitle())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,9 @@ public Case resolveActorRef(Case useCase, boolean canSaveUseCase) {
/**
* Resolves actor permissions for the useCase based on the actor list data field.
*
* @param useCase useCase where to resolve actor permissions
* @param useCase useCase where to resolve actor permissions
* @param actorFieldId field id of the actor list
* @param permission permission associated with the useCase and actor list
*
* @param permission permission associated with the useCase and actor list
* @return true if the useCase was modified, false otherwise
*/
private boolean resolveActorRefPermissions(Case useCase, String actorFieldId, Map<String, Boolean> permission) {
Expand All @@ -278,22 +277,27 @@ private List<String> getExistingActors(ActorListFieldValue actorListFieldValue)
return null;
}
return actorListFieldValue.getActorValues().stream()
.filter(this::actorExists)
.map(ActorFieldValue::getId)
.filter(actorId -> {
AbstractUser user = userService.findById(actorId, null);
if (user != null) {
return true;
}
try {
groupService.findById(actorId);
return true;
} catch (IllegalArgumentException ignored) {
return false;
}
})
.collect(Collectors.toList());
}

private boolean actorExists(ActorFieldValue actorFieldValue) {
if (actorFieldValue == null || actorFieldValue.getId() == null) {
return false;
}
AbstractUser user = userService.findById(actorFieldValue.getId(), actorFieldValue.getRealmId());
if (user != null) {
return true;
}
try {
groupService.findById(actorFieldValue.getId());
return true;
} catch (IllegalArgumentException ignored) {
return false;
}
}

public CreateCaseEventOutcome createCase(CreateCaseParams createCaseParams) {
fillAndValidateAttributes(createCaseParams);
PetriNet petriNet = createCaseParams.getProcess();
Expand Down
Loading