fix(api): move recent-actions LogEntry query out of api/ (S-15 guard)#523
Merged
Merged
Conversation
The recent-actions view (#502) queried LogEntry.objects.filter(user=…) inline, tripping the S-15 security guard (no Model.objects.all/filter in api/). CI didn't catch it — the test suite doesn't gate CI yet (#452), only CodeQL does — so it landed on main and the full local run flagged it. Move the user-scoped LogEntry query into django_admin_react/audit.py as recent_actions_for_user(), alongside object_log_entries(). That module is the designated, documented home for framework audit-table access outside api/ (LogEntry is not a consumer model, so the get_queryset rule is categorically inapplicable). The view now delegates to it — no behaviour change, S-15 satisfied honestly. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Owner
Author
MartinCastroAlvarez
left a comment
There was a problem hiding this comment.
Security + architecture review (same-session reviewer lane).
Confirmed correct and security-positive:
- Behaviour identical:
recent_actions_for_userruns the sameLogEntry.objects.filter(user__pk=user_pk).order_by("-action_time")[:limit]— pure relocation, no semantic change. - User-scoping intact: still keyed on
request.user.pk, so each admin sees only their own actions — no IDOR / cross-user leak. - Architecture correct: lands in
audit.pybesideobject_log_entries(), the documented home for frameworkLogEntryaccess. Rule 2 (get_queryset) is categorically inapplicable —LogEntryis Django's audit table, not a consumer model — and the query now physically lives outsideapi/, restoring the S-15 guard (test_s15_no_objects_all_or_filter_in_api) to green. LogEntryimport in the view is still used by_serialize_action's annotations — no orphaned import.no-storeheader +_target_fordeep-linkhas_view_permissiongating untouched.
This is exactly the fix flagged when the suite is run locally (the gap that #452/#506 closes in CI). Merging on green CodeQL.
This was referenced May 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The recent-actions view (#502, merged in #505) queried
LogEntry.objects.filter(user=…)inline, which trips the S-15 security guard (tests/test_security.py::test_s15_no_objects_all_or_filter_in_api— noModel.objects.all|filterinapi/). It landed onmainbecause the test suite doesn't gate CI yet (#452); a full local run flagged it.Fix: move the user-scoped query into
django_admin_react/audit.pyasrecent_actions_for_user(), next to the existingobject_log_entries(). That module is the documented home for framework audit-table (LogEntry) access outsideapi/—LogEntryis not a consumer model, so theget_querysetrule is categorically inapplicable (the history view already follows this pattern). The view delegates to it. No behaviour change.Role
Author. Eligible for same-session review/merge once CI is green — this restores a green security guard on
main.Test plan
test_s15_no_objects_all_or_filter_in_apipasses (was failing onmain).tests/test_security.py+tests/test_history.pygreen (34 passed);tests/test_recent_actions.pygreen (12).ruff+mypyclean onaudit.py+recent_actions.py.🤖 Generated with Claude Code