Skip to content

InteractiveUtils.versioninfo(): when verbose=true, print environment variables that might affect the NetworkOptions stdlib; also, try to redact some (but not all) sensitive environment variables #43836

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

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions stdlib/InteractiveUtils/src/InteractiveUtils.jl
Original file line number Diff line number Diff line change
@@ -139,15 +139,36 @@ function versioninfo(io::IO=stdout; verbose::Bool=false)
println(io, " LLVM: libLLVM-",Base.libllvm_version," (", Sys.JIT, ", ", Sys.CPU_NAME, ")")

function is_nonverbose_env(k::String)
return occursin(r"^JULIA_|^DYLD_|^LD_", k)
return occursin(r"^JULIA_|^DYLD_|^LD_"i, k)
end
function is_verbose_env(k::String)
return occursin(r"PATH|FLAG|^TERM$|HOME", k) && !is_nonverbose_env(k)
regex = r"""
FLAG|HOME|PATH|^TERM$|
^SSH_DIR$|^SSH_KEY_NAME$|^SSH_KEY_PATH$|^SSH_KNOWN_HOSTS_FILES$|^SSH_PUB_KEY_PATH$|
^SSL_CERT_DIR$|^SSL_CERT_FILE$
"""ix
return occursin(regex, k) && !is_nonverbose_env(k)
end

function should_be_redacted(k::String)
return occursin(r"AUTH|KEY|PASS|PRIV|SECRET|TOKEN"i, k)
end
function format_for_printing(k::String, v::String)
if should_be_redacted(k)
if isempty(v)
v_redacted = ""
else
v_redacted = "***"
end
return " $(k) = $(v_redacted)"
else
return " $(k) = $(v)"
end
end
env_strs = String[
String[" $(k) = $(v)" for (k,v) in ENV if is_nonverbose_env(uppercase(k))];
String[format_for_printing(k, v) for (k,v) in ENV if is_nonverbose_env(uppercase(k))];
(verbose ?
String[" $(k) = $(v)" for (k,v) in ENV if is_verbose_env(uppercase(k))] :
String[format_for_printing(k, v) for (k,v) in ENV if is_verbose_env(uppercase(k))] :
String[]);
]
if !isempty(env_strs)