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

Only first ValueMasker is applied #690

Closed
aukevanleeuwen opened this issue Nov 1, 2021 · 0 comments · Fixed by #696
Closed

Only first ValueMasker is applied #690

aukevanleeuwen opened this issue Nov 1, 2021 · 0 comments · Fixed by #696
Milestone

Comments

@aukevanleeuwen
Copy link

Describe the bug
It's up for debate if this is a bug, but at least it is unexpected behaviour to me and I can't find it in the documentation. So filed a bug report anyway.

When configuring multiple ValueMaskers. and both of them would match a certain value, on the first one is applied.

To Reproduce
Steps to reproduce the behavior:

  1. Assuming we have two net.logstash.logback.mask.ValueMaskers:
  • com.example.MatchesOnStringA which would mask all occurences of "StringA" to "*******"
  • com.example.MatchesOnStringB which would mask all occurences of "StringB" to "*******"
  1. Use this logback.xml configuration†:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <include resource="org/springframework/boot/logging/logback/defaults.xml"/>

  <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
      <encoder class="net.logstash.logback.encoder.LogstashEncoder">
          <jsonGeneratorDecorator class="net.logstash.logback.mask.MaskingJsonGeneratorDecorator">
              <valueMasker class="com.example.MatchesOnStringA"/>
              <valueMasker class="com.example.MatchesOnStringB"/>
          </jsonGeneratorDecorator>
      </encoder>
  </appender>

  <root level="INFO">
      <appender-ref ref="CONSOLE"/>
  </root>
</configuration>

† this is maybe not entirely correct configuration, I've manually trimmed a few lines here and there to make it consise

  1. Execute this logger statement:
log.info("StringA and StringB");
  1. See the log

Expected behavior
I would expect this to match

******* and *******

But in fact only the first configured ValueMasker is applied, so the result is

******* and StringB

Additional context
I had a look through the sources and I guess it's to be expected because of this code:

    private Object getMaskedValueForCurrentPathAndValue(Object value) {
        JsonStreamContext context = getOutputContext();
        for (ValueMasker valueMasker : valueMaskers) {
            Object maskedValue = valueMasker.mask(context, value);
            if (maskedValue != null) {
                return maskedValue;
            }
        }
        return null;
    }
philsttr added a commit that referenced this issue Nov 7, 2021
Previously, masking of a single value would stop after the first ValueMasker returned a masked value.
This meant that only one ValueMasker would process a string.
Now, all ValueMaskers are given the opportunity to process a value, which means that multiple substrings can be masked independently by different ValueMaskers

Fixes #690
philsttr added a commit that referenced this issue Nov 7, 2021
* Allow masking of multiple substrings
Previously, masking of a single value would stop after the first ValueMasker returned a masked value.
This meant that only one ValueMasker would process a string.
Now, all ValueMaskers are given the opportunity to process a value, which means that multiple substrings can be masked independently by different ValueMaskers

Fixes #690
@philsttr philsttr added this to the 7.0 milestone Nov 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants