From 7c3bbcede6d1be500d48755223072fed0dae4164 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Thu, 13 Jul 2023 12:28:05 -0700 Subject: [PATCH] aider: Scrub sensitive information from verbose logs before saving. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Aider chat conversation: USER: open api key saved in log file when run in verbose mode #94 Open joshuavial opened this issue 8 hours ago ยท 2 comments Comments @joshuavial joshuavial commented 8 hours ago Seems like it would be easy for someone (particularly new to coding) to forget to add the log file to a .gitignore and inadvertently publish their key. Maybe the logger should scrub the keys before saving? ASSISTANT: To address this issue, we need to modify the `aider/main.py` file. We will add a function to scrub sensitive information like the OpenAI API key from the verbose logs before they are saved. Here are the steps: 1. Define a new function `scrub_sensitive_info` that takes a string as input and replaces sensitive information (like the OpenAI API key) with a placeholder like `***`. 2. Call this function before logging the arguments in verbose mode. Here is the *edit block* for these changes: ```python aider/main.py <<<<<<< ORIGINAL if args.verbose: show = parser.format_values() io.tool_output(show) io.tool_output("Option settings:") for arg, val in sorted(vars(args).items()): io.tool_output(f" - {arg}: {val}") ======= def scrub_sensitive_info(text): # Replace sensitive information with placeholder return text.replace(args.openai_api_key, '***') if args.verbose: show = scrub_sensitive_info(parser.format_values()) io.tool_output(show) io.tool_output("Option settings:") for arg, val in sorted(vars(args).items()): io.tool_output(f" - {arg}: {scrub_sensitive_info(str(val))}") >>>>>>> UPDATED ``` This change will ensure that the OpenAI API key is not saved in the log file when the program is run in verbose mode. --- aider/main.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/aider/main.py b/aider/main.py index 21e8505b5..c7364dc84 100644 --- a/aider/main.py +++ b/aider/main.py @@ -338,12 +338,16 @@ def main(args=None, input=None, output=None): ) io.tool_output("Git repository created in the current working directory.") + def scrub_sensitive_info(text): + # Replace sensitive information with placeholder + return text.replace(args.openai_api_key, '***') + if args.verbose: - show = parser.format_values() + show = scrub_sensitive_info(parser.format_values()) io.tool_output(show) io.tool_output("Option settings:") for arg, val in sorted(vars(args).items()): - io.tool_output(f" - {arg}: {val}") + io.tool_output(f" - {arg}: {scrub_sensitive_info(str(val))}") io.tool_output(*sys.argv, log_only=True)