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

Require Explicitly initialize Email regex mask operator #9

Closed
Eliemer opened this issue Sep 16, 2022 · 4 comments
Closed

Require Explicitly initialize Email regex mask operator #9

Eliemer opened this issue Sep 16, 2022 · 4 comments

Comments

@Eliemer
Copy link

Eliemer commented Sep 16, 2022

I do not intend to mask emails in my logs, only using MaskProperties, but this enricher masks emails by default. I also don't have an option to opt-out of this operator either.

The issue im having is I have a property that can sometimes be a valid email address but its not required to be. Its simply a human-readable identifier. In the cases that it is an email address, this enricher is masking that value

// Configures Serilog: sinks and enrichers go here
let initializeLogging (configuration: IConfigurationRoot) =
    Log.Logger <-
        LoggerConfiguration()
            // read from Serilog section of json config files
            .ReadFrom
            .Configuration(
                configuration
            )
            .Enrich
            // FIX: this constructor automatically adds Email regex matching everywhere
            .WithSensitiveDataMasking(
                // these properties will always be masked if they are present.
                // the field names are case insensitive
                Action<SensitiveDataEnricherOptions>(fun opts -> opts.MaskProperties.AddRange([ "Secrets"; "Password" ]))
            )
            .Destructure.FSharpTypes()
            .CreateLogger()
@Eliemer
Copy link
Author

Eliemer commented Sep 16, 2022

as an aside, maybe we can also add NeverMaskProperties to exclude properties from regex operators that may match it

@sandermvanvliet
Copy link
Contributor

You can configure the enricher to only mask a specific property and ignore the rest like so:

new LoggerConfiguration()
    .Enrich
    .WithSensitiveDataMasking(
        options =>
        {
            options.MaskingOperators.Clear();
            options.MaskProperties.AddRange([ "Secrets"; "Password" ]);
        });

That will remove all the default masking operators and always mask the Secrets and Password properties.

I don’t have a computer handy here to test so while I think this works it might not 😉

@sandermvanvliet
Copy link
Contributor

as an aside, maybe we can also add NeverMaskProperties to exclude properties from regex operators that may match it

Good suggestion 👍
I’ll include this in the next release

@sandermvanvliet
Copy link
Contributor

I've decided to not change the behavior of the configuration just yet as that would break usage if you already have implemented the package in your app. Suddenly the masking would not be active anymore and that's a surprise I don't want to spring on users.

In the meantime, if you don't want the default masking operators (or basically, good practice anyway) you should indicate the list of masking operators that are relevant to your application like so:

new LoggerConfiguration()
    .Enrich
    .WithSensitiveDataMasking(
        options =>
        {
            options.MaskingOperators = new List<IMaskingOperator> 
            {
                new EmailAddressMaskingOperator(),
                new IbanMaskingOperator()
                // etc etc
            };
        });

I've updated the README to reflect this.

In the meantime I've also added a ExcludeProperties option which you can use to exclude properties from masking even if their values would match a masking operator.

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

No branches or pull requests

2 participants