mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-31 09:44:59 +00:00
aider: Scrub sensitive information from verbose logs before saving.
# 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.
This commit is contained in:
parent
fb11754492
commit
7c3bbcede6
1 changed files with 6 additions and 2 deletions
|
@ -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)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue