Skip to content

Prevent server token exposure in error logs and log files - #1063

Merged
mlim19 merged 2 commits into
masterfrom
fix/token-log-exposure
Oct 21, 2026
Merged

mlim19 merged 2 commits into
masterfrom
fix/token-log-exposure

Conversation

@mlim19

@mlim19 mlim19 commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Redact the server token from request errors (gprofiler/client.py): exceptions raised by requests embed the request URL, which includes the token in its query string (key=<token>). When such errors were logged (e.g. a failed server health check at startup, or a failed profile upload), the token ended up in the local log file, stdout, and uploaded logs. The token is now replaced with ***, and the exception type is preserved (callers still catch Timeout specifically).
  • Restrict log file permissions (gprofiler/log.py): log files are now owner-only (0600), including files left by older versions and files created on rotation. A log directory created by gProfiler is 0700.

Rootless / sudoless compatibility

  • Existing directories are never modified, so --rootless runs with a user-provided --log-file (e.g. in $HOME or /tmp) are unaffected.
  • Log files remain owned by and readable/writable for the user running gProfiler.
  • Setting the file mode is best-effort: if it can't be applied (e.g. a writable log file owned by another user), logging continues as before.

Note

Non-root readers of /var/log/gprofiler (e.g. log shippers running without root) will need elevated access once the directory and files are recreated with the new modes.

Test plan

  • Connection error to an unreachable server: message shows key=***, no raw or URL-encoded token
  • As non-root: existing user dir keeps its mode; new log dir is 0700; log and rotated log are 0600; old 0644 log file becomes 0600
  • black, isort, flake8

🤖 Generated with Claude Code

Exceptions raised by requests embed the request URL, which includes the
server token in its query string. Redact the token before these errors
are logged.

Restrict log files to owner-only access (0600), including rotated files,
and create a new log directory as 0700. Existing directories are left
untouched, so rootless runs with a user-provided --log-file are not
affected.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings October 20, 2026 18:03

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Token redaction and log permissions retain exposure gaps, and exception reconstruction can break error handling.

4 open issues
What changed in this PR

This PR reduces server-token exposure by sanitizing request errors and restricting local log permissions.

Changes:

  • Redacts encoded tokens from request exceptions.
  • Restricts active and newly rotated logs to owner-only access.
  • Creates new log directories with owner-only permissions.
File Description
gprofiler/​log.py Adds restrictive log-file and directory permissions.
gprofiler/​client.py Adds token redaction when rethrowing request exceptions.

Review effort: Balanced

Comment thread gprofiler/client.py Resolved
Comment thread gprofiler/client.py Resolved
Comment thread gprofiler/log.py Resolved
Comment thread gprofiler/log.py Resolved
… redacting invalid JSON failures'

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings October 21, 2026 18:03

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Permission handling still leaves exposure risks during file creation and for legacy rotated logs.

2 open issues
2 resolved since last review

Review effort: Balanced

@mlim19
mlim19 merged commit b38d20c into master Oct 21, 2026
29 of 35 checks passed
@mlim19
mlim19 deleted the fix/token-log-exposure branch October 21, 2026 19:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants