You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CHANGELOG
+4Lines changed: 4 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,9 @@
1
1
# Changelog for Serilog.Enrichers.Sensitive
2
2
3
+
## 1.2.0
4
+
5
+
- Add `ShouldMaskMatch` to the `RegexMaskingOperator` to allow implementors to perform further checks on the sensitive value in order to decide whether or not to perform masking
6
+
3
7
## 1.1.0
4
8
5
9
- Add support to supply a custom mask value [#6](https://github.com/serilog-contrib/Serilog.Enrichers.Sensitive/issues/6)
Copy file name to clipboardExpand all lines: README.md
+14-13Lines changed: 14 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -135,23 +135,24 @@ the rendered log message comes out as: `"This is a sensitive ***MASKED***"`
135
135
136
136
## Extending to additional use cases
137
137
138
-
Extending this enricher is a fairly straight forward process.
138
+
Depending on the type of masking operation you want to perform, the `RegexMaskingOperator` base class is most likely your best starting point. It provides a number of extension points:
139
139
140
-
1. Create your new class and inherit from the RegexMaskingOperator base class
141
-
1. Pass your regex pattern to the base constructor
142
-
2. To control if the regex replacement should even take place, override ShouldMaskInput, returning `true` if the mask should be applied, and `false` if it should not.
143
-
3. Override PreprocessInput if your use case requires adjusting the input string before the regex match is applied.
144
-
4. Override PreprocessMask if your use case requires adjusting the mask that is applied (for instance, if your regex includes named groups). See the [CreditCardMaskingOperator](src/Serilog.Enrichers.Sensitive/CreditCardMaskingOperator.cs) for an example.
145
-
2. When configuring your logger, pass your new encricher in the collection of masking operators
140
+
| Method | Purpose |
141
+
|--------|---------|
142
+
| ShouldMaskInput | Indicate whether the operator should continue with masking the input |
143
+
| PreprocessInput | Perform any operations on the input value before masking the input |
144
+
| PreprocessMask | Perform any operations on the mask before masking the matched value |
145
+
| ShouldMaskMatch | Indicate whether the operator should continue with masking the matched value from the input |
146
+
147
+
To implement your own masking operator, inherit from `RegexMaskingOperator`, supply the regex through the base constructor and where necessary override any of the above extension points.
148
+
149
+
Then, when configuring your logger, pass your new encricher in the collection of masking operators:
varmaskedResult=_regex.Replace(preprocessedInput, match =>
38
+
{
39
+
if(ShouldMaskMatch(match))
40
+
{
41
+
returnmatch.Result(PreprocessMask(mask));
42
+
}
43
+
44
+
returnmatch.Value;
45
+
});
46
+
32
47
varresult=newMaskingResult
33
48
{
34
49
Result=maskedResult,
@@ -38,10 +53,35 @@ public MaskingResult Mask(string input, string mask)
38
53
returnresult;
39
54
}
40
55
56
+
/// <summary>
57
+
/// Indicate whether the operator should continue with masking the input
58
+
/// </summary>
59
+
/// <param name="input">The message template or the value of a property on the log event</param>
60
+
/// <returns><c>true</c> when the input should be masked, otherwise <c>false</c>. Defaults to <c>true</c></returns>
61
+
/// <remarks>This method provides an extension point to short-circuit the masking operation before the regular expression matching is performed</remarks>
/// Indicate whether the operator should continue with masking the matched value from the input
81
+
/// </summary>
82
+
/// <param name="match">The match found by the regular expression of this operator</param>
83
+
/// <returns><c>true</c> when the match should be masked, otherwise <c>false</c>. Defaults to <c>true</c></returns>
84
+
/// <remarks>This method provides an extension point to short-circuit the masking operation if the value matches the regular expression but does not satisfy some additional criteria</remarks>
0 commit comments