Skip to content
Merged
Show file tree
Hide file tree
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
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1516,9 +1516,6 @@ for the path string format and more examples. But in general:

Specific values to be masked can be specified in several ways, as seen in the following example:

When using regexes to identify strings to mask, all matches within each string field value will be replaced.
If you want to match the full string field value, then use the beginning of line (`^`) and end of line (`$`) markers.

```xml
<encoder class="net.logstash.logback.encoder.LogstashEncoder">
<jsonGeneratorDecorator class="net.logstash.logback.mask.MaskingJsonGeneratorDecorator">
Expand Down Expand Up @@ -1561,6 +1558,13 @@ If you want to match the full string field value, then use the beginning of line
Identifying data to mask by value is much more expensive than identifying data to mask by [path](#identifying-field-values-to-mask-by-path).
Therefore, prefer identifying data to mask by path.

The value to mask is passed through every value masker, with the output of one masker passed as input to the next masker.
This allows each masker to mask specific substrings within the value.
The order in which the maskers are executed is not defined, and should not be relied upon.

When using regexes to identify strings to mask, all matches within each string field value will be replaced.
If you want to match the full string field value, then use the beginning of line (`^`) and end of line (`$`) markers.


## Customizing Standard Field Names

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -525,18 +525,22 @@ private Object getMaskedValueForCurrentPath() {
return null;
}
/**
* @param value the value to potentially mask
* @param originalValue the value to potentially mask
* @return the masked value for the current path and value if the value should be masked.
* otherwise returns null.
*/
private Object getMaskedValueForCurrentPathAndValue(Object value) {
private Object getMaskedValueForCurrentPathAndValue(Object originalValue) {
JsonStreamContext context = getOutputContext();
Object localValue = originalValue;
for (ValueMasker valueMasker : valueMaskers) {
Object maskedValue = valueMasker.mask(context, value);
Object maskedValue = valueMasker.mask(context, localValue);
if (maskedValue != null) {
return maskedValue;
localValue = maskedValue;
}
}
if (localValue != originalValue) {
return localValue;
}
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,14 @@ public void maskedAndUnmaskedField() throws IOException {
"value.");
}

@Test
public void maskedSubstrings() throws IOException {
testMaskByValue(
"{\"fieldA\":\"tomask1\",\"fieldB\":\"tomask2\",\"fieldC\":\" tomask1-tomask2 \"}",
"{\"fieldA\":\"****\",\"fieldB\":\"****\",\"fieldC\":\" ****-**** \"}",
"tomask1", "tomask2");
}

@Test
public void onlyMaskedField() throws IOException {
testMaskByPath(
Expand Down