feat: add attribute value depth limit configuration - #702
Draft
pellared wants to merge 3 commits into
Draft
Conversation
trentm
pushed a commit
to trentm/opentelemetry-specification
that referenced
this pull request
Aug 7, 2026
…-telemetry#5186) Towards open-telemetry#4911 Per open-telemetry#4006 (comment) ### Motivation Bound (limit) the processing of nested attribute values. It could also mitigate possible recursive processing of nested attribute values if languages allow it. The default of 64 is intentionally conservative. It matches the .NET `System.Text.Json` default and is the lowest non-unlimited nesting/depth default found in the parsers checked. Exact depth-counting semantics differ between libraries, so this table is used only as rationale for the default value. | Library / parser | Ecosystem | Default nesting/depth limit | Notes | | --- | --- | ---: | --- | | `System.Text.Json` | .NET | 64 | `MaxDepth` default value of `0` means a maximum depth of 64. | | `serde_json` | Rust | 128 | `Deserializer` initializes `remaining_depth` to 128. | | Gson `JsonReader` | Java | 255 | `DEFAULT_NESTING_LIMIT = 255`; docs describe it as protection against recursive stack overflow. | | Moshi `JsonReader` | JVM / Kotlin | 256 | Internal stack grows up to 256 levels, including the top-level document. | | Jackson `StreamReadConstraints` | Java | 1000 | `DEFAULT_MAX_DEPTH = 1000`. | | Go `encoding/json` | Go | 10000 | Internal scanner cap exists to prevent stack overflow. | ### Changes - Add `AttributeValueDepthLimit` to the common attribute limit rules with a default of 64. - Define depth counting explicitly: depth starts at 1 for the top-level attribute value and increments when descending into array elements or map values. - Replace any nested array or map with an empty value to not go beyond the limit. The depth limiting algorithm matches what e.g. `System.Text.Json` would expect if they have the same limit. ### Prototype - open-telemetry/opentelemetry-java#8656 - open-telemetry/opentelemetry-go#8534 ### Declarative config - open-telemetry/opentelemetry-configuration#702 ### Notes - This PR does not add an environment variable for the new limit. - This is updating a stable part of the specification. However, I classify this as a bugfix as having unbounded processing is not desired (https://cwe.mitre.org/data/definitions/789.html). --------- Co-authored-by: Carlos Alberto Cortez <calberto.cortez@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add configuration for limit introduced in: