Fixes - API key printing in log and Vulnerabilities#483
Fixes - API key printing in log and Vulnerabilities#483shree1988 wants to merge 1 commit intodatacommonsorg:masterfrom
Conversation
Summary of ChangesHello @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
Changelog
Activity
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
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.
| 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:]}" |
There was a problem hiding this comment.
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:]}"|
/gcbrun |
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.