-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Treat zap custom encoders as sanitizers for log-injection checks #20912
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
base: main
Are you sure you want to change the base?
Treat zap custom encoders as sanitizers for log-injection checks #20912
Conversation
d9379df to
360014f
Compare
|
This PR doesn't make much sense. I don't think the tests would pass. There is already a query called |
Hi @owen-mc thanks for looking. I am pretty new to codeql. So I will try and move all the stuff into the correct place when its ready. Am I okay to tag you when It is ready for a review? |
0aea3eb to
997d300
Compare
|
My aim is to allow using a zap encoder with a sanitise within as a valid way to suppress a CWE 117 |
|
Things are in the right place now, but the tests still don't make any sense. May I ask, are you using an LLM coding assistant? Yes, please tag me when you have got the tests passing locally on your machine, or you are stuck and need help with the CodeQL. |
| private predicate isSafeZapEncoder(Type t) { | ||
| exists(Type zapEncoder | | ||
| // Matches go.uber.org/zap/zapcore.JSONEncoder | ||
| zapEncoder.hasQualifiedName("go.uber.org/zap/zapcore", "JSONEncoder") and |
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.
This type doesn't exist, at least according to https://pkg.go.dev/go.uber.org/zap/zapcore.
Summary
Add an experimental CodeQL helper and query to treat custom zap encoders (types implementing go.uber.org/zap/zapcore.Encoder) as sanitizers for the purposes of log-injection detection. This reduces false positives where applications use a custom encoder to escape or sanitize log field values.
Notes for reviewers
Risks