Skip to content

Protect credentials and secrets#1840

Open
cebarks wants to merge 3 commits intomainfrom
security/protect-credentials
Open

Protect credentials and secrets#1840
cebarks wants to merge 3 commits intomainfrom
security/protect-credentials

Conversation

@cebarks
Copy link
Copy Markdown
Collaborator

@cebarks cebarks commented Mar 17, 2026

Summary

Settings file permissions

  • Write settings.json with 0o600 (owner-only) permissions via os.open()
  • Add os.chmod() to enforce permissions on pre-existing files

API key redaction (7 locations)

  • Replace fragile string truncation with regex-based re.sub() redaction
  • Use capture group to preserve URL delimiters (?/&) in redacted output
  • Apply to all exception types, not just HTTPError/SSLError
  • Add redaction to handle_exception() excepthook — was bypassing loguru filter via exc_info=
  • Add redaction to CLI error handlers (__main__.py, build_db.py)
  • Add _redact_secrets() to obfuscate_message.py global loguru filter
  • Centralize redaction in dialogue.py base classes for all UI dialogs

Security Impact

Severity: High — The old sanitization logic was actively broken: when &key= was not found in a stacktrace, str.find() returned -1, silently truncating the entire stacktrace to 4 characters. Settings file with API keys was world-readable (0o644) on Linux.

Test plan

  • tests/utils/test_obfuscate_message.py — 11 tests passing (4 existing + 7 new)
  • Verify settings.json is created with 0o600 permissions on Linux
  • Verify API key does not appear in logs or error dialogs on Steam API failure

🤖 Generated with Claude Code

cebarks and others added 3 commits March 16, 2026 22:51
Settings file permissions:
- Write settings.json with 0o600 (owner-only) permissions to prevent
  other users on shared systems from reading stored API keys/tokens.

API key sanitization:
- Replace fragile string truncation with regex-based redaction across
  all 3 locations (__main__.py, webapi/wrapper.py x2).
- Apply redaction to all exception types, not just HTTPError/SSLError.
- Handle both ?key= and &key= URL parameter formats.
- Fix bug where missing pattern caused silent stacktrace destruction
  (truncated to 4 characters).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Settings file permissions:
- Write settings.json with 0o600 (owner-only) permissions
- Add os.chmod() to enforce permissions on existing files

API key redaction:
- Replace fragile string truncation with regex-based redaction
- Use capture group to preserve URL delimiters in redacted output
- Apply to all exception types, not just HTTPError/SSLError
- Add redaction to handle_exception() excepthook (was bypassing
  loguru filter via exc_info=)
- Add redaction to CLI error handlers (__main__.py, build_db.py)
- Add _redact_secrets() to obfuscate_message.py global log filter
- Centralize redaction in dialogue.py base classes for all UI dialogs

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.

1 participant