Skip to content

🛡️ Sentinel: [security improvement] Sanitize Content-Type in ValueError messages#783

Open
abhimehro wants to merge 1 commit into
mainfrom
jules-13399901602050852528-31d00218
Open

🛡️ Sentinel: [security improvement] Sanitize Content-Type in ValueError messages#783
abhimehro wants to merge 1 commit into
mainfrom
jules-13399901602050852528-31d00218

Conversation

@abhimehro
Copy link
Copy Markdown
Owner

@abhimehro abhimehro commented May 11, 2026

Severity: Medium
Vulnerability: External input (content_type) was passed into ValueError string without sanitization. Since exceptions are commonly logged, including raw, potentially attacker-controlled HTTP header data could lead to Log Injection attacks.
Impact: Attackers could inject arbitrary log entries or control characters, confusing monitoring systems or hiding traces of malicious activity.
Fix: Used the existing sanitize_for_log() function to sanitize the content_type variables before embedding them in the exception message.
Verification: Verified using uv run pytest tests/test_content_type.py and the full test suite.


Open in Devin Review

Copilot AI review requested due to automatic review settings May 11, 2026 23:11
@trunk-io
Copy link
Copy Markdown

trunk-io Bot commented May 11, 2026

Merging to main in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here

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: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Open in Devin Review

Copy link
Copy Markdown

@codescene-delta-analysis codescene-delta-analysis Bot left a comment

Choose a reason for hiding this comment

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

Gates Passed
6 Quality Gates Passed

See analysis details in CodeScene

Quality Gate Profile: Pay Down Tech Debt
Install CodeScene MCP: safeguard and uplift AI-generated code. Catch issues early with our IDE extension and CLI tool.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR mitigates potential log injection by sanitizing attacker-controlled Content-Type header values before embedding them in ValueError messages raised by the GitHub fetch helper (_gh_get) in main.py.

Changes:

  • Sanitized content_type in both _gh_get Content-Type validation error paths using the existing sanitize_for_log() helper.
  • Made the fallback (retry) branch’s error message consistent by also sanitizing the URL before logging/raising.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request improves logging security in main.py by ensuring that url and content_type are sanitized using sanitize_for_log() before being included in ValueError messages. The reviewer pointed out that the Content-Type validation logic is duplicated in two separate locations within the _gh_get function and suggested refactoring it into a helper function or a module-level constant to improve maintainability.

Comment thread main.py
Comment on lines 1528 to 1533
allowed_types = ["application/json", "text/json", "text/plain"]
if not any(t in content_type for t in allowed_types):
raise ValueError(
f"Invalid Content-Type from {url}: {content_type}. "
f"Invalid Content-Type from {sanitize_for_log(url)}: {sanitize_for_log(content_type)}. "
f"Expected one of: {', '.join(allowed_types)}"
)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The logic for validating the Content-Type and raising a ValueError is duplicated in two places within _gh_get (here and around line 1594). This duplication can lead to inconsistencies if the allowed types or the error message format need to be updated in the future. Consider refactoring this into a helper function or at least moving allowed_types to a module-level constant to improve maintainability and ensure consistent validation across both code paths.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants