Audit log API returns 500 when called with an Organisation API key

Open
#9,117 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
68/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python
Domain
api, backend

Research direction

Start with audit/views.py, especially get_queryset at the line named in the server log, and trace how it filters audit records for dashboard users and API key users. Reproduce the request with an Organisation API key and check whether the endpoint returns the project audit log or an intentional 403 instead of a 500.

Written by the indexing model from the issue text.

Description

Version: self-hosted 2.295.2 (flagsmith/flagsmith:2.295.2, Docker Compose)

What happens

GET /api/v1/audit/?project=<id> returns HTTP 500 when authenticated with an Organisation API key (Authorization: Api-Key …). The same request works for a logged-in dashboard user.

Steps to reproduce
curl -i -H "Authorization: Api-Key $ORG_API_KEY" "http://localhost:8000/api/v1/audit/?project=1"
Server log
File "/app/audit/views.py", line 63, in get_queryset
TypeError: Field 'id' expected a number but got <api_keys.user.APIKeyUser object at 0x…>.
Expected

The audit log for the project (or a 403 if API keys aren't meant to read it), not a 500.

Notes

It looks like get_queryset filters on request.user as if it were an FFAdminUser; with an API key it is an APIKeyUser. Found while building FlagLens, a VS Code extension for self-hosted Flagsmith; it currently falls back to its own change journal.

Dominant language
Python
Stars
9.9k
Forks
658
Avg merge
1d 15h
Merged PRs (30d)
168

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Flagsmith/flagsmith

All issues in Flagsmith/flagsmith

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.