Skip to content

feat(decoder): expose the maximum nesting depth as a configuration option - #77

Merged
Spomky merged 1 commit into
3.1.xfrom
feat/decoder-max-depth-option-3.1.x
Aug 31, 2026
Merged

feat(decoder): expose the maximum nesting depth as a configuration option#77
Spomky merged 1 commit into
3.1.xfrom
feat/decoder-max-depth-option-3.1.x

Conversation

@Spomky

@Spomky Spomky commented Aug 31, 2026

Copy link
Copy Markdown
Member

Targets the new 3.1.x branch, cut from 3.0.x: this adds a feature, so it does not belong on a patch branch.

What

spomky-labs/cbor-php 3.3.3 bounds how deeply nested a decoded data item may be — without it, a payload of a few dozen kilobytes made only of nested arrays builds an object graph deep enough to segfault the process when it is released, after decode() has already returned. The bundle now exposes that bound:

# config/packages/cbor.yaml
cbor:
    max_depth: 1000 # Default, CBOR\Decoder::DEFAULT_MAX_DEPTH

A much lower value is worth setting when the decoded data comes from an untrusted source:

cbor:
    max_depth: 32

How

The bundle had no configuration at all — getConfiguration() returned null. It now returns a Configuration with a single max_depth integer node (default Decoder::DEFAULT_MAX_DEPTH, minimum 1, info() filled in for config:dump-reference). The value lands in the cbor.max_depth container parameter and is passed to the Decoder service as its $maxDepth argument; the tag and other object managers keep being autowired, so nothing else about the service changes.

spomky-labs/cbor-php moves from ^3.0 to ^3.3.3, the release that introduces Decoder::DEFAULT_MAX_DEPTH.

The PHPStan baseline is regenerated: narrowing getConfiguration() to a non-nullable return type removes one of its entries.

Tests

tests/Functional/MaxDepthTest.php boots the test kernel with max_depth: 64 and checks the parameter value, that 64 levels decode, and that 65 are rejected with the exact message. Full suite: 32 tests, 35 assertions.

Verified locally in ghcr.io/spomky-labs/phpqa:8.4: PHPStan, ECS, Rector, parallel-lint, Deptrac, licenses, PHPUnit and Infection all pass.

…tion

spomky-labs/cbor-php 3.3.3 bounds how deeply nested a decoded data item may be,
so that a small payload of nested arrays can no longer build an object graph deep
enough to crash the process when it is released. That bound is now reachable from
the bundle configuration:

    cbor:
        max_depth: 1000 # CBOR\Decoder::DEFAULT_MAX_DEPTH

The value is passed to the Decoder service as its $maxDepth argument, while the
tag and other object managers keep being autowired. A much lower value is worth
setting when the decoded data comes from an untrusted source.
@Spomky Spomky self-assigned this Aug 31, 2026
@Spomky Spomky added this to the 3.1.0 milestone Aug 31, 2026
@Spomky Spomky added the enhancement New feature or request label Aug 31, 2026
@Spomky
Spomky merged commit f0705af into 3.1.x Aug 31, 2026
16 checks passed
@Spomky
Spomky deleted the feat/decoder-max-depth-option-3.1.x branch August 31, 2026 17:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

1 participant