-
Notifications
You must be signed in to change notification settings - Fork 53
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
Add: the ability to redact values from Stringer and Error interface. #592
Conversation
Implemented privacy measures to strip all PII from zap log entries, and from the outputs of String() and Error() methods. This update minimizes privacy risks by sanitizing log entries and error information.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dev #592 +/- ##
==========================================
+ Coverage 69.01% 69.03% +0.01%
==========================================
Files 140 140
Lines 23523 23625 +102
==========================================
+ Hits 16235 16309 +74
- Misses 4228 4242 +14
- Partials 3060 3074 +14 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
on behalf of @r-hang
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good on behalf of @tchung1118.
We can add the redacted feature designation to zap logs instead if skipping them outright.
@@ -852,3 +853,26 @@ func TestLogNilStruct(t *testing.T) { | |||
require.NoError(t, x.MarshalLogObject(enc)) | |||
assert.Empty(t, enc.Fields) | |||
} | |||
|
|||
func TestZapOptOut(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a new test? Should we also be adding a the case here for a redacted field since we're adding this new feature here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it is. I noticed that no tests have been conducted for ZapOut. Implementing a small test could help increase our code coverage. I updated the test and add a test case.
Currently, there's no feature to exclude sensitive information from outputs generated by the Stringer and Error interface implementations. However, we use the nolog annotation to exclude specific properties from being logged by the zap.objectMarshal method. This is particularly useful for omitting sensitive data in zap logger outputs. Despite this, there are scenarios where sensitive information might still be exposed. For instance, consider the following example:
The code snippet above leads to the following implementation for the MarshalLogObject method:
However, our implementation of the Stringer and Error interfaces inadvertently exposes properties marked with nolog:
This behavior can lead to unintended exposure of information annotated as
nolog
. For example, when this exception is utilized as an Error, or when logged usingzap.Stringer("exception", e)
orzap.Error(e)
, the nolog-annotated property is inadvertently revealed:playground link
This PR introduces a new feature that enables the redaction of specified properties through a new Go annotation, go.redacted. When applied, this annotation ensures that the actual value of a property is replaced with in the outputs generated by our Stringer and Error interface implementations.
Output after this diff: