Skip to content

fix(server): parse request bodies nested to the depth the service validates - #807

Open
LeeroyHannigan wants to merge 20 commits into
mainfrom
fix/request-nesting-depth
Open

LeeroyHannigan wants to merge 20 commits into
mainfrom
fix/request-nesting-depth

Conversation

@LeeroyHannigan

@LeeroyHannigan LeeroyHannigan commented Nov 3, 2026 •

Copy link
Copy Markdown
Collaborator

Changes since the last review

  • 71b3e1b test(server): pin the edges of the syntax check's looser rules. No row tested the edges of two of the looser rules. Three changes to the check each passed the unit tests, and the check with all three passed the wire file. The changes are any printable byte after \u, no + among the number bytes, and a number that starts with + or .. The commit adds rows at 63 and at 20000 wrappers to the syntax tests of request_parse.rs and to tests/test_request_nesting_depth.py. The numbers 1+, 1e+5 and 1.eE-+ and the escape \ugggg reach authentication. The numbers +1 and .5 and the escapes \u000/ and \u000h get a SerializationException before it. The service gives each body that answer, unsigned and badly signed, on 2 of 2 sends (us-east-1, 2026-11-25). Each of the three changes above fails a new unit test row and passes the unit tests of 027483d. A server with all three fails 28 of the 32 new wire cases and passes the 73 cases of 027483d. Its four \ugggg cases pass, because none of the three changes narrows the range after \u. At 71b3e1b, cargo fmt --all -- --check is clean. So are cargo +1.97.0 clippy -p extenddb-server --all-targets -- -D warnings and cargo +1.91.1 check -p extenddb-server --all-targets. The 12 request_parse unit tests pass. On SQLite, test_request_nesting_depth (105) and test_continuous_backups (9) pass. The clippy step of wasm.yml is clean, run locally with a stand-in C compiler because clippy does not link. pytest --collect-only collects tests/ (6765) and tests/python (672) with no error.
  • 027483d docs(wasm): say that admit runs on the result of parse_request. The WebAssembly adapter's module doc in crates/wasm-adapter/src/runtime.rs said that Engine::dispatch runs the operation name check and ParsedRequest::admit through extenddb_engine::parse_request. Only the name check runs in parse_request. dispatch calls admit on the ParsedRequest that parse_request returns. The module doc now says so, and so does the What section below. At 027483d, cargo fmt --all -- --check is clean. So is cargo +1.97.0 clippy -p extenddb-server -p extenddb-engine -p extenddb-wasm-adapter --all-targets -- -D warnings, and cargo +1.91.1 check -p extenddb-wasm-adapter --all-targets. The 12 request_parse unit tests pass. On SQLite, test_request_nesting_depth (73) and test_continuous_backups (9) pass. The clippy step of wasm.yml is clean, run locally with a stand-in C compiler because clippy does not link. pytest --collect-only collects tests/ (6733) and tests/python (672) with no error.
  • The Breaking changes section now lists the answers that this branch changes and the stack size that a host must give the server's worker threads. It said "None.".
  • 1a9efd7 refactor(server): run the engine's operation check and admit around the server's parse. feat(wasm): [Add WebAssembly browser support for ExtendDB #1009 moved the checks before dispatch into extenddb_engine::parse_request and ParsedRequest::admit. The engine now makes the operation name check a step of its own: check_operation returns a KnownOperation. KnownOperation::with_body takes the body that this branch's parser reads and returns the ParsedRequest. The handler calls check_operation before its depth scan. After authentication it calls with_body(input).admit(), in place of its own is_known_operation and refuse_point_in_time_recovery calls. No answer changes. The WebAssembly adapter still calls parse_request(..)?.admit(), and parse_request is check_operation and the serde_json parse. The docs that name the callers now say this. They are the module doc of pre_dispatch.rs, the handler comments, the adapter's module doc, the doc of malformed_body_error and the README's list of the server's checks. The five pre_dispatch unit tests reach the two new functions through parse_request. Three mutants each fail one of them: one accepts every operation, one drops the operation in with_body and one drops the body. The commit adds 43 and removes 22 lines of code, and adds no test.
  • acfd6a6 Merge origin/main into fix/request-nesting-depth. It merges main at b0d1c64: test(storage-mongodb): end the killed holder's lease by data, not by waiting #1280, feat(wasm): [Add WebAssembly browser support for ExtendDB #1009 and UpdateExpression ADD creates no missing map on its path #596. It has one conflict, in the checks before authentication in crates/server/src/handler.rs. There feat(wasm): [Add WebAssembly browser support for ExtendDB #1009 replaced the name check and the parse with parse_request, and the point-in-time refusal with admit. The resolution keeps this branch's sequence with the handler's own calls, and 1a9efd7 routes that sequence through the engine's steps. crates/server/Cargo.toml auto-merged. Main changes no other file of this branch. The merged tree builds with cargo check -p extenddb-server -p extenddb-app --all-targets. feat(wasm): [Add WebAssembly browser support for ExtendDB #1009's malformed_body_error builds the message of serialization_error in request_parse.rs. This branch keeps its own function, because the syntax walk's faults are text and malformed_body_error takes a serde_json error. fix(server): send no message for a body with a JSON syntax fault #1261 removes the function with its callers.
  • Runs at 1a9efd7. cargo fmt --all -- --check is clean, and so are the two cargo clippy --all-targets commands of clippy.yml with -D warnings. cargo +1.91.1 check -p extenddb-engine -p extenddb-server --all-targets is clean. The 5 pre_dispatch unit tests pass. cargo test -p extenddb-server --lib passes 526 tests, with the same 5 backup_store failures on this host. cargo test -p extenddb-wasm-adapter --test parity passes. The clippy step of wasm.yml is clean, run locally with a stand-in C compiler because clippy does not link. On SQLite, 322 wire tests pass. They are test_request_nesting_depth (73), test_auth_error_fidelity (24), test_auth_integration (82), test_auth_permissions (66), test_continuous_backups (9), test_authz_cross_account (19) and test_authz_resource_arn (49). test_auth_permissions passes on a server with the settings that CI applies. Its key import tests need allow_credential_import, which a new server leaves off. pytest --collect-only collects tests/ (6733) and tests/python (672) with no error.
  • b9baaf5 Merge origin/main into fix/request-nesting-depth. It merges main at 018715e: fix(sqlite): render the stream retention cutoff in the created_at column shape #503, fix(engine): compare the Return fields on a TransactWriteItems token replay #526, fix: match data relations by catalog id in catalog-check, so --fix keeps live tables #690, fix(scan): drop the FilterExpression suffix from the values message #765 and fix(server): send Message on the two errors the service sends it on #774. None of the five changes a file of this branch, and the merge has no conflict. The branch's change over main is byte for byte its change before the merge. fix(server): send Message on the two errors the service sends it on #774 changes crates/server/src/response.rs, which renders this branch's refusals. A SerializationException keeps the message key, and a refusal with an empty message still has no message key. At b9baaf5, cargo fmt --all -- --check, cargo clippy -p extenddb-server --all-targets with -D warnings and cargo +1.91.1 check -p extenddb-server --all-targets are clean. cargo test -p extenddb-server --lib passes 526 tests, with the same 5 backup_store failures on this host. tests/test_request_nesting_depth.py passes its 73 cases on SQLite. pytest --collect-only collects tests/ (6710) and tests/python (672) with no error.
  • ce77837 and 4c2995c Merge origin/main into fix/request-nesting-depth. The first merges main at 44cd436 (35 commits), the second main at 6aef346 (fix(storage): plan an LSI query as an index walk on PostgreSQL and SQLite #432 and feat(streams): AT_TIMESTAMP shard iterator on all four backends #468). Neither has a conflict. Main changes five files this branch also changes, each in a different region: crates/server/Cargo.toml, handler.rs, lib.rs, serve.rs and docs/manuals/10-security-model.md. In handler.rs, fix(server): refuse point-in-time recovery before authorization #950 refuses point-in-time recovery after authentication, below the parse this branch moves. The branch's change over main is byte for byte its change over the old merge base. At 4c2995c, cargo fmt --all -- --check, cargo clippy -p extenddb-server --all-targets with -D warnings and cargo +1.91.1 check -p extenddb-server --all-targets are clean. cargo test -p extenddb-server --lib passes 525 tests there, with the same 5 backup_store failures on this host. tests/test_request_nesting_depth.py passes its 73 cases on SQLite at 4c2995c. pytest --collect-only collects tests/ (6676) and tests/python (672) with no error.
  • c73c1b0 fix(server): skip a deep body with the service's grammar before authentication. check_request_syntax no longer skips the body with serde_json. A scan of its own, skip_value, reads the first JSON value with the service's three looser lexemes. The eight forms the service authenticates first now pass the check, and the seven forms it refuses are still refused. The unit tests and the wire file carry the measured rows.
  • bb44727 test(server): pin the message boundary of the syntax check's refusal. Unclosed rows of 5200 and 5201 openers hold the boundary between a refusal with a message and one without.
  • 3dad856 docs(server): list the forms the syntax check passes to authentication. The security manual lists the forms that reach authentication.
  • 51cc638 refactor(server): move the syntax scan into its own module. The scan moves from request_parse.rs, which had reached 642 lines, to crates/server/src/request_syntax.rs. No line of the scan changed.

What

The request handler parses JSON bodies nested past serde_json's recursion limit, up to 5200 structural levels (about 2598 document wrappers). A deep body now reaches the nesting depth check.

  • crates/server/src/request_parse.rs is new. A byte scan (nesting_depth) measures the body's nesting without recursion. The parse runs with the deserializer's recursion limit disabled, bounded by that scan. Past the ceiling the server answers SerializationException with no message field. The service gives an attribute that deep the same refusal on some sends, and on every send from 5000 wrappers. A body whose unknown top-level member nests past the ceiling gets the same refusal here, where the service ignores the member and answers 200.
  • The parse of a body deeper than 127 levels waits until authentication succeeds. The handler parses a body within 127 levels, the depth serde_json's default limit accepts, before authentication as before. An unsigned deep body with valid syntax therefore gets MissingAuthenticationToken, and no unauthenticated request makes a worker thread recurse past the old depth.
  • extenddb-server exports REQUEST_WORKER_STACK_SIZE (32 MiB). cmd_serve sizes its runtime's worker threads with it, and the docs of serve and start_server state that any other host must do the same. The handling thread parses an authenticated body at the ceiling, converts it to typed attribute values and drops both. Each step recurses to the body's depth.
  • Before authentication, check_request_syntax checks the syntax of a body deeper than 127 levels. It calls skip_value (crates/server/src/request_syntax.rs), a scan that reads the first JSON value and keeps the closers of the open containers in a Vec, so it does not recurse. The scan is new because neither existing scanner fits: nesting_depth tracks only strings and escapes, and serde_json's skip applies its own grammar and cannot be configured. The grammar is JSON's except in three lexemes, where the service's check before authentication is looser. A number is - or a digit and then any run of 0-9, +, -, ., e and E. The four bytes after \u may be any byte from 0 to g (0x30 to 0x67). NUL, VT and FF count as whitespace between tokens. So the numbers 01, 1., 1e and -, the escape \u12G4, and NUL, VT or FF before a value pass the check and reach authentication, as on the service. Bytes after the first value, an invalid UTF-8 byte and a lone surrogate escape pass it too. The check refuses what the service refuses before authentication. Between tokens or in a literal, those are SOH before a value, tru, a missing colon and a missing comma. In a string, they are a \u before the closing quote, a raw control byte and the escape \q. The check also refuses a number that starts with + or ., and a byte after \u outside 0 to g, such as / or h. A body that fails it gets SerializationException whatever the signature.
  • A malformed body within the ceiling still gets SerializationException with a message field, as on main, where the service sends none (ExtendDB adds a message to the SerializationException for a body with a JSON syntax fault, where the service sends none #1195).
  • The handler still parses a body within 127 levels in full before authentication, as on main. It therefore refuses an invalid UTF-8 byte or a lone surrogate escape in that body before authentication, where the service authenticates first (ExtendDB refuses a string with an invalid UTF-8 byte or a lone surrogate escape before authentication, where the service authenticates first #1196). For the same reason it refuses the eight forms above in a body within 127 levels (ExtendDB refuses a body of 127 levels or less with \u12G4, NUL, VT or FF before authentication where the service authenticates first #1433).
  • The handler calls extenddb_engine::check_operation before its body checks and KnownOperation::with_body(..).admit() after authentication. Both are in crates/engine/src/pre_dispatch.rs. The WebAssembly adapter makes the same two checks: the name check through parse_request, and admit on the ParsedRequest that parse_request returns. It parses a body with serde_json's defaults, so it does not give this branch's answers to a deep body (The WebAssembly build and the server parse a request body differently #1471).

Why

Amazon DynamoDB parses a PutItem nested far past 128 levels and checks its nesting. The figures below are from us-east-1 on 2026-11-12 and 2026-11-13, 24 or more sends per depth. Up to 1500 document wrappers, every 400 answer was the "Nesting Levels have exceeded supported limits" ValidationException. From 1700 wrappers the answer varied per request between that and a message-less SerializationException. From 5000 wrappers it was the SerializationException on every send. On main, ExtendDB refused every body nested past 128 levels with a SerializationException before the nesting check ran.

The service also checks authentication before it refuses an over deep body. An unsigned PutItem of 1, 63, 2000, 20000 or 100000 wrappers was MissingAuthenticationTokenException on 14 of 14 sends. A badly signed one was InvalidSignatureException on 8 of 8. The service refuses a deep body with a syntax fault before authentication. Unsigned and badly signed, x followed by 6000 [ was SerializationException on 2 of 2 sends (2026-11-20). So were PutItem bodies of 63, 200, 2000 and 20000 wrappers without their last byte.

The service's check before authentication is looser than serde_json's grammar in three lexemes. A PutItem whose attribute ends in 01, 1., 1e or -, in the string escape \u12G4, or in NUL, VT or FF before a value reaches authentication. At 63 and at 20000 wrappers it is MissingAuthenticationTokenException unsigned and InvalidSignatureException badly signed, 2 of 2 sends each (us-east-1, 2026-11-24). For the four bytes after \u, \u::::, \u@@@@, \uffff, \ugggg, four backslashes and four backticks reach authentication. \u/123, \u12.4, \u12"x, \uhhhh, \uzzzz, \u~~~~, four SOH bytes and four bytes above 0x7F are SerializationException (unsigned, 200 wrappers, 2 of 2 sends each). The seven refused forms above are SerializationException with no message, unsigned and badly signed (2026-11-24, and 2026-11-20 for the control byte and the escape \q). At 63 and at 20000 wrappers, 1+, 1e+5, 1.eE-+ and \ugggg reach authentication, and +1, .5, \u000/ and \u000h are SerializationException with no message. Each held unsigned and badly signed on 2 of 2 sends (2026-11-25).

As first pushed, this branch parsed every body before authentication with the recursion limit disabled. Measured 2026-11-13, debug build: with Tokio's default 2 MiB thread stacks, an unsigned 8.5 KB body of 700 wrappers aborted the process. The same build with this revision answers unsigned bodies of up to 1,000,000 wrappers (12 MB) with a 400 while the process stays up.

Related: #564, whose item 5 records the serialization error for a value nested 100 levels deep.

Testing done

  • Unsigned deep bodies, ExtendDB on SQLite at 1f49125, debug build, with 2 MiB and with 32 MiB stacks (2026-11-20). Bodies of 1, 63, 2000, 20000, 100000 and 1,000,000 wrappers are 400 MissingAuthenticationToken, in 10 to 469 ms per round trip. A 16 MiB body of [ is 400 SerializationException with no message field, in about 1.1 s. A shallow 16 MiB array, which this branch and main parse in full before authentication, takes about 1.4 s. The process stays alive, with /health 200 after each send. 16 MiB plus one byte is 413. A bad signature at 2000 and 20000 wrappers is InvalidSignatureException. The 2 MiB build of the earlier revision aborted at 700 wrappers.
  • Authenticated bodies, 32 MiB stacks: 63, 300, 1000, 1500, 2000 and 2598 wrappers are the nesting ValidationException with the service's message byte for byte. 2599, 5000 and 20000 wrappers are the message-less SerializationException. Bodies of exactly 5199, 5200 and 5201 levels bracket the ceiling. 3000 shallow sibling maps and a 20000 wrapper attribute behind an escaped quote behave as the service does. On 2 MiB stacks an authenticated 1000 wrapper body still aborts, which is why the docs state the stack requirement.
  • Live service, us-east-1: 522 signed and unsigned sends on 2026-11-13 and two runs on 2026-11-12, as the figures above. 134 unsigned and badly signed sends on 2026-11-24 for the three lexemes, each body twice, on a table name that does not exist. 64 more on 2026-11-25 for the eight edge rows, the same way.
  • tests/test_request_nesting_depth.py (dual-target) passes on SQLite at 71b3e1b with 105 cases. Its 27 cases at 1f49125 passed against the service on two runs (us-east-1, 2026-11-20). c73c1b0 adds 46 cases: the eight passing forms at 63 and 20000 wrappers and the seven refused forms at 200, unsigned and badly signed. Each of those rows has a service measurement from 2026-11-24. 71b3e1b adds 32: the eight edge rows at 63 and 20000 wrappers, unsigned and badly signed, measured on 2026-11-25. Its raw sender retries a 500 InternalFailure, as the client library does. The service gives a deep body that answer a few times per hundred sends (1500 wrappers: 2 of 56).
  • The same bodies sent to SQLite servers at 3dad856 and at 51cc638 on 2026-11-24 get the service's answer on every row. The rows are the eight forms at 63 and 20000 wrappers, the 22 \u forms at 200, and the seven refused forms at 200 and 20000.
  • Controls on the two syntax check unit tests at 51cc638. With serde_json's skip back in check_request_syntax, the 16 new passing rows fail and nothing else does. With no check, all 16 refusal rows fail. With the message boundary moved to >=, the 5200 opener row fails alone.
  • Wire tests on SQLite at 1f49125: test_auth_error_fidelity, test_auth_integration, test_attribute_value_validation, test_expression_attribute_map_validation, test_item_operations and test_batch_write_validation_order, 423 passed.
  • cargo test -p extenddb-server --lib and cargo test -p extenddb-app --lib at 3dad856, and the 12 request_parse tests again at 51cc638: 600 passed, the 12 request_parse unit tests among them. 5 backup_store tests that need an owner-only path fail on this host on main as well.
  • cargo fmt --all -- --check, cargo clippy -p extenddb-server --all-targets with -D warnings, and cargo +1.91.1 check -p extenddb-server --all-targets are clean at 51cc638. pytest --collect-only collects tests/ and tests/python with no error.

Checklist

  • I have read CONTRIBUTING.md
  • All tests pass (cargo test --workspace)
  • Code is formatted (cargo fmt --check)
  • Clippy is clean (cargo clippy -- -W clippy::pedantic)
  • I have added or updated tests for new functionality
  • I have updated documentation if behavior changed
  • Breaking changes are noted below (if any)
  • If this changes the wire protocol, Storage trait, auth model, on-disk
    format, or public CLI surface, an RFC has been accepted or is linked
    below. Otherwise, an ADR captures the decision (link below).

ADR / RFC: n/a. The change makes request parsing accept the bodies the service accepts. No document describes the old limit.

Breaking changes

A client sees these answers change:

  • A body nested 128 to 5200 structural levels is parsed. It gets the answer of the checks that follow, for example the nesting ValidationException for an item attribute. Before, it got a SerializationException with the message "Start of structure or map found where not expected: recursion limit exceeded" and a position.
  • A body nested past 5200 levels gets a SerializationException with no message field. Before, it got the recursion limit message.
  • An unsigned or badly signed request whose body nests deeper than 127 levels, with valid syntax, gets the authentication error. Before, it got the SerializationException.

A program that runs the server on its own Tokio runtime must give its worker threads REQUEST_WORKER_STACK_SIZE (32 MiB) of stack. The docs of serve and start_server say so. A body near the ceiling overflows an 8 MiB stack (measured 2026-11-02, debug build).


By submitting this pull request, I confirm that my contribution is made under
the terms of the Apache License 2.0 and I agree to the Developer Certificate of
Origin (DCO). See CONTRIBUTING.md for details.

…idates

The request handler read the JSON body with serde_json's default
deserializer, which refuses a document nested past 128 levels with a
SerializationException. A request whose attribute nested deeper was
refused before the nesting depth check ran, so a body that the service
answers with the document nesting ValidationException got a serialization
error here instead.

Amazon DynamoDB parses and validates a body nested to at least about 2000
document wrappers (roughly 4000 JSON levels) and answers it with "Nesting
Levels have exceeded supported limits". It refuses only a deeper body, and
then with a SerializationException that has no message field (measured
2026-11-02, us-east-1).

request_parse.rs disables the deserializer's recursion limit for the
request body. A byte scan first bounds the structural nesting at 5200
levels (about 2600 wrappers), so a deeper body is refused before any
recursive work. Every body the service validates is parsed and reaches the
nesting check. Past the ceiling the server answers a SerializationException
with an empty message, so error_response omits the message field, as the
service does. A shallow or malformed body gets the same
SerializationException as before.

A body at the ceiling recurses to its depth three times: the parse, the
conversion to typed AttributeValues, and the drop of both. In a debug build
that takes about 13 MiB of stack, so cmd_serve sizes each serve worker
thread at 32 MiB, over twice the measured peak.

The request_parse unit tests and the dual-target
tests/test_request_nesting_depth.py cover an attribute within the limit, a
63-level attribute, bodies of 120, 300, 1000 and 2000 wrappers that get
the nesting ValidationException, and one far past the ceiling that gets
the message-less SerializationException. The deep bodies are built as raw
JSON and signed, so no client library recurses to produce them.

@demohan demohan left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parse change does what it sets out to do for signed PutItem, BatchWriteItem and TransactWriteItems bodies between 128 and 5200 levels, on all four backends, with no regression against main in the shapes measured. Six items before merge: two scan tests, the 2000 wrapper live case, the stack precondition, two comments that claim more than the service does, and a rebase onto main for a conflict in cmd_serve.rs.

Comment thread crates/server/src/request_parse.rs Resolved
Comment thread crates/server/src/request_parse.rs Resolved
Comment thread tests/test_request_nesting_depth.py Resolved
Comment thread crates/server/src/request_parse.rs Resolved
Comment thread crates/server/src/request_parse.rs Resolved
Comment thread crates/app/src/cmd_serve.rs Resolved
Comment thread tests/test_request_nesting_depth.py Resolved
Comment thread crates/server/src/request_parse.rs Resolved
Comment thread crates/server/src/request_parse.rs Resolved
The handler parsed every request body before authentication, with the
deserializer's recursion limit disabled and the byte scan's 5200 level
ceiling as the only bound. On a runtime whose threads have Tokio's
default 2 MiB stack, the parse of an unsigned body within that ceiling
overflows the stack and aborts the process (measured 2026-11-12, debug
build: 700 single-key wrappers on 2 MiB), so anyone who can reach the
listener can take the server down without credentials. extenddb's own
serve sizes its workers at 32 MiB, but extenddb_server::serve and
start_server are public and run on whatever runtime the caller built.

Amazon DynamoDB checks the request's JSON syntax before authentication
and refuses an over deep body only after it. Measured 2026-11-12 in
us-east-1: an unsigned PutItem of 63, 2000 or 20000 wrappers is a 400
MissingAuthenticationTokenException on every send, a badly signed one is
an InvalidSignatureException, and only the signed 20000 wrapper body is
the message-less SerializationException. Unsigned malformed JSON is a
SerializationException at any depth.

The handler now scans the depth first and parses a body within
serde_json's default 128 levels before authentication, as it always did
on a default stack. A deeper body is parsed only once the caller is
authenticated, so no unauthenticated request makes the handling thread
recurse past that depth, and an unsigned deep body gets the
MissingAuthenticationToken answer the service gives. The stack a thread
needs for an authenticated body at the ceiling is now the exported
REQUEST_WORKER_STACK_SIZE, used by cmd_serve and the unit test, and the
requirement is documented on serve and start_server. The one shape that
still differs is an unsigned body that is both malformed and deeper than
128 levels: the service answers SerializationException, the server
MissingAuthenticationToken, because checking its syntax would mean
recursing before authentication.

The ceiling comment no longer claims every body the service validates
is parsed. Measured 2026-11-12, 24 sends per depth across four windows:
up to 1700 wrappers the service answered the nesting ValidationException
on every send, from 1800 wrappers the answer varied per request between
that and the message-less SerializationException (4000 wrappers also
drew 500 InternalFailure 7 times), 5000 and 20000 wrappers were refused
on every send, and an unknown top-level member nested 5201, 6001 or
20000 levels was ignored (200) by PutItem, DescribeTable and ListTables.
The 5200 level ceiling (2598 wrappers) sits inside the band where the
service itself varies.

The scan tests now pin the behaviour the ceiling relies on: an over
ceiling attribute behind an escaped quote is counted and refused, 3000
shallow sibling maps (more openers than the ceiling, depth 5) parse, as
the service stores them, bodies of exactly 5200 and 5201 levels bracket
the ceiling, and a malformed body carries the server's usual message.

Signed-off-by: Lee Hannigan <29015211+LeeroyHannigan@users.noreply.github.com>
The dual-target test pinned a 2000 wrapper PutItem to the nesting
ValidationException. The service has no fixed ceiling there: measured
2026-11-12 in us-east-1 with 24 sends per depth across four windows,
300 to 1700 wrappers got the ValidationException on every send, 1800 to
2598 wrappers got it on 22 or 23 of 24 sends and the message-less
SerializationException on the rest, 3000 wrappers split 19 to 5, and
5000 and 20000 wrappers were refused on every send.

The always-validated cases are now 300, 1000 and 1500 wrappers, the 2000
and 2598 wrapper cases accept either of the two answers, and the far
past the ceiling case stays at 20000. The recursion limit botocore needs
to serialize the two boto3 built items is set by a fixture for those two
cases and restored afterwards instead of for the whole session.

Signed-off-by: Lee Hannigan <29015211+LeeroyHannigan@users.noreply.github.com>
The raw PutItem sender sent once and the two raw tests asserted a 400.
The service answers a deep body with 500 InternalFailure now and then.
Measured 2026-11-13 in us-east-1: 1500 wrappers 2 of 56 sends, 2000
wrappers 1 of 37, 2598 wrappers 2 of 48. The client library retries a
500 by default, so only the raw cases could fail on one. The sender now
sends up to three times while the answer is a 500, with a pause of one
and then two seconds. The assertions are unchanged.

The depth the service validates on every send is 1500 wrappers, not
1700. Across 2026-11-12 and 2026-11-13, 1700 wrappers drew the
message-less SerializationException on 3 of 74 sends. 1500 wrappers
drew it on 0 of 104. The module docs and the test comments now give
1500, and the raw cases at 300, 1000 and 1500 wrappers are unchanged.

UNAUTHENTICATED_PARSE_DEPTH is 127. serde_json's default recursion
limit of 128 parses 127 nested levels and refuses the 128th. At 128 the
constant admitted one level more than the server parsed before the
limit was lifted. The unit test now parses with serde_json's default
limit at the constant and one level past it, instead of restating the
number.

The malformed-body unit test no longer pins the refusal of trailing
bytes, which the service accepts. A signed PutItem with bytes after the
closing brace was a 200 on 4 of 4 sends (measured 2026-11-13). The row
is a truncated body instead. Typo fix in the cmd_serve stack comment:
"the stack that needs" is now "the stack it needs".

Signed-off-by: Lee Hannigan <29015211+LeeroyHannigan@users.noreply.github.com>

@demohan demohan left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rewrite fixes eight of the ten items: the escape and closer scan tests, the live cases at 300 to 2598 wrappers, the ceiling comment, the stack constant and its docs, the merge with main, the recursion limit fixture, and the malformed message assertion. Measured on 2026-11-16 in us-east-1, the dual-target file passed 9 of 9 twice against the service and twice on each of SQLite, PostgreSQL, MongoDB and Cassandra.

Moving the deep parse after authentication changes the answer for malformed bodies. An unsigned PutItem of x followed by 6000 [ gets a SerializationException with no message from the service on 2 of 2 sends. The previous head gave the same bytes. This head answers MissingAuthenticationToken, and InvalidSignatureException with a bad signature. A truncated PutItem at 200 or 2000 wrappers, unsigned, behaves the same way. The service checks syntax before authentication at every depth, so the handler needs a syntax check before authentication that does not recurse. The depth scan already walks the body in one loop, and the same loop can hold a stack of container kinds.

Two items from the earlier review remain: the comment at request_parse.rs:44 and the 5200 level bracket.

Err(e) => return error_response(&e, &request_id),
}
} else {
None

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A malformed body deeper than 127 levels skips the syntax check before authentication. Measured 2026-11-16, an unsigned PutItem of x followed by 6000 [ is 400 {"__type":"com.amazon.coral.service#SerializationException"} on the service on 2 of 2 sends, and on the previous head too. Here it is MissingAuthenticationToken, and InvalidSignatureException with a bad signature. Unsigned truncated PutItem bodies at 63, 200 and 2000 wrappers get the SerializationException from the service and the authentication error here. A syntax check that walks the body in one loop like nesting_depth, with a stack of container kinds, would refuse these before authentication without recursing.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In 99542cb, the handler runs check_request_syntax before authentication on a body deeper than 127 levels. The check deserializes the body as serde::de::IgnoredAny, which serde_json skips in one loop with a Vec of open container kinds, so it doesn't recurse.

Unsigned and badly signed, x plus 6000 [ and truncated PutItem bodies at 63, 200, 2000 and 20000 wrappers are now a 400 SerializationException. That's the service's status and type on 2 of 2 sends each (us-east-1, 2026-11-20). Past the 5200 level ceiling the whole response body matches. Within it, our response keeps the message field a shallow malformed body has always had, where the service sends none (#1195).

Comment thread crates/server/src/request_parse.rs Outdated
/// An unknown top-level member is ignored at any depth (20000 levels is a 200).
/// The ceiling, 5200 structural levels or about 2598 wrappers, sits inside the
/// band where the service itself varies: every depth the service answers
/// consistently is parsed here, and a deeper body gets the message-less

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A body whose unknown top-level member nests 5201, 6001 or 20000 levels gets 200 from the service on PutItem, DescribeTable and ListTables (42 of 42 sends, 2026-11-16). Here it gets the messageless SerializationException on all four backends. "Every depth the service answers consistently is parsed here" holds for an attribute but not for this shape. The PR body sentence "as the service does" has the same gap. Suggested text: "An attribute shallow enough for the service to validate it on every send is parsed here, and a deeper body gets the message-less refusal the service gives for an attribute in that band. A body with an unknown top-level member nested past the ceiling is refused here, where the service ignores the member."

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Taken in b8fee45 with your wording, except that "a deeper body" is now "a body nested past the ceiling". That's because the server parses an attribute all the way to the ceiling, past the 1500 wrappers the service validates on every send.

The comment now also says that the service ignores an unknown top-level member. A member nested 5201, 6001 or 20000 levels gets a 200 on PutItem, DescribeTable and ListTables (20 of 20 sends, us-east-1, 2026-11-19). I've changed the PR body sentence to match.

Comment thread crates/server/src/request_parse.rs Outdated
let rows: [(Vec<u8>, usize); 5] = [
(deep_body(100), 203),
(deep_body(2000), 4003),
(b"[".repeat(MAX_REQUEST_JSON_DEPTH), MAX_REQUEST_JSON_DEPTH),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These rows are built from MAX_REQUEST_JSON_DEPTH, so they move with it. With the constant set to 5199, the 10 unit tests and the 9 wire tests pass, and with 5201 they pass as well. Literal 5200 and 5201 in two rows would pin the boundary.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 5d71902. The rows now use the literal depths 5200 and 5201, and the test fails with the constant at 5199 and at 5201.

The handler parses a body nested deeper than 127 levels only after
authentication, so a malformed body that deep got the authentication
error. The service checks the syntax of every body before
authentication. Unsigned or badly signed, the byte `x` followed by 6000
`[` is a 400 SerializationException with no message field on every send.
A PutItem body of 63, 200, 2000, 5000 or 20000 wrappers without its last
byte gets the same answer. The complete bodies are
MissingAuthenticationTokenException unsigned and InvalidSignatureException
badly signed (us-east-1, 2026-11-19 and 2026-11-20, 2 sends per shape and
signing).

`check_request_syntax` runs before authentication for a body deeper than
127 levels. It deserializes the body as `serde::de::IgnoredAny`.
serde_json skips such a value in one loop. The loop keeps the kinds of
the open containers in a Vec, so the check does not recurse at any depth.
The check reads one JSON value, as the service's check does. Bytes after
a complete body pass it, and so do an invalid UTF-8 byte and a lone
surrogate escape in a string. A body that fails the check gets the
SerializationException that the parse after authentication gives. Past
the 5200 level ceiling it has no message, and within the ceiling it has
the server's usual wording.

Two unit tests cover the check on a worker-sized stack and on the
default test stack, with a body of 1,000,000 levels. The wire file gains
two dual-target cases. A malformed deep body is a SerializationException
unsigned and badly signed. A complete deep body, with or without
trailing bytes, reaches authentication. The security model manual states
the order.
The comment on the request depth ceiling said that the server parses
every depth the service answers consistently. That holds for an
attribute. The service ignores an unknown top-level member nested 5201,
6001 or 20000 levels. It answers 200 on PutItem, DescribeTable and
ListTables (us-east-1, 2026-11-19, 20 of 20 sends). The server refuses
such a body past its 5200 level ceiling. The comment now states both
answers.
The rows of `the_depth_scan_brackets_the_ceiling_exactly` took their
depths from `MAX_REQUEST_JSON_DEPTH`, so they moved with the constant and
no row failed when it changed. The rows now hold the literal depths 5200
and 5201 and say whether each one is within the ceiling. With the
constant at 5199 or at 5201, the test fails.
The security manual said that a malformed body returns
SerializationException whatever the signature. For a body nested deeper
than 127 levels, the check before authentication reads only the first
JSON value. It does not check UTF-8 or surrogate escapes in strings.
Bytes after that value, an invalid UTF-8 byte and a lone surrogate
escape reach authentication, as on the service. Unsigned, the service
answers each with MissingAuthenticationTokenException (us-east-1,
2026-11-19). The manual now says so.

The comment on the syntax check test said that the check gives the
same refusal as the parse after authentication. The message is the
same for the structural faults in its rows. For a raw control character
in a string, the check reports one column earlier. The comment now says
both.

The unit test drops two asserts that its row loop and two other tests
already cover. It also builds its wrong closer row inline in place of a
helper with one caller. The wire test builds each malformed body from a
wrappers parameter and no longer parses shape names.
@LeeroyHannigan

Copy link
Copy Markdown
Collaborator Author

Thanks demohan, all three items are in.

  1. Malformed deep bodies before authentication: 99542cb. A body deeper than 127 levels gets a syntax check before authentication that doesn't recurse. Unsigned and badly signed, x plus 6000 [ and the truncated PutItem bodies are now a SerializationException here, as on the service.
  2. The comment at request_parse.rs:44: b8fee45, with your wording except "a body nested past the ceiling" for "a deeper body". The PR body sentence matches it now.
  3. The 5200 level bracket: 5d71902. Two rows hold the literal depths 5200 and 5201.

In 1f49125, the security manual now says which faults in a body nested past 127 levels still reach authentication, as on the service. They are bytes after the first JSON value, an invalid UTF-8 byte and a lone surrogate escape.

At that commit the wire file passes 27 of 27 against the service on two runs (us-east-1, 2026-11-20) and on SQLite. CI runs it on PostgreSQL, MongoDB and Cassandra. The PR body now describes the check, with its measurements, and the two differences that remain (#1195 and #1196).

@demohan demohan left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The items from the earlier reviews are resolved at 1f49125. The new check introduces one divergence (inline). Each request was sent twice to the service and to a SQLite release build of this head.

  • x followed by 6000 [, and PutItem bodies cut short by one byte at 63, 200, 2000 and 20000 wrappers, answer 400 SerializationException unsigned, badly signed and signed, as the service does. Past the 5200-level ceiling the response body equals the service's.
  • An unknown top-level member nested 5201, 6001 and 20000 levels answers SerializationException with no message, as the comment at request_parse.rs:46 now says. The rows hold the literal depths 5200 and 5201.
  • The syntax check does not recurse. A body of 16,777,200 open [ is refused in 0.10 s, and a 1,000,000-wrapper valid PutItem reaches authentication in under 0.04 s. With the check parsing into a full Value and no depth limit, the unit test overflows its stack. 32 concurrent 16 MiB deep bodies add about 22 MB each over e2e58e3.
  • The test file passes 27 of 27 against the service and this head, and 10 cases fail with the new branch removed. CI is green on 58 of 58 checks.

I will approve once the check below accepts what the service authenticates first, and the security manual lists it.

/// body that fails it gets a `SerializationException`, with no message past
/// the ceiling, as from [`parse_request_value`], and with the server's usual
/// wording within it.
pub(crate) fn check_request_syntax(body: &[u8], depth: usize) -> Result<(), DynamoDbError> {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check_request_syntax applies serde_json's grammar, and the service authenticates these deep bodies first. Each was sent unsigned, at 63 to 20000 wrappers:

  • a number 01: the service answers MissingAuthenticationTokenException, and this head answers SerializationException
  • a number 1.: the same
  • a string escape \u12G4: the same
  • a form feed or a NUL byte as whitespace: the service answers MissingAuthenticationTokenException unsigned and InvalidSignatureException badly signed, and this head answers SerializationException

e2e58e3 answered all of these as the service does.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in c73c1b0, and 51cc638 moves the scan to crates/server/src/request_syntax.rs. The check no longer skips the body with serde_json. skip_value reads the first JSON value with serde_json's grammar in every lexeme but three, where the service's check before authentication is looser. A number is - or a digit and then any run of 0-9, +, -, ., e and E. The four bytes after \u may be any byte from 0 to g (0x30 to 0x67). NUL, VT and FF count as whitespace between tokens.

Your five forms and three more, 1e, a lone - and VT. I sent each twice unsigned and twice badly signed, at 63 and at 20000 wrappers. Each was a PutItem on a table name that does not exist (us-east-1, 2026-11-24):

leaf 63 wrappers, UTC of the first sends 20000 wrappers service unsigned service badly signed
01 11:00:11.348Z, 11:00:11.903Z 11:00:20.229Z, 11:00:20.805Z MissingAuthenticationTokenException InvalidSignatureException
1. 11:00:12.467Z, 11:00:13.015Z 11:00:21.393Z, 11:00:21.968Z MissingAuthenticationTokenException InvalidSignatureException
1e 11:00:13.570Z, 11:00:14.127Z 11:00:22.553Z, 11:00:23.139Z MissingAuthenticationTokenException InvalidSignatureException
- 11:00:14.700Z, 11:00:15.250Z 11:00:23.723Z, 11:00:24.299Z MissingAuthenticationTokenException InvalidSignatureException
\u12G4 11:00:15.808Z, 11:00:16.359Z 11:00:24.889Z, 11:00:25.464Z MissingAuthenticationTokenException InvalidSignatureException
FF before the value 11:00:16.912Z, 11:00:17.462Z 11:00:26.055Z, 11:00:26.630Z MissingAuthenticationTokenException InvalidSignatureException
NUL before the value 11:00:18.018Z, 11:00:18.567Z 11:00:27.220Z, 11:00:27.795Z MissingAuthenticationTokenException InvalidSignatureException
VT before the value 11:00:19.128Z, 11:00:19.677Z 11:00:28.384Z, 11:00:28.971Z MissingAuthenticationTokenException InvalidSignatureException

A SQLite build of 51cc638 gives the same answer on each row (ExtendDB's type for the first is MissingAuthenticationToken, #1075).

I measured the four bytes after \u unsigned at 200 wrappers, 2 of 2 sends each, from 10:55:40Z to 10:59:38Z. \u::::, \u@@@@, \uffff, \ugggg, four backslashes and four backticks reach authentication. \u/123, \u12.4, \u12"x, \uhhhh, \uzzzz, \u~~~~, four SOH bytes and four bytes above 0x7F are SerializationException with no message. The check follows that range.

The service still refuses these deep bodies before authentication, and so does the check. Between tokens or in a literal: SOH before a value, tru, a missing colon and a missing comma. In a string: a \u before the closing quote, a raw control byte and the escape \q. Each is SerializationException with no message, unsigned (09:52:06Z to 09:52:09Z) and badly signed (11:00:40Z to 11:00:43Z), and 2026-11-20 for the two string faults.

The unit tests carry the eight forms at 63 and 20000 wrappers and the seven refused forms at 200. The wire file has 73 cases, 27 before. With serde_json's skip back in the check, the 16 new passing rows fail and nothing else does. With no check, all 16 refusal rows fail.

The scan is new code because nesting_depth tracks only strings and escapes, and serde_json's skip cannot be configured. Its number rule is number_byte, one function, so the later number fixes on this branch can call it.

Comment thread docs/manuals/10-security-model.md Outdated
9. Apply the deferred decisions from steps 3 and 6, after the signature check so that failure paths take the same time: an inactive key or a wrong or missing token is `UnrecognizedClientException`

Request bodies are parsed before authentication (the service does the same), so a malformed body returns `SerializationException` whatever the signature. Headers not named in `SignedHeaders` do not take part in verification; the service behaves the same way, and clients sign every `x-amz-*` header they send.
A request body's JSON syntax is checked before authentication at every nesting depth (the service does the same). A malformed body therefore returns `SerializationException` whatever the signature. In a body nested deeper than 127 levels, the syntax check reads only the first JSON value. It does not check UTF-8 or surrogate escapes in strings, as on the service. So bytes after that value, an invalid UTF-8 byte or a lone surrogate escape reach authentication, and only the parse after authentication refuses them. A body nested deeper than 127 levels is parsed only after authentication, so an unauthenticated request never makes a worker thread recurse past that depth. Headers not named in `SignedHeaders` do not take part in verification; the service behaves the same way, and clients sign every `x-amz-*` header they send.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The sentence names bytes after the first value, an invalid UTF-8 byte and a lone surrogate escape as the faults that reach authentication. Those three hold: unsigned, the service answers MissingAuthenticationTokenException for each. The four shapes in the comment above also reach authentication on the service.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 3dad856. The paragraph now says that a body that fails the check returns SerializationException whatever the signature, and lists what the check passes. It follows the service in four places. It does not check UTF-8 or surrogate escapes in strings. A number is - or a digit and any run of 0-9, +, -, ., e and E. The four bytes after \u may be any byte from 0 to g. NUL, vertical tab and form feed are whitespace between tokens. So bytes after the first value, an invalid UTF-8 byte and a lone surrogate escape reach authentication. So do a number such as 01, 1., 1e or -, an escape such as \u12G4, and those three bytes between tokens. Only the parse after authentication refuses them.

…ntication

The syntax check before authentication deserialized the body as
serde::de::IgnoredAny, so it applied serde_json's grammar. The service's
check is looser in three lexemes, and it authenticates these deep bodies
first, where the check refused them. The forms are the numbers 01, 1.,
1e and -, the escape \u12G4 in a string, and NUL, VT or FF between
tokens. At 63 and at 20000 wrappers, each is a
MissingAuthenticationTokenException unsigned and an
InvalidSignatureException badly signed. That held on 2 of 2 sends per
body and signing (us-east-1, 2026-11-24).

check_request_syntax now calls skip_value, a scan of the body's first
JSON value with serde_json's grammar in every lexeme but those three.
Whitespace also takes NUL, VT and FF. SOH stays refused. A number is -
or a digit and then any run of the bytes number_byte names, 0-9 + - . e
E. The four bytes after \u are not read as hex digits. The service takes
any byte from 0 to g (0x30 to 0x67) there and refuses the others.
Unsigned at 200 wrappers, \u::::, \u@@@@, \uffff, \ugggg, four
backslashes and four backticks reach authentication. \u/123, \u12.4,
\u12"x, \uhhhh, \uzzzz, \u~~~~, four SOH bytes and four bytes above 0x7F
are a SerializationException (us-east-1, 2026-11-24). The scan keeps the
closers of the open containers in a Vec, as serde_json's skip does, so
it does not recurse at any depth. nesting_depth tracks only strings and
escapes, and serde_json's skip cannot be configured, so neither could
take the three lexemes.

The check still refuses the seven forms the service refuses before
authentication. Four sit between tokens or in a literal: SOH before a
value, tru, a missing colon and a missing comma. Three sit in a string:
a \u before the closing quote, a raw control byte and the escape \q.
Each is a SerializationException with no message, unsigned and badly
signed (us-east-1, 2026-11-24, and 2026-11-20 for the two string
faults). The depth branch stays. A body past the 5200 level ceiling
gets the message-less refusal as before.

The unit test rows gain the eight forms at 63 and at 20000 wrappers and
the seven refused forms at 200. They run on the default test stack.
The refusal test changes. It no longer compares the check's message with
the parse's, since the scan words its faults itself. It asserts the
type, a message within the ceiling and none past it. The wire file gains
the same rows, 73 cases in place of 27.
The check's refusal carries the server's wording for a body within the
5200 level ceiling and no message for a body past it. No row sat on the
boundary, so a check that dropped the message from 5200 levels on
passed every test. Two unclosed rows, 5200 and 5201 openers, now hold
the boundary: the first must carry a message and the second must not.
The security manual said that a malformed body returns
SerializationException whatever the signature. It named bytes after the
first value, an invalid UTF-8 byte and a lone surrogate escape as the
faults that reach authentication. The check before authentication now
follows the service in three more lexemes, so the sentence holds only
for a body that fails the check. The manual now says so and lists what
passes. A number such as 01, 1., 1e or - passes. So does an escape
whose four bytes after \u lie between 0 and g. So do NUL, vertical tab
and form feed between tokens (us-east-1, 2026-11-24, unsigned and badly
signed).
request_parse.rs reached 642 lines with the scan and its rows. The scan
(number_byte, Scan and skip_value) now sits in request_syntax.rs, 171
lines. request_parse.rs keeps the depth scan, the parse, the check that
calls skip_value, and the tests, 483 lines. No line of the scan changed
beyond the two pub(crate) markers the module boundary needs.
Merges main at 44cd436 (35 commits). No conflicts. Main changes five
files this branch also changes, each in a different region.
crates/server/Cargo.toml adds zeroize. handler.rs refuses point-in-time
recovery after authentication (#950), below the parse this branch moves.
lib.rs adds two modules. serve.rs loads the KEK in serve_inner.
docs/manuals/10-security-model.md changes sections outside the
pre-authentication paragraph. The merge keeps every line of this branch.
Merges main at 6aef346, two commits past 44cd436: #432 (LSI query
plan on PostgreSQL and SQLite) and #468 (AT_TIMESTAMP shard iterator).
No conflicts. Neither commit changes a file of this branch.
Merges main at 018715e, five commits past 6aef346:

- #503: the stream retention cutoff shape on SQLite
- #526: the Return fields on a TransactWriteItems token replay
- #690: catalog-check matches data relations by catalog id
- #765: the FilterExpression suffix in the values message
- #774: the Message key on two errors

No conflicts. None of the five changes a file of this branch. #774
changes crates/server/src/response.rs, which renders the errors this
branch's tests assert. The key on SerializationException stays message.
Merges main at b0d1c64, three commits past 018715e:

- #1280: the MongoDB lease test ends the killed holder's lease by data
- #1009: the WebAssembly browser build
- #596: UpdateExpression ADD creates no missing map on its path

One conflict, in the checks before authentication in
crates/server/src/handler.rs. #1009 moved the operation name check and
the body parse into extenddb_engine::parse_request, and the
point-in-time refusal into ParsedRequest::admit. This branch replaced
that parse with a depth scan and a parse before authentication. For a
deep body it runs a syntax walk instead, and parses the body after
authentication.

Kept: this branch's sequence. The handler checks the operation name and
scans the depth. Then it parses the body or walks a deep body's syntax.
Then it authenticates the caller, parses a deep body, and applies the
point-in-time refusal. The handler calls is_known_operation and
refuse_point_in_time_recovery again, so its hunk for admit goes too.
The next commit makes the handler call the engine's steps again around
its own parse.

Auto-merged: crates/server/Cargo.toml keeps main's default feature on
the engine dependency and this branch's unbounded_depth feature on
serde_json.
…he server's parse

#1009 moved the checks before dispatch into extenddb_engine::parse_request
and ParsedRequest::admit, and the server and the WebAssembly adapter both
called them. This branch parses a body with its own parser in
request_parse.rs. So the merge of main kept the server's own calls of
is_known_operation and refuse_point_in_time_recovery. A check added to
admit later would then reach only the adapter.

The engine now makes the operation name check a step of its own.
check_operation returns a KnownOperation. KnownOperation::with_body pairs
it with a body that the entry point parsed and returns the ParsedRequest.
parse_request is check_operation and the serde_json parse, as before, so
the adapter still calls parse_request(..)?.admit().

The handler calls check_operation before its depth scan. It calls
with_body(input).admit() after it authenticates the caller and parses a
deep body, in place of its own two calls. No answer changes: the two
steps make the same checks at the same points.

These docs now say that the server calls check_operation and admit and
parses the body itself:

- the module doc of pre_dispatch.rs and the doc comments that name the
  callers
- the handler comments and the adapter's module doc
- the doc of malformed_body_error
- the README's list of the server's checks, which also says that its
  table does not list the answers where the two parsers differ

The five pre_dispatch tests reach check_operation and with_body through
parse_request. Three mutants each fail one of them: one accepts every
operation, one drops the operation in with_body, and one drops the
body. So this commit adds no test.
The adapter's module doc said that Engine::dispatch runs the operation
name check and ParsedRequest::admit through extenddb_engine::parse_request.
Of the two, only the name check runs in parse_request. dispatch calls admit
on the ParsedRequest that parse_request returns. The sentence now says so.

@demohan demohan left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The items from the earlier review are resolved at 1a9efd7. The check before authentication now passes what the service passes to authentication: the 8 forms (01, 1., 1e, -, \u12G4, and NUL, VT or FF before a value) at 63 and 20000 wrappers answer MissingAuthenticationTokenException unsigned and InvalidSignatureException badly signed, as the service in us-east-1 does, two sends each in two runs, where 1f49125 answered SerializationException. Across 76 more shapes that probe each looser rule (numbers such as 1+2, --, 1.2.3 and 9-9, the \u byte range, and NUL, VT and FF in 9 positions between tokens), this head matches the service in status and error class, and the 7 forms the service refuses still answer SerializationException. The security model paragraph now names the four places the check is looser than JSON, and each matches the code and these sends.

skip_value is one loop with one byte per open level, so no thread stack grew past 88 kB on unsigned bodies up to 16 MiB of [ and 1,000,000 wrappers, and a signed body at the 2598-wrapper ceiling peaks at 4060 kB of the 32 MiB worker stack. 32 concurrent unsigned 16 MiB bodies peak at 1.27 to 1.45 GB resident against 1.14 to 1.40 GB at 1f49125. The operation check still runs before the body checks and the admit step where main runs it, the 5200 and 5201 boundary rows hold, the module move keeps every test, fmt, clippy and the 1.91.1 check are clean, and CI is green on 65 checks.

I will approve once the edges of the looser rules have rows.

/// Whether `b` can be part of a number as the service reads one. The service
/// takes a run of these bytes that starts with a digit or `-` as one number.
pub(crate) fn number_byte(b: u8) -> bool {
matches!(b, b'0'..=b'9' | b'-' | b'+' | b'.' | b'e' | b'E')

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No test pins the edges of two of the looser rules. Widening the \u range at :68 to any printable byte, dropping + here, and letting a number start with + or . each pass both syntax unit tests, and a build with all three passes the wire file 73 of 73 twice. That build differs from the service on six bodies, 4 of 4 sends each: 1+, 1e+5 and 1.eE-+ answer SerializationException where the service authenticates first, and +1, .5, \u000/ and \u000h reach authentication where the service refuses them. Passing rows for 1e+5 and \u000f or \ugggg, and refused rows for +1, .5, \u000/ and \u000h, in the unit tests and tests/test_request_nesting_depth.py, would hold the grammar.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in 71b3e1b, at 63 and at 20000 wrappers, in the syntax unit tests of request_parse.rs and in tests/test_request_nesting_depth.py:

  • Reach authentication, in LOOSE_LEAVES of both files: 1+, 1e+5, 1.eE-+ and \ugggg.
  • Refused before authentication, in the_syntax_check_refuses_a_malformed_deep_body and test_a_malformed_deep_body_is_refused_before_authentication: +1, .5, \u000/ and \u000h.

The service gave each body the answer you measured, unsigned and badly signed, 2 of 2 sends each (us-east-1, 25 Nov).

With the tests kept, each of your three changes fails a new unit row. The printable \u range and a number that starts with + or . fail the refusal test. Dropping + fails the pass test at 1+. Each change passes the unit tests of 027483d. A build with all three fails 28 of the 32 new wire cases and passes the old file 73 of 73. Its four \ugggg cases pass, because none of the three narrows the range.

No row held the edges of two of the looser rules of the check before
authentication. A check that took any printable byte after \u, dropped +
from the number bytes, or let a number start with + or . passed the unit
tests and the wire file.

New rows sit at 63 and at 20000 wrappers, in the syntax tests of
request_parse.rs and in tests/test_request_nesting_depth.py:

- The numbers 1+, 1e+5 and 1.eE-+ and the escape \ugggg reach
  authentication. The + is a number byte, and g is the highest byte the
  service takes after \u.
- The check refuses the numbers +1 and .5 and the escapes \u000/ and
  \u000h before authentication. A number starts with - or a digit, and /
  and h are the bytes on either side of 0 to g.

The service answers the first four with a
MissingAuthenticationTokenException unsigned and an
InvalidSignatureException badly signed. It answers the last four with a
SerializationException that has no message, unsigned and badly signed.
Each answer held on 2 of 2 sends per body and signing (us-east-1,
2026-11-25).

@demohan demohan left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The edge rows hold at 71b3e1b. On the service in us-east-1, 1+, 1e+5, 1.eE-+ and \ugggg reach authentication, and +1, .5, \u000/ and \u000h are refused with a SerializationException that has no message, at 63, 200 and 20000 wrappers, unsigned and badly signed, 4 of 4 sends per cell. A release build of this head answers as the service does on all 120 cells, and the wire file passes 105 of 105 twice.

Each of the three looser rules now has a row that fails without it. Passing any printable byte after \u, dropping + from the number bytes, or letting a number start with + or . fails the request_parse unit tests, and so do the range ends moved by one byte; on servers built with those changes, the new wire rows fail 8, 12 and 8 cases, and 28 of the 32 together, with none of the older 73. The commit changes only tests, fmt, clippy and the 1.91.1 check are clean, and CI is green on 65 of 65 checks.

@demohan demohan left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Posted twice by mistake; the review above stands.

@LeeroyHannigan
LeeroyHannigan added this pull request to the merge queue Nov 26, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 26, 2026
@LeeroyHannigan
LeeroyHannigan added this pull request to the merge queue Nov 26, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Nov 26, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants