Repository navigation
Potential fix for code scanning alert no. 35: Clear-text logging of sensitive information #5564
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -437,14 +437,35 @@ def format_docker_command(docker_command): | |
| f"{shlex.quote(docker_command[0])} {shlex.quote(docker_command[1])}" | ||
| ) | ||
| i = 2 | ||
|
|
||
| sensitive_env_keys = {"API_KEY", "OPENAI_API_KEY"} | ||
|
|
||
| def _redact_env_arg(env_assignment: str) -> str: | ||
| if "=" not in env_assignment: | ||
| return env_assignment | ||
| key, value = env_assignment.split("=", 1) | ||
| key_upper = key.upper() | ||
| if ( | ||
| key_upper in sensitive_env_keys | ||
| or "TOKEN" in key_upper | ||
| or "SECRET" in key_upper | ||
| or "PASSWORD" in key_upper | ||
| or key_upper.endswith("_KEY") | ||
| ): | ||
| return f"{key}=***REDACTED***" | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The placeholder is appropriate for diagnostic logs, but copying the printed command now sets the container API key to the literal |
||
| return f"{key}={value}" | ||
|
|
||
| while i < len(docker_command): | ||
| quoted = shlex.quote(docker_command[i]) | ||
| if ( | ||
| docker_command[i].startswith("-") | ||
| and i + 1 < len(docker_command) | ||
| and not docker_command[i + 1].startswith("-") | ||
| ): | ||
| next_quoted = shlex.quote(docker_command[i + 1]) | ||
| next_arg = docker_command[i + 1] | ||
| if docker_command[i] in ("-e", "--env"): | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Smaller completeness point: this catches separate |
||
| next_arg = _redact_env_arg(next_arg) | ||
| next_quoted = shlex.quote(next_arg) | ||
| lines.append(f"{quoted} {next_quoted}") | ||
| i += 2 | ||
| else: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we narrow the token matching?
"TOKEN" in key_upperalso redacts ordinary settings such asVLLM__MAX_NUM_BATCHED_TOKENS=3072, which our embedding model specs use, andTOKENIZERS_PARALLELISM=false. This hides useful debugging information and makes copied commands pass***REDACTED***where a number or boolean is expected. Known credential names plus narrower patterns such as_TOKEN,_SECRET, and_PASSWORDwould avoid these false positives. A regression test for an ordinary token-count setting would be useful.