Skip to content

Potential fix for code scanning alert no. 10: Clear-text logging of sensitive information#93

Closed
DaTiC0 wants to merge 2 commits into
mainfrom
alert-autofix-10
Closed

Potential fix for code scanning alert no. 10: Clear-text logging of sensitive information#93
DaTiC0 wants to merge 2 commits into
mainfrom
alert-autofix-10

Conversation

@DaTiC0

@DaTiC0 DaTiC0 commented Mar 7, 2026

Copy link
Copy Markdown
Owner

Potential fix for https://github.com/DaTiC0/smart-google/security/code-scanning/10

General approach: Avoid logging untrusted or potentially sensitive response bodies, especially when they are associated with secrets such as API keys. Keep only minimal, non-sensitive information in logs, such as HTTP status codes or high-level error messages, and do not log the API key, full URL, or raw body.

Best concrete fix here: In action_devices.py’s request_sync function, keep the status code logging (which is not sensitive) but stop logging the full response.text. If needed for troubleshooting, we can log a truncated or generic message that does not contain the raw body. This addresses all three alert variants because they all flow through response.text logging. We do not need new imports or structural changes; just adjust the print statements.

Specific changes:

  • File: action_devices.py
    • In request_sync:
      • Keep the line logging requests.codes["ok"] and response.status_code.
      • Replace the line print(f'\nResponse: {response.text}') with a safer message that does not include the body, e.g. print('\nResponse body omitted from logs for security reasons') or remove it entirely. I’ll keep a generic note so operators know a response was received.

No other files need code changes for this issue, because the vulnerability is at the sink in request_sync.


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

Summary by Sourcery

Avoid logging full HTTP response bodies in device sync requests to reduce the risk of exposing sensitive information in logs.

Bug Fixes:

  • Prevent clear-text logging of potentially sensitive response data in the request_sync flow.

Enhancements:

  • Replace detailed response body logging with a generic non-sensitive log message in request_sync.

…ensitive information

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@sourcery-ai

sourcery-ai Bot commented Mar 7, 2026

Copy link
Copy Markdown
Contributor
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This PR mitigates a code scanning alert about clear-text logging of sensitive information by removing detailed response body logging from the request_sync function and replacing it with a generic, non-sensitive log message while retaining status code logging.

Sequence diagram for updated request_sync logging behavior

sequenceDiagram
    actor Caller
    participant ActionDevices as request_sync
    participant Requests as requests
    participant ExternalAPI as GoogleHomeGraphAPI
    participant Logger

    Caller->>ActionDevices: request_sync(api_key, agent_user_id)
    ActionDevices->>Requests: post(url, json=data)
    Requests->>ExternalAPI: HTTP POST /requestSync
    ExternalAPI-->>Requests: HTTP Response (status_code, body)
    Requests-->>ActionDevices: Response

    ActionDevices->>Logger: print(\"Requests Code: requests.codes[ok], Response Code: response.status_code\")
    ActionDevices->>Logger: print(\"Response body omitted from logs for security reasons\")

    ActionDevices-->>Caller: return response.status_code == requests.codes[ok]
Loading

File-Level Changes

Change Details Files
Stop logging raw HTTP response bodies in request_sync to avoid leaking sensitive information while preserving useful status code logs.
  • Keep existing logging of expected OK code and actual HTTP response status code.
  • Remove interpolation of response.text from logs to prevent clear-text exposure of potentially sensitive data.
  • Add a generic log line indicating the response body is intentionally omitted for security reasons.
action_devices.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request implements a crucial security enhancement by modifying the logging behavior within the request_sync function. The change prevents the inadvertent exposure of sensitive data, such as API keys or full response bodies, in logs, thereby mitigating a potential information disclosure vulnerability identified by code scanning.

Highlights

  • Security Fix: Addressed a code scanning alert (no. 10) by preventing clear-text logging of sensitive information, specifically response bodies, in the request_sync function.
  • Logging Adjustment: Replaced the logging of the full response.text with a generic message indicating that the response body is omitted for security reasons, while retaining status code logging.
Changelog
  • action_devices.py
    • Replaced logging of the full HTTP response body with a security message to prevent sensitive data leakage.
Activity
  • The pull request was created by DaTiC0 to address a code scanning alert regarding clear-text logging of sensitive information.
  • The proposed changes were generated with the assistance of Copilot Autofix.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request correctly addresses a security vulnerability by removing sensitive data from logs in action_devices.py. To fully resolve the issue across the project, two other areas should be considered:

  1. A similar logging vulnerability exists in ReportState.py on line 44, where response.text is logged.
  2. The exception handling in request_sync (line 306) and other places could still log sensitive information contained in exception messages, such as API keys in URLs. It's safer to log sanitized error messages instead of the raw exception.

Additionally, I've added a review comment suggesting an improvement to the logging mechanism by using the standard logging module instead of print.

Comment thread action_devices.py
print(f'\nRequests Code: {requests.codes["ok"]}\nResponse Code: {response.status_code}')
print(f'\nResponse: {response.text}')
# Do not log full response body to avoid leaking sensitive information.
print('\nResponse body omitted from logs for security reasons')

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.

medium

Using print() for application logging is not a best practice. The standard logging module offers more robust features like log levels, different handlers, and formatting, which are crucial for production environments. I recommend replacing print() with a proper logger throughout the application, for instance using logging.info() here.

…rough an exception

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@DaTiC0 DaTiC0 closed this Mar 7, 2026
@DaTiC0
DaTiC0 deleted the alert-autofix-10 branch March 7, 2026 21:33
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