diff --git a/src/main/java/org/jenkinsci/plugins/workflow/log/FileLogStorage.java b/src/main/java/org/jenkinsci/plugins/workflow/log/FileLogStorage.java index a4d7ae9a..000ce890 100644 --- a/src/main/java/org/jenkinsci/plugins/workflow/log/FileLogStorage.java +++ b/src/main/java/org/jenkinsci/plugins/workflow/log/FileLogStorage.java @@ -169,14 +169,62 @@ private final class IndexOutputStream extends OutputStream { @Override public void write(@NonNull byte[] b) throws IOException { synchronized (FileLogStorage.this) { checkId(id); - bos.write(b); + maskedWrite(b, 0, b.length); } } @Override public void write(@NonNull byte[] b, int off, int len) throws IOException { synchronized (FileLogStorage.this) { checkId(id); - bos.write(b, off, len); + maskedWrite(b, off, len); + } + } + + /* + * Mask the sensitive data in the log + */ + private void maskedWrite(@NonNull byte[] b, int off, int len) throws IOException { + String in = new String(b, off, len); + + String regexPattern = "(? 0) { + String left = new String(b, off, leftStringLen); + String outString = left.replaceAll(regexPattern, replacementString); + bos.write(outString.getBytes()); + } + + String consoleNote = new String(b, off + preamble_idx, consoleNoteLen); + System.out.println("consoleNote:" + consoleNote); + + if (rightStringLen > 0) { + String right = new String(b, off + postamble_idx + postamble_length, rightStringLen); + String outString = right.replaceAll(regexPattern, replacementString); + bos.write(outString.getBytes()); } }