Skip to content

Commit 85ffe2e

Browse files
committed
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
1 parent dd0c14b commit 85ffe2e

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

stdlib/InteractiveUtils/src/InteractiveUtils.jl

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ controlled with boolean keyword arguments:
8585
8686
- `verbose`: print all additional information
8787
88+
!!! warning "Warning"
89+
The output of this function may contain sensitive information. Before sharing the output,
90+
please review the output and remove any data that should not be shared publicly.
91+
8892
See also: [`VERSION`](@ref).
8993
"""
9094
function versioninfo(io::IO=stdout; verbose::Bool=false)
@@ -139,15 +143,36 @@ function versioninfo(io::IO=stdout; verbose::Bool=false)
139143
println(io, " LLVM: libLLVM-",Base.libllvm_version," (", Sys.JIT, ", ", Sys.CPU_NAME, ")")
140144

141145
function is_nonverbose_env(k::String)
142-
return occursin(r"^JULIA_|^DYLD_|^LD_", k)
146+
return occursin(r"^JULIA_|^DYLD_|^LD_"i, k)
143147
end
144148
function is_verbose_env(k::String)
145-
return occursin(r"PATH|FLAG|^TERM$|HOME", k) && !is_nonverbose_env(k)
149+
regex = r"""
150+
FLAG|HOME|PATH|^TERM$|
151+
^SSH_DIR$|^SSH_KEY_NAME$|^SSH_KEY_PATH$|^SSH_KNOWN_HOSTS_FILES$|^SSH_PUB_KEY_PATH$|
152+
^SSL_CERT_DIR$|^SSL_CERT_FILE$
153+
"""ix
154+
return occursin(regex, k) && !is_nonverbose_env(k)
155+
end
156+
157+
function should_be_redacted(k::String)
158+
return occursin(r"AUTH|KEY|PASS|PRIV|SECRET|TOKEN"i, k)
159+
end
160+
function format_for_printing(k::String, v::String)
161+
if should_be_redacted(k)
162+
if isempty(v)
163+
v_redacted = ""
164+
else
165+
v_redacted = "***"
166+
end
167+
return " $(k) = $(v_redacted)"
168+
else
169+
return " $(k) = $(v)"
170+
end
146171
end
147172
env_strs = String[
148-
String[" $(k) = $(v)" for (k,v) in ENV if is_nonverbose_env(uppercase(k))];
173+
String[format_for_printing(k, v) for (k,v) in ENV if is_nonverbose_env(uppercase(k))];
149174
(verbose ?
150-
String[" $(k) = $(v)" for (k,v) in ENV if is_verbose_env(uppercase(k))] :
175+
String[format_for_printing(k, v) for (k,v) in ENV if is_verbose_env(uppercase(k))] :
151176
String[]);
152177
]
153178
if !isempty(env_strs)

0 commit comments

Comments
 (0)