-
Notifications
You must be signed in to change notification settings - Fork 59
fix: [exporter-etw] Enforce depth limit when JSON serializing complex types #238
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?
fix: [exporter-etw] Enforce depth limit when JSON serializing complex types #238
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #238 +/- ##
=======================================
- Coverage 50.3% 50.2% -0.1%
=======================================
Files 60 60
Lines 7651 7640 -11
=======================================
- Hits 3851 3840 -11
Misses 3800 3800 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
@psandana Could you review? This seems safer |
.map(|(k, v)| (k.to_string(), v.as_json_value())) | ||
.collect::<Map<String, Value>>(), | ||
) | ||
const ERROR_MSG: &str = "Maximum allowed nesting depth of `1` exceeded"; |
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.
nit - should we return more structured error message. Eg
json!({ "truncated": true, "type": "list/map", reason: " max depth reached"})
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.
First. I must mention that I'm not a fan of silent failures. I would rather the user gets a panic right away, than unexpectedly finding truncated content in production logs. But I recognize that a proper fix may not come easily, thus, let's move forward.
I +1
@lalitb comment, and we should actually mention this is not an error, is a truncation. I would add the truncation depth as another value. In the future, we could allow users to modify this number under their own risk.
json!({ "truncated": true, "type": "list/map", reason: "max depth reached", reason_depth: "1"})
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.
First. I must mention that I'm not a fan of silent failures. I would rather the user gets a panic right away, than unexpectedly finding truncated content in production logs.
I would have to disagree here. Do we really want a log statement to be capable of bringing down the entire application and affect the user's SLA and business? In my opinion, it's better that we give the user a chance to fix their telemetry without crashing their application.
we should actually mention this is not an error, is a truncation. I would add the truncation depth as another value. In the future, we could allow users to modify this number under their own risk.
This is what the message looks like now: Message truncated as nested lists/maps are not supported.
I think this is much simpler for the user to understand than mentioning depth = 1
etc. We can always include depth information later, if in future we decide to support nested structures. But for now, I favor the simplicity of the current message.
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.
+1, we can't panic. OTel spec has been very clear on this from day 1:
https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/error-handling.md
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.
Do we really want a log statement to be capable of bringing down the entire application and affect the user's SLA and business?
Personally, yes, I would like to fail early. Any piece of code should be covered already by tests, so I would get the panic early anyway. But I just agree is not the way that OTel specification is, so granted :)
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.
Personally, yes, I would like to fail early. Any piece of code should be covered already by tests, so I would get the panic early anyway.
I think this works well for high-level applications/libraries that have controlled and known usage. However, libraries meant for telemetry, serialization, etc. are more foundational. For these base libraries, it's crucial to be secure by default rather than relying on user testing.
Consider Newtonsoft.Json as an example: when a similar CVE was reported, they had to deprecate all previous vulnerable versions and fix the issue themselves. They couldn't simply make this the user's responsibility.
Foundational libraries need to handle edge cases robustly since they're often used in security-sensitive contexts and by developers who may not anticipate all potential attack vectors. This is probably why OpenTelemetry has this guidance.
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.
to be secure by default
I've seen two meanings for the statement above: fail early, or fallback safely. I rather to fail than to produce a wrong and unexpected side effect.
With this in mind, I was thinking that the correct approach may be to:
- Issue a warning that
depth > n
has been reached, and application may crash, withn
default to1
. - Enable a feature to truncate the depth logged if a user-defined depth is trespassed
- Just let the app crash if SO happen. Warnings have been given, and user must configure the library correctly as in previous point.
I think logs nesting dynamically just won't happen. Mostly logs structure will be statically defined. Thus, unexpected SO should be really infrequent.
Addresses #234 (comment)
Changes
1
when serializingAnyValue::ListAny
andAnyValue::HashMap
vec
or aHashMap
containing primitive typesvec
or aHashMap
contains yet anothervec
or aHashMap
we would serialize an error message string instead of parsing it futherMerge requirement checklist
CHANGELOG.md
files updated for non-trivial, user-facing changes