feat: add HoneypotPayloadViewSet with RBAC-gated download. closes #1460 - #1464
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a new DRF read-only API for honeypot-captured payload metadata, plus an RBAC-gated endpoint to download quarantined .vir files for authorized users (staff / threat researchers).
Changes:
- Introduces
HoneypotPayloadViewSetwithlist,retrieve(metadata) anddownload(file stream) actions. - Adds
IsThreatResearcherOrAdminpermission and aHoneypotPayloadSerializerthat excludes the file field/path. - Registers the new route under
/api/payloadsand adds tests for permissions and view behavior.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/api/views/test_payload_view.py | Adds API tests for listing, retrieving, and RBAC-gated download behavior. |
| tests/api/test_permissions.py | Adds unit tests for the new permission class. |
| api/views/payloads.py | Implements the new read-only payload viewset and download action. |
| api/views/init.py | Exposes the new viewset via api.views imports. |
| api/urls.py | Registers the payloads router endpoint. |
| api/serializers/payloads.py | Adds serializer for payload metadata (excluding file). |
| api/serializers/init.py | Re-exports the new serializer module. |
| api/permissions.py | Adds IsThreatResearcherOrAdmin permission and group constant. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Hi @regulartim, /usr/local/lib/python3.13/site-packages/rest_framework/pagination.py:198: UnorderedObjectListWarning: Pagination may yield inconsistent results with an unordered object_list: <class 'greedybear.models.HoneypotPayload'> QuerySet.Should I just ignore this or try to fix it by making changes in model like It is also reported by copilot in second run. |
- Create HoneypotPayloadViewSet at /api/payloads/ (ReadOnly, sha256 lookup) - Add IsThreatResearcherOrAdmin permission class (staff or threat_researcher group) - list/retrieve return metadata only; download action streams .vir file - Add HoneypotPayloadSerializer excluding internal fields - 16 tests covering auth, RBAC, metadata-only responses, and download streaming
c5d697c to
8dc79d8
Compare
|
Hi @opbot-xd !
I think ignoring it would introduce a correctness bug on paginated responses. I think Copilot's suggetion of just adding a |
regulartim
left a comment
There was a problem hiding this comment.
Looks good! 👍
One thing I would really like to see: OpenAPI/Swagger schema documentation for the new API endpoint. I already implemented that for the Feeds API and I think it adds a lot of value. See #962 for context.
Basically you create a request and a response serializer and comment its fields adequately. The rest is done by a DRF module. You want to try it? You can just ask me if anything is unclear.
… serializer field descriptions
regulartim
left a comment
There was a problem hiding this comment.
Hey @opbot-xd ! The documentation was not wired in correctly. I did that and will push the changes soon. To view the docs, just open /api/schema/swagger-ui/. Maybe you could polish it a bit? Like adding all possible responses to list and retrieve and fix the documented response format for download?
- Add explicit 200/401/404 responses to list and retrieve - Fix download 200 response to use OpenApiTypes.BINARY instead of bytes - Add 401 to download action responses
|
Hi @regulartim, :D
|
Description
Add a DRF ViewSet and RBAC permission class to expose
HoneypotPayloaddata viaapi/payloads/.Related issues
Type of change
Checklist
Formalities
<feature name>. Closes #999develop.develop.Docs and tests
Ruff) gave 0 errors. If you have correctly installed pre-commit, it does these checks and adjustments on your behalf.GUI changes
Ignore this section if you did not make any changes to the GUI.
Review process