-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Disable HTMLEscape for zapcore.JSONEncoder #700
Comments
Seems reasonable, from the json documentation:
Since zap logs to console or to files, I don't think the security concerns affect zap. Thoughts @abhinav? |
This seems like it would be a significant behavioral change. I disagree that I still think this is a reasonable ask but it should be opt-in. Perhaps a new |
Actually looking more at the code, we already don't try to protect against this. Zap uses a custom JSON encoder for known primitives, and these types are not protected: Lines 429 to 431 in badef73
And the tests also verify that we don't escape zap/zapcore/json_encoder_impl_test.go Lines 75 to 76 in badef73
I verified by changing one of the example tests to include
The only case where we don't escape is within a nested object that's encoded by the JSON reflection library. I think there's no reason not to enable this by default since we're already not protecting against this case. |
Fair enough. |
Fixes #700. Zap's custom JSON encoder does not escape HTML, so make encoding by the reflect-based JSON encoder work the same way.
Fixes #700. Zap's custom JSON encoder does not escape HTML, so make encoding by the reflect-based JSON encoder work the same way.
Fixes uber-go#700. Zap's custom JSON encoder does not escape HTML, so make encoding by the reflect-based JSON encoder work the same way.
Hi,
I've been used zap for structured logging using
zap.JSONEncoder
, but currently it encodes HTML characters like (<
,>
,&
) to Unicode codes (\u003c
,\u003e
,\u0026
). So, the log that would be:{ "level": "info", "time": "2019-04-17T19:54:53.739900902Z", "caller": "go-log/main.go:90", "message": "Hello & World" }
It is logged as:
{ "level": "info", "time": "2019-04-17T19:54:53.739900902Z", "caller": "go-log/main.go:90", "message": "Hello \u0026 World" }
My sugestion is to disable the HTML Escape in the
zap.JSONEncoder
after line zapcore/json_encoder.go#L139 as follow:enc.reflectEnc.SetEscapeHTML(false)
The text was updated successfully, but these errors were encountered: