Skip to content

fix(exceptions): prevent info leak from exception cause chain#366

Merged
iamgp merged 2 commits intomainfrom
fix/support-correctness-batch-348
Apr 6, 2026
Merged

fix(exceptions): prevent info leak from exception cause chain#366
iamgp merged 2 commits intomainfrom
fix/support-correctness-batch-348

Conversation

@iamgp
Copy link
Copy Markdown
Collaborator

@iamgp iamgp commented Apr 6, 2026

Summary

Fixes part of issue #348 (support module correctness batch) and issue #351 (security hardening batch).

Issue: Exception cause chain could leak internal implementation details like connection strings, query fragments, or internal paths when formatted in error output.

Fix: In PhloError._format_message(), only show the exception type name (e.g., ValueError) instead of the full message (e.g., ValueError: connection string with password=secret).

Changes

File: src/phlo/exceptions.py

  • Changed f"Caused by: {type(self.cause).__name__}: {str(self.cause)}" to f"Caused by: {type(self.cause).__name__}"

File: tests/test_exceptions.py

  • Updated test to expect only type name in cause string

Testing

  • All 396 tests pass
  • Ruff linting passes

Related Issues

Closes #348 item 2 (exception cause chain leak)
Closes #351 item 2 (Exception cause chain may leak internal implementation details)


Open with Devin

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 6, 2026

Cairn Quality Report

Commit: d3204f9 · View full report

Checker Status ✅ Passed ❌ Failed Items
ruff passed 0 0 0
ruff-format pass 0 0 1
pytest-3.11 passed 399 0 400
pytest-3.12 passed 399 0 400

…oError output

Security fix: Exception cause messages could leak sensitive data like
passwords, tokens, connection strings, etc.

Changes:
- Added _SENSITIVE_PATTERNS regex list for common sensitive patterns
- Added _redact_sensitive() helper to redact matched patterns
- Updated PhloError._format_message() to redact sensitive data in cause
- Added test to verify redaction works correctly

Preserves diagnostic value for non-sensitive errors while protecting
against credential leaks in error output.
@iamgp iamgp force-pushed the fix/support-correctness-batch-348 branch from 3af7b1a to c54ec98 Compare April 6, 2026 19:22
@iamgp iamgp merged commit 4c17583 into main Apr 6, 2026
42 checks passed
@iamgp iamgp deleted the fix/support-correctness-batch-348 branch April 6, 2026 19:30
Copy link
Copy Markdown

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

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

Devin Review found 1 new potential issue.

View 3 additional findings in Devin Review.

Open in Devin Review

r"\b(password|passwd|token|secret|api_key|apikey|credential)\b\s*[:=]\s*[^\s,;]+",
re.IGNORECASE,
)
_AUTHORIZATION_SENSITIVE_PATTERN = re.compile(r"\b(authorization|bearer)\b\s+\S+", re.IGNORECASE)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 _AUTHORIZATION_SENSITIVE_PATTERN over-redacts common error context words after "authorization"

The _AUTHORIZATION_SENSITIVE_PATTERN regex \b(authorization|bearer)\b\s+\S+ unconditionally redacts whatever single word follows "authorization" or "bearer". This corrupts common error messages where these words are followed by non-sensitive context like "failed", "denied", "required", or "header".

Examples of false-positive redaction
  • "authorization failed""authorization <redacted>" ("failed" is not a secret)
  • "authorization denied""authorization <redacted>"
  • "authorization required""authorization <redacted>"
  • "missing authorization header""missing authorization <redacted>"
  • "authorization error: invalid credentials""authorization <redacted> invalid credentials"

These are common error message patterns from HTTP clients and auth libraries. When such exceptions are wrapped as a cause in a PhloError, the diagnostic context is destroyed, making it significantly harder to debug authorization-related failures.

Prompt for agents
The _AUTHORIZATION_SENSITIVE_PATTERN at line 14 of src/phlo/exceptions.py matches any word following 'authorization' or 'bearer', causing false-positive redaction of common non-sensitive context words like 'failed', 'denied', 'required', 'header', etc.

The pattern is: r"\b(authorization|bearer)\b\s+\S+"

The intent is to catch HTTP Authorization header values like 'Authorization: Bearer <token>' or inline 'bearer <token>' patterns. But the 'authorization' alternative is too broad.

Possible fixes:
1. Remove 'authorization' from this pattern entirely since the 'bearer' alternative already catches the actual token in 'Authorization: Bearer <token>' format.
2. Make the 'authorization' alternative more specific, e.g. require a colon delimiter like 'authorization:\s+\S+' to only match header-like formats.
3. Add a negative lookahead for common non-sensitive words: 'authorization\s+(?!failed|denied|required|error|header|expired|invalid)\S+'.

Option 1 is simplest and most robust since Bearer already handles the main use case.
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

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.

[MEDIUM] Security hardening batch [MEDIUM] Support module correctness issues batch

1 participant