Fix DicomNode permission leak between groups#302
Conversation
The accessible_by_user() method used separate .filter() calls for group membership and access type, causing Django ORM to create independent JOINs. This allowed permissions from one group to leak to users of another group when both groups had access to the same DicomNode. Combined all conditions into a single .filter() call to ensure they apply to the same DicomNodeGroupAccess record. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Summary of ChangesHello @samuelvkwong, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request resolves a security vulnerability in the Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
|
No actionable comments were generated in the recent review. 🎉 📝 WalkthroughWalkthroughThe changes refactor the permission filtering logic in Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 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. ✨ Finishing touches
🧪 Generate unit tests (beta)
Tip Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord. 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 |
Code ReviewSummaryThis PR fixes a real and subtle Django ORM bug. The analysis is correct and the fix is the right approach. Here is my detailed feedback. Bug Fix Assessment: CorrectThe root cause description is accurate. When you chain separate
|
There was a problem hiding this comment.
Code Review
This pull request effectively resolves a critical permission leak bug in DicomNodeManager.accessible_by_user by consolidating separate .filter() calls into a single call, which correctly applies all conditions to the same database join. The fix is well-reasoned and the inclusion of a specific regression test is a great practice, ensuring this issue does not reappear. I have one minor suggestion to further refactor the implementation for improved code clarity and maintainability. Overall, this is a well-executed and important fix.
| if all_groups: | ||
| accessible_nodes = self.filter( | ||
| accesses__group__in=user.groups.all(), **access_filter | ||
| ) | ||
| else: | ||
| accessible_nodes = self.filter(accesses__group=user.active_group, **access_filter) |
There was a problem hiding this comment.
To improve maintainability and adhere to the Don't Repeat Yourself (DRY) principle, you can construct the group filter arguments separately and then make a single .filter() call. This avoids repeating the self.filter(...) logic within the if/else block and makes the code more modular.
| if all_groups: | |
| accessible_nodes = self.filter( | |
| accesses__group__in=user.groups.all(), **access_filter | |
| ) | |
| else: | |
| accessible_nodes = self.filter(accesses__group=user.active_group, **access_filter) | |
| group_kwargs = ( | |
| {"accesses__group__in": user.groups.all()} | |
| if all_groups | |
| else {"accesses__group": user.active_group} | |
| ) | |
| accessible_nodes = self.filter(**group_kwargs, **access_filter) |
Summary
DicomNodeManager.accessible_by_user()where permissions from one group could leak to users of another group.filter()calls creating independent JOINs, allowing conditions to match differentDicomNodeGroupAccessrecords.filter()call to ensure they apply to the same access recordTest plan
pytest adit/core/tests/test_models.py::TestDicomNodeManagerto verify the fix and regression test🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
Tests