fix(security): enforce object-level permissions on admin JSON endpoints#210
fix(security): enforce object-level permissions on admin JSON endpoints#210phusi319 wants to merge 3 commits into
Conversation
Signed-off-by: Phu Si On <phusi319@users.noreply.github.com>
Signed-off-by: Phu Si On <phusi319@users.noreply.github.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (2)
📜 Recent review details🧰 Additional context used📓 Path-based instructions (2)**/*.{js,ts,py,java,go,rb,php,sh,bash,yml,yaml}📄 CodeRabbit inference engine (Custom checks)
Files:
**/*.{js,ts,py,java,go,rb,php}📄 CodeRabbit inference engine (Custom checks)
Files:
🧠 Learnings (2)📚 Learning: 2026-03-26T22:29:15.066ZApplied to files:
📚 Learning: 2026-03-26T22:29:15.066ZApplied to files:
🔇 Additional comments (3)
📝 WalkthroughWalkthroughThis change adds authorization enforcement to two admin JSON endpoints: Estimated code review effort🎯 2 (Simple) | ⏱️ ~15 minutes 🚥 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)
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.
Pull request overview
This PR hardens django_loci’s custom Django admin JSON endpoints for locations by enforcing object-level authorization checks before returning location/floorplan data.
Changes:
- Add
has_view_or_change_permission(request, obj=instance)checks to the locationjson_viewandfloorplans_json_view, raisingPermissionDeniedwhen unauthorized. - Add regression tests ensuring users without location permission receive
403from both JSON endpoints.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
django_loci/base/admin.py |
Enforces object-level permission checks on the two custom admin JSON endpoints. |
django_loci/tests/base/test_admin.py |
Adds regression tests for unauthorized access returning 403 for both endpoints. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| from django.contrib.contenttypes.admin import GenericStackedInline | ||
| from django.core.exceptions import PermissionDenied, ValidationError | ||
| from django.http import JsonResponse | ||
| from django.shortcuts import get_object_or_404 | ||
| from django.urls import path |
There was a problem hiding this comment.
This file now contains CRLF (carriage return) line endings (visible as \r in diffs/search results), which causes the PR to rewrite the whole file and can create noisy diffs/merge conflicts. Please convert the file back to LF-only line endings (e.g., dos2unix or configure core.autocrlf/editor settings) and keep the change limited to the permission check logic.
| import json | ||
|
|
||
| import responses | ||
| from django.contrib.auth.models import Permission | ||
| from django.contrib.humanize.templatetags.humanize import ordinal | ||
| from django.urls import reverse |
There was a problem hiding this comment.
This file appears to have been converted to CRLF line endings (carriage returns), which rewrites the entire file in the diff and can create avoidable churn. Please normalize back to LF line endings and keep the diff focused on the two new regression tests.
Signed-off-by: Phu Si On <phusi319@users.noreply.github.com>
|
Addressed both review comments by normalizing reviewed files to LF-only line endings and keeping the diff focused on the permission checks/tests. No logic changes beyond the intended security fix and regression tests. |
Summary
This PR adds explicit object-level authorization checks to the custom admin JSON endpoints for locations.
Security issue
The custom admin endpoints:
/admin/.../location/<uuid>/json//admin/.../location/<uuid>/floorplans/json/retrieved objects and returned data without checking
has_view_or_change_permissionfor the target instance.Even though these views are wrapped with
admin_view, they should still enforce object-level checks before returning potentially sensitive location/floorplan data.Fix
In
django_loci/base/admin.py:PermissionDeniedhas_view_or_change_permission(request, obj=instance)checks in:json_viewfloorplans_json_viewPermissionDeniedwhen unauthorizedIn
django_loci/tests/base/test_admin.py:403on both JSON endpoints.Notes
Could not fully execute project tests locally because this environment misses OpenWISP runtime dependencies (
openwisp2) required by the test setup. Added focused regression tests for CI to validate behavior.Signed-off-by: Phu Si On phusi319@users.noreply.github.com