Skip to content

Fixes - API key printing in log and Vulnerabilities#483

Open
shree1988 wants to merge 1 commit intodatacommonsorg:masterfrom
shree1988:bug/fix-printing-api-key-in-logs
Open

Fixes - API key printing in log and Vulnerabilities#483
shree1988 wants to merge 1 commit intodatacommonsorg:masterfrom
shree1988:bug/fix-printing-api-key-in-logs

Conversation

@shree1988
Copy link

Discovered a bug where the API key is being printed in the logs during job execution. To resolve this, I have added slicing to ensure that only a few characters are printed for identification purposes.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @shree1988, 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 focuses on improving the security posture of the application by addressing two key areas: preventing the full exposure of API keys in logs and updating core dependencies to mitigate known vulnerabilities. The changes ensure that sensitive credentials are not inadvertently logged in plain text and that the application runs on a more secure and up-to-date Python environment.

Highlights

  • Security Enhancement: Implemented a mask_key utility function to obscure API keys in logs, preventing sensitive information from being fully exposed during job execution.
  • Dependency Update: Updated the base Python image in the Dockerfile from 3.11.4-slim to 3.11.14-slim to address potential vulnerabilities and ensure the use of a more recent, stable version.
Changelog
  • build/simple/Dockerfile
    • Updated the base Python image version from 3.11.4-slim to 3.11.14-slim.
  • simple/util/dc_client.py
    • Added a new mask_key function to partially obscure API keys.
    • Applied the mask_key function to the API key logging statement to prevent full key exposure.
Activity
  • No activity has occurred on this pull request yet.
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.

Copy link
Contributor

@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 effectively addresses the security concern of logging sensitive API keys by introducing a mask_key utility function. The implementation of mask_key correctly obfuscates the API key in log outputs, significantly improving security. Additionally, the Dockerfile has been updated to use a more recent Python patch version, which is a good practice for stability and security.

Comment on lines +73 to +85
def mask_key(key: str, show: int = 5, max_visible_percent: float = 0.3) -> str:
if not key:
return ""

length = len(key)
max_visible = int(length * max_visible_percent)
visible_each_side = min(show, max_visible // 2)

if visible_each_side < 1 or length <= visible_each_side * 2:
return "*" * length

middle = "*" * (length - visible_each_side * 2)
return f"{key[:visible_each_side]}{middle}{key[-visible_each_side:]}"
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Please add a docstring to the mask_key function. This will improve code readability and maintainability, making it easier for other developers to understand its purpose, arguments, and return value without needing to read the implementation details.

def mask_key(key: str, show: int = 5, max_visible_percent: float = 0.3) -> str:
  """Masks a key for logging purposes, showing only parts of it.

  Args:
    key: The string key to mask.
    show: The number of characters to show from each end of the key.
    max_visible_percent: The maximum percentage of the key's length that can be
      visible from both ends combined.

  Returns:
    A masked string of the key.
  """
  if not key:
    return ""

  length = len(key)
  max_visible = int(length * max_visible_percent)
  visible_each_side = min(show, max_visible // 2)

  if visible_each_side < 1 or length <= visible_each_side * 2:
    return "*" * length

  middle = "*" * (length - visible_each_side * 2)
  return f"{key[:visible_each_side]}{middle}{key[-visible_each_side:]}"

@dwnoble
Copy link
Contributor

dwnoble commented Feb 27, 2026

/gcbrun

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