Repository navigation
Add opt-in rfl::MaxDepth<N> processor for recursion-depth DoS protection - #130
Draft
clockblocker wants to merge 1 commit into
Draft
clockblocker wants to merge 1 commit into
clockblocker wants to merge 1 commit into
Conversation
…pth DoS protection
This was referenced Nov 28, 2026
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.
Summary
Adds an opt-in
rfl::MaxDepth<N>processor that bounds container and struct nesting depth during deserialization, returning anrfl::Errorinstead of overflowing the C++ call stack on deeply nested untrusted inputs (such asrfl::Genericor recursiverfl::Box<Node>structs).if constexpr (internal::max_depth_v<ProcessorsType> > 0)— emits zero instructions and zero TLS lookups whenrfl::MaxDepthis not passed.VectorParser,MapParser,NamedTupleParser::read_view/read_view_with_default,ParserArray,TupleParser,FieldVariantParser) so it applies uniformly across JSON, YAML, TOML, XML, CBOR, MsgPack, etc.ParseDepthGuard(exception-safe and thread-safe, matching#72ActiveNodeGuard), supports nestedrfl::Processors<...>, andstatic_asserts againstMaxDepth<0>or duplicateMaxDepthprocessors.docs/content/processors.mdand addedtests/json/test_max_depth.cpp(exact depth boundaries, 5,000-level nested arrays & recursive structs,DefaultIfMissing, maps,std::array,std::tuple, and post-error recovery).Motivation
Underlying DOM parsers like
yyjsonparse thousands of levels of nested arrays/objects iteratively on the heap without crashing, after whichreflect-cpp's recursive C++Parser::readoverflows the call stack (SIGSEGV) on untrusted input (rfl::Genericor recursiverfl::Box<Node>structs).rfl::MaxDepth<N>closes that stack-overflow DoS vector inreflect-cpp's own layer (same crash class as#72's YAML cyclic-alias guard).Verification
-Wall -Wextra -Wpedantic -Wshadow -Wconversion -Werror):rfl/MaxDepth.hppandrfl/internal/max_depth.hpppassed; 0 relative-include errors.static_assertverified forMaxDepth<0>and duplicateMaxDepth.tests/json/test_max_depth.cppunder-fsanitize=undefined -fno-sanitize-recover=all: 3/3 passed (including 5,000-level deep arrays & recursiverfl::Box<Node>structs).