Skip to content

Conversation

@aegilops
Copy link
Collaborator

@aegilops aegilops commented Jun 2, 2025

Potential fix for https://github.com/advanced-security/python-lint-code-scanning-action/security/code-scanning/553

To fix the issue, we need to sanitize the user-provided input (args.linter) before logging it. Specifically:

  1. Remove any newline characters (\n and \r) from the input to prevent log injection.
  2. Optionally, escape or replace other potentially harmful characters to ensure the log entry is safe and unambiguous.

The best approach is to use Python's str.replace() method to remove newline characters from the args.linter value before including it in the log message. This ensures that the log entry remains safe while preserving the original functionality.


Suggested fixes powered by Copilot Autofix. Review carefully before merging.

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@aegilops aegilops marked this pull request as ready for review June 2, 2025 10:27
@aegilops aegilops requested a review from Copilot June 2, 2025 10:28
Copy link
Contributor

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 addresses a log injection vulnerability by sanitizing user-provided linter names before logging them.

  • Strips \n and \r characters from each entry in args.linter
  • Logs the sanitized list instead of the raw input to prevent injection
Comments suppressed due to low confidence (1)

python_lint.py:773

  • Add a unit test for this sanitization logic to ensure inputs containing newlines or other control characters are correctly cleaned before logging.
sanitized_linter = [linter.replace('\n', '').replace('\r', '') for linter in args.linter]

aegilops and others added 2 commits June 2, 2025 14:46
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@aegilops aegilops merged commit 7ad9431 into main Jun 2, 2025
3 checks passed
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.

2 participants