Skip to content

Missing username in log files when using API Token #13751

@NoaFayn

Description

@NoaFayn

Slack us first!
Done!

Be informative
Regarding the logs of the uwsgi container, it correctly shows the username of the user making the request on the web server, but doesn't for the API calls.

When using the web interface (to access web pages), the uwsgi container logs the following:

uwsgi-1  | [pid: 41|app: -|req: -/-] 172.18.0.1 (USERNAME) {64 vars in 1258 bytes} [XXX] GET /alerts/count => generated 15 bytes in 57 msecs (HTTP/1.1 200) 7 headers in 212 bytes (1 switches on core 1)

However, when making a request to the API using an API token, the log is as follow:

uwsgi-1  | [pid: 41|app: -|req: -/-] 172.18.0.1 (-) {44 vars in 681 bytes} [XXX] GET /api/v2/findings/3473444/ => generated 2403 bytes in 311 msecs (HTTP/1.1 200) 8 headers in 261 bytes (1 switches on core 2)

Notice the dash instead of the username of the user who generated the API token and performed the request.

This appears only when using the Token provided by the /api/key-v2 page.
If the user uses the swagger UI to make the API request, then the username correctly appears.

After discussion on Slack:

So issue is connected to AuthN method, not to url.

This may need custom middleware to get loggeed: https://stackoverflow.com/questions/26240832/django-and-middleware-which-uses-request-user-is-always-anonymous

Bug description
A clear and concise description of what the bug is. For errors include at least the exact error message you are seeing (including traceback).

Steps to reproduce
Steps to reproduce the behavior:

  1. Go to /api/key-v2 page using web interface
  2. Copy the given python code example (using Authorization Token in the headers)
  3. Execute the script
  4. Look at the uwsgi container logs and notice that the username doesn't appear in the logged request

Expected behavior
I expect the username to appear in the logs.

The logs are used for traceability and having no indication of the user that performed a request is a flaw that prevent forensic analysis or event simply traceability.

Deployment method

  • Docker Compose
  • Kubernetes
  • GoDojo

Environment information

  • Operating System: Debian 12
  • Docker Compose: v2.39.4
  • DefectDojo version: tested on v2.51.3 and v2.52.1

Logs

uwsgi-1  | [pid: 41|app: -|req: -/-] 172.18.0.1 (USERNAME) {64 vars in 1258 bytes} [XXX] GET /alerts/count => generated 15 bytes in 57 msecs (HTTP/1.1 200) 7 headers in 212 bytes (1 switches on core 1)
uwsgi-1  | [pid: 41|app: -|req: -/-] 172.18.0.1 (-) {44 vars in 681 bytes} [XXX] GET /api/v2/findings/3473444/ => generated 2403 bytes in 311 msecs (HTTP/1.1 200) 8 headers in 261 bytes (1 switches on core 2)

Sample scan files
N/A

Screenshots
N/A

Additional context (optional)
N/A

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions