[NAE-2407] Improve Permission Validation in GetData#431
[NAE-2407] Improve Permission Validation in GetData#431machacjozef merged 6 commits intorelease/6.4.3from
Conversation
Introduced `canCallGetData` method in `TaskAuthorizationService` and applied `@PreAuthorize` annotations to secure `getData` endpoints in `TaskController` and `PublicTaskController`. Updated related method signatures to include `Authentication` parameter for proper authorization handling.
|
Warning Rate limit exceeded
Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 30 minutes and 52 seconds. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (2)
WalkthroughAdded authorization checking to task data retrieval endpoints by introducing Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In
`@src/main/java/com/netgrif/application/engine/workflow/web/PublicTaskController.java`:
- Around line 114-118: The `@PreAuthorize` on getData currently passes the runtime
Authentication principal (`#auth.getPrincipal`()) to
taskAuthorizationService.canCallGetData; change it to use the anonymous user
helper consistent with other public endpoints by invoking
userService.getAnonymousLogged() as the principal argument (i.e., call
taskAuthorizationService.canCallGetData(`@userService.getAnonymousLogged`(),
`#taskId`) in the `@PreAuthorize` expression on the getData method).
In
`@src/main/java/com/netgrif/application/engine/workflow/web/responsebodies/DataGroupsResource.java`:
- Around line 25-26: The self link call in DataGroupsResource currently invokes
TaskController.getData with an empty taskId (getData("", null, null)) which
produces an invalid URI; update that invocation to pass the actual taskId from
the surrounding context (for example the method parameter or the represented
object's id) into methodOn(TaskController.class).getData(taskId, null, null) so
the generated self link correctly points to the task resource, and if no taskId
is available in scope then remove/skip creating the self link instead of using
an empty string.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 33698010-1ca7-4fae-b7d4-cd69ec46dcd4
📒 Files selected for processing (7)
src/main/java/com/netgrif/application/engine/workflow/service/TaskAuthorizationService.javasrc/main/java/com/netgrif/application/engine/workflow/service/interfaces/ITaskAuthorizationService.javasrc/main/java/com/netgrif/application/engine/workflow/web/AbstractTaskController.javasrc/main/java/com/netgrif/application/engine/workflow/web/PublicTaskController.javasrc/main/java/com/netgrif/application/engine/workflow/web/TaskController.javasrc/main/java/com/netgrif/application/engine/workflow/web/responsebodies/DataGroupsResource.javasrc/main/java/com/netgrif/application/engine/workflow/web/responsebodies/LocalisedTaskResource.java
Updated `@PreAuthorize` annotation to use anonymous user context when fetching task data. Refactored `buildLinks` method to pass task ID dynamically, ensuring proper link generation based on the parent task.
Refactored getData methods in TaskController, PublicTaskController, and AbstractTaskController to exclude the unused Authentication parameter. This streamlines method signatures and improves code clarity while retaining functionality and security checks.
There was a problem hiding this comment.
♻️ Duplicate comments (1)
src/main/java/com/netgrif/application/engine/workflow/web/responsebodies/DataGroupsResource.java (1)
21-26:⚠️ Potential issue | 🟠 MajorGuard self-link creation when
taskIdis missing.
taskIdcan benull(Line 25), butbuildLinksalways emits the self link (Line 31). This can produce an invalidgetDataURI when no parent task is present incontent.Suggested fix
private void buildLinks(String taskId) { + if (taskId == null || taskId.isBlank()) { + return; + } add(WebMvcLinkBuilder.linkTo(WebMvcLinkBuilder.methodOn(TaskController.class) .getData(taskId, null, null)).withSelfRel()); }Also applies to: 29-31
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/main/java/com/netgrif/application/engine/workflow/web/responsebodies/DataGroupsResource.java` around lines 21 - 26, The code calls buildLinks(taskId) even when taskId is null which causes an invalid self-link/getData URI; update DataGroupsResource so that either buildLinks only emits the self link when the passed taskId is non-null/non-blank or call buildLinks conditionally (e.g., if (taskId != null && !taskId.isBlank()) buildLinks(taskId)); ensure the check is applied for both call sites shown and that buildLinks and any self-link construction use the validated taskId.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Duplicate comments:
In
`@src/main/java/com/netgrif/application/engine/workflow/web/responsebodies/DataGroupsResource.java`:
- Around line 21-26: The code calls buildLinks(taskId) even when taskId is null
which causes an invalid self-link/getData URI; update DataGroupsResource so that
either buildLinks only emits the self link when the passed taskId is
non-null/non-blank or call buildLinks conditionally (e.g., if (taskId != null &&
!taskId.isBlank()) buildLinks(taskId)); ensure the check is applied for both
call sites shown and that buildLinks and any self-link construction use the
validated taskId.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: a0906935-2e82-4bbc-87fe-0f6b228d0eda
📒 Files selected for processing (3)
src/main/java/com/netgrif/application/engine/workflow/web/PublicTaskController.javasrc/main/java/com/netgrif/application/engine/workflow/web/TaskController.javasrc/main/java/com/netgrif/application/engine/workflow/web/responsebodies/DataGroupsResource.java
Extended the XML configuration and added new roles and userRefs for view permissions. Implemented test cases to verify task authorization behavior for positive and negative view permissions using both roles and userRefs.
Eliminated redundant `sleep(4000)` calls in test cases to improve execution efficiency and reduce test runtime. The changes do not affect the test logic or expected outcomes.
The unnecessary `workflowService.save` calls have been removed from `testCanGetDataWithPosViewUserRef` and `testCannotGetDataWithNegViewUserRef` in `TaskAuthorizationServiceTest.groovy`. This simplifies the code and improves test clarity without affecting functionality.
Description
Implements NAE-2407
Dependencies
No new dependencies were introduced
Third party dependencies
Blocking Pull requests
There are no dependencies on other PR
How Has Been This Tested?
This was tested manually and with unit tests.
Test Configuration
Checklist:
Summary by CodeRabbit
New Features
Bug Fixes