更新时 日志输出新进程命令行时 打码敏感信息 (#6456)

This commit is contained in:
辞庐 authored and GitHub committed 2026-07-21 21:30:32 +08:00
1 parent 4c9cd950e4
commit fe05bb58a4
1 file changed
+24 -1
@@ -47,6 +47,7 @@ import java.util.concurrent.CancellationException;
import java.util.concurrent.CountDownLatch;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import static org.jackhuang.hmcl.ui.FXUtils.checkFxUserThread;
import static org.jackhuang.hmcl.util.Lang.thread;
@@ -220,13 +221,35 @@ public final class UpdateHandler {
commandline.add("-jar");
commandline.add(jar.toAbsolutePath().toString());
commandline.addAll(Arrays.asList(appArgs));
LOG.info("Starting process: " + commandline);
LOG.info("Starting process: " + maskCommandline(commandline));
new ProcessBuilder(commandline)
.directory(Paths.get("").toAbsolutePath().toFile())
.inheritIO()
.start();
}
private static String maskCommandline(List<String> commandline) {
return commandline.stream().map(str -> {
if (str.startsWith("-D")) {
int eqIdx = str.indexOf('=');
if (eqIdx != -1) {
String key = str.substring(2, eqIdx);
String value = str.substring(eqIdx + 1);
if (key.contains("http.proxy") ||
key.startsWith("https.proxy") ||
key.startsWith("socksProxy") ||
key.equals("hmcl.microsoft.auth.id") ||
key.equals("hmcl.curseforge.apikey")
) {
return "-D" + key + "=" + (value.isEmpty() ? "" : value.charAt(0) + "*".repeat(value.length() - 1));
}
}
}
return str;
}).collect(Collectors.joining(" "));
}
private static Optional<Path> tryRename(Path path, String newVersion) {
String filename = path.getFileName().toString();
Matcher matcher = Pattern.compile("^(?<prefix>[hH][mM][cC][lL][.-])(?<version>\\d+(?:\\.\\d+)*)(?<suffix>\\.[^.]+)$").matcher(filename);