Skip to content
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

Replace secret data with asterisks in debug logs #24

Merged
merged 1 commit into from
Nov 1, 2022
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import java.util.concurrent.ForkJoinWorkerThread;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.atomic.AtomicReference;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.ovirt.vdsm.jsonrpc.client.JsonRpcClient;
import org.ovirt.vdsm.jsonrpc.client.JsonRpcEvent;
Expand Down Expand Up @@ -37,6 +39,8 @@ public final class ResponseWorker extends Thread {
private final ResponseTracker tracker;
private final EventPublisher publisher;
private static final Logger log = LoggerFactory.getLogger(ResponseWorker.class);
private static final Pattern SENSITIVE_DATA_PATTERN = Pattern.compile("(\"_X_[a-zA-Z0-9_]+\": *)\"[^\"]+\"");

static {
MAPPER = new ObjectMapper(new JsonFactoryBuilder()
.configure(JsonFactory.Feature.INTERN_FIELD_NAMES, false)
Expand Down Expand Up @@ -93,7 +97,12 @@ public void run() {
break;
}
if (log.isDebugEnabled()) {
log.debug("Message received: " + new String(contextRef.get().getMessage(), UTF8));
String message = new String(contextRef.get().getMessage(), UTF8);
Matcher matcher = SENSITIVE_DATA_PATTERN.matcher(message);
if (matcher.find()) {
message = matcher.replaceAll("$1\"***\"");
}
log.debug("Message received: " + message);
}
JsonNode rootNode = MAPPER.readTree(contextRef.get().getMessage());
if (!rootNode.isArray()) {
Expand Down