Skip to content

fix(server): authenticate a request with an empty body first - #1265

Open
LeeroyHannigan wants to merge 11 commits into
fix/1195-syntax-fault-messagefrom
fix/1259-empty-body-auth
Open

LeeroyHannigan wants to merge 11 commits into
fix/1195-syntax-fault-messagefrom
fix/1259-empty-body-auth

Conversation

@LeeroyHannigan

@LeeroyHannigan LeeroyHannigan commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Changes since the last review

What

A request with an empty body now goes to authentication before ExtendDB reads the body, as DynamoDB does. Before this change, ExtendDB checked the JSON syntax of each body before authentication, and an empty body failed that check with a SerializationException.

The change is in crates/server/src/handler.rs. The check before authentication skips a body of zero bytes. After authentication, the parse refuses an empty body with serialization_refusal(), as it did before, so a signed empty body still gets a SerializationException with no message. Every other body takes the same path as before.

In the tests, _unauthenticated_put in tests/test_request_nesting_depth.py is now _unauthenticated_post. It takes the operation, and it can sign for an access key that does not exist. tests/test_syntax_fault_message.py gets one table of 15 bodies. The test sends each body unsigned, signed for that key, and signed with the caller's key and a wrong secret.

The Rust test empty_body in tests/rust/src/raw_http.rs sends an unsigned GetItem with an empty body. It expected a SerializationException and skipped DynamoDB. It now expects the missing token error and runs against DynamoDB too.

The base of this PR is #1261, which changes the same lines of handler.rs.

A new paragraph of the security manual (docs/manuals/10-security-model.md) states this order for an empty body.

Why

DynamoDB's answers, measured in us-east-1 on 20 November 2026. Each DescribeTable request went out twice and got the same answer both times. "Unknown key" is a signature for an access key that does not exist. "Wrong secret" is a signature with the caller's key and a wrong secret key. The wrong secret column comes from 3 December 2026, except for the empty body (20 November). On 3 December the {} row got the same answers again, with no signature and for an unknown key.

Body No signature Unknown key Wrong secret
empty MissingAuthenticationTokenException UnrecognizedClientException InvalidSignatureException
one space, \n\t, \n, {, x, a byte order mark alone, {not json, one NUL byte SerializationException with no message SerializationException with no message SerializationException with no message
{}, null, [], "x", 5, {"TableName": "<table>"} MissingAuthenticationTokenException UnrecognizedClientException InvalidSignatureException

So DynamoDB checks the JSON syntax of a body before authentication. A body of zero bytes is the one body that passes this check with no JSON in it. Other requests with an empty body, measured the same day, got these answers.

  • signed with a known key and a wrong secret, for DescribeTable and PutItem: InvalidSignatureException
  • signed in full, for DescribeTable and PutItem: SerializationException with no message
  • an Authorization header with no =: IncompleteSignatureException
  • a credential scoped to another region: InvalidSignatureException
  • UpdateContinuousBackups, RestoreTableToPointInTime and GetItem with no signature: MissingAuthenticationTokenException

On #1261's head, ExtendDB answered every one of these unsigned or badly signed requests with a SerializationException. With this change, each of them gets DynamoDB's exception type, as do all 45 body and signing pairs in the table. The type for a missing signature differs (#1075), and so does the namespace of UnrecognizedClientException (#1116).

Fixes #1259

Testing done

  • CI's Test workflow passed at fb0d3ea (run 45570786171, 25 November 2026). Its run-tests jobs, on stable and on 1.91.1, ran cargo test --locked --workspace --exclude extenddb-backup-store and cargo test --locked -p extenddb-backup-store. In each job, the server crate's unit tests gave 530 passed and 0 failed. 53d0c75 changes only tests/test_syntax_fault_message.py, and CI has not run on it yet.
  • cargo +1.97.0 clippy -p extenddb-server --all-targets -- -D warnings and cargo +1.97.0 fmt --all -- --check are clean at 6aa0a50, at ff8f38b and at 91a55bc.
  • Against ExtendDB on SQLite at 6aa0a50, tests/test_syntax_fault_message.py and tests/test_request_nesting_depth.py passed 70 tests. Against a server built from fix(server): send no message for a body with a JSON syntax fault #1261's head, an empty body gets a SerializationException, unsigned and with an unknown key.
  • At 53d0c75, tests/test_syntax_fault_message.py passed 60 tests against SQLite and 60 against PostgreSQL. The servers ran a build of fb0d3ea, whose Rust code 53d0c75 keeps. With tests/test_request_nesting_depth.py, 165 tests passed against each.
  • A SQLite server built from fb0d3ea with the empty body branch of handle_request removed fails 3 of the 60 tests. They are the empty body with no signature, for the unknown key, and with the wrong secret. The {} row passes there, because that branch changes only a body of zero bytes.
  • With one character of the expected wrong secret message changed, the 7 wrong secret pairs that reach authentication fail against SQLite.
  • At 53d0c75, pytest --collect-only collects tests/ (6825) and tests/python (672) with no error.

The unit tests have no new row. The existing unit row for b"" already checks the answer after authentication, and the signed empty row of tests/test_syntax_fault_message.py checks it on the wire.

Line counts of this PR's own change at 53d0c75: production +11 -5, tests +97 -14, and one new paragraph of the security manual.

This PR adds no conflict with an open PR: each open PR that conflicts with it has the same conflicting files with #1261. Its empty body branch in handler.rs falls inside a conflict hunk that #200, #547, #549, #557, #587, #850 and #854 each already have there. 28 open PRs outside #807, #1261, #1265, #1344 and #1372 change docs/manuals/10-security-model.md. Of these, only #140 conflicts with this branch in that file, and it has the same four conflict hunks with main. At 53d0c75, git merge-tree shows no conflict with #1344 at 693b815 or #1372 at 4f689ba.

With main at c057660 (3 December 2026), git merge-tree of 53d0c75 reports conflicts in README.md, crates/engine/src/lib.rs and crates/wasm-adapter/src/runtime.rs. #1261 at 600726b and #807 at 71b3e1b have the same three conflicts. This PR changes none of the three files.

Not in this PR, each in an open issue:

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

Breaking changes

A request with an empty body and no valid signature now gets the authentication error, where it got a SerializationException with no message. With no signature, it gets ExtendDB's MissingAuthenticationToken error (#1075). Signed for an access key that does not exist, it gets UnrecognizedClientException, and with a wrong secret InvalidSignatureException. A signed empty body still gets the SerializationException with no message.


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.

For a DescribeTable request with an empty body and no signature,
DynamoDB answers MissingAuthenticationTokenException. Signed for an
access key that does not exist, it answers UnrecognizedClientException.
ExtendDB answered both with a SerializationException, since it checked
the JSON syntax of the body before authentication.

Measured in us-east-1 on 2026-11-20. Each body went out twice and got
the same answer both times. A body of one space, a lone "{" or a lone
byte order mark got a SerializationException, unsigned and with the
unknown key. The bodies {}, null, [], "x" and 5 got the authentication
error. Signed, an empty body got a SerializationException with no
message.

ExtendDB now parses an empty body only after authentication. That parse
refuses it with no message, as before. ExtendDB's type and text for a
missing signature still differ from DynamoDB's (#1075).

Fixes #1259.
An empty body now goes to authentication before its syntax is read, as
DynamoDB does. The raw HTTP test of an unsigned empty body expected a
SerializationException and skipped DynamoDB. It now expects the missing
token error, which DynamoDB also sends, and runs on both.
Merges 748d21e of fix/1195-syntax-fault-message. That brings in
fix/request-nesting-depth at 4c2995c and the merge commit of that
branch. The 4c2995c head holds the syntax scan with the service's
grammar in request_syntax.rs and the merges of main at 44cd436 and
6aef346.

Conflicts and their resolution, both in tests/test_request_nesting_depth.py:

- test_a_malformed_deep_body_is_refused_before_authentication: the
  other branch added the leaf parameter and its rows. This branch
  renamed the helper _unauthenticated_post. Kept: the other branch's
  body construction and comment, and the call to _unauthenticated_post.
- test_a_complete_deep_body_reaches_authentication: the same two
  changes on the same lines. Kept the same way.

Auto-merged: handler.rs keeps the empty body branch before the
one-argument check_request_syntax call. request_parse.rs keeps the
module doc sentence about an empty body beside the other branch's
check. tests/rust/src/raw_http.rs and tests/test_syntax_fault_message.py
are this branch's alone.
The security manual's paragraph on the syntax check, from
fix/request-nesting-depth, said that every body is checked before
authentication. On this branch a body of zero bytes goes to
authentication first, as on the service, and the parse refuses it after that. The
paragraph now says so.
The note that an empty body goes to authentication first now follows the
syntax check paragraph as a paragraph of its own. The first sentence of
that paragraph is again the one fix/request-nesting-depth wrote. The
sibling branches fix/1257-leading-zero-numbers and fix/1343-number-forms
change a later sentence of the same paragraph. With the note inside that
paragraph, every edit to it conflicted with theirs. The paragraphs now
merge clean.
Merges 0986467 of fix/1195-syntax-fault-message, its merge of
fix/request-nesting-depth at b9baaf5. That commit 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 refusals and
the authentication errors that this branch's tests assert. The two
errors that get the Message key are not among them. A refusal with an
empty message still has no message key.
Merges 654fef3 of fix/1195-syntax-fault-message, its merge of
fix/request-nesting-depth at 1a9efd7. That brings main at b0d1c64
(#1280, #1009 and #596). It also brings the commit that makes the
handler call extenddb_engine::check_operation and
with_body(input).admit() around the server's parse. The README item on
the PartiQL operations now says that a server answers a body that does
not parse with no message.

No conflicts. crates/server/src/handler.rs auto-merged. The two hunks of
the other branch are the name check and the point-in-time refusal. This
branch's empty body branch, before the parse and the syntax check, sits
between them. So the handler checks the operation name and scans the
depth, and it leaves an empty body for later. Then it authenticates the
caller, parses the body and calls admit.
Merges 7d7a089 of fix/1195-syntax-fault-message. That brings three
commits:

- its merge of fix/request-nesting-depth at 027483d, which changes one
  sentence of the WebAssembly adapter's module doc
- 3f5ccff, after which the helper _is_messageless_serialization_error
  of tests/test_request_nesting_depth.py compares the whole error
  document
- 7d7a089, after which REQ-ERR-002 in docs/design/01-requirements.md
  says that a SerializationException for a body that does not parse has
  no message field

No conflicts. tests/test_request_nesting_depth.py auto-merged: the
helper is above this branch's _unauthenticated_post. This branch's
refused rows in tests/test_syntax_fault_message.py call the helper, so
they now compare the whole document too.
test_which_bodies_are_refused_before_authentication compared only the
start of the type after the "#" for a body that reaches authentication.
For an access key that does not exist, the service and the server send
the same message (DescribeTable, us-east-1, 2026-11-25). The test now
compares it by equality with "The security token included in the
request is invalid."

The test does not compare the message for a missing signature, because
ExtendDB's type and message differ from the service's (#1075). The
comment above AUTHENTICATION_ERRORS now says so.
Merges 600726b of fix/1195-syntax-fault-message, its merge of
fix/request-nesting-depth at 71b3e1b. That brings the rows at the
edges of the syntax check's looser rules. At 63 and at 20000 wrappers,
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 refusal before it.

No conflicts. crates/server/src/request_parse.rs and
tests/test_request_nesting_depth.py auto-merged. The new rows are
parameters of the two tests that send through _unauthenticated_post,
this branch's name for the helper. They run unsigned and badly signed.

@navareamol navareamol 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.

I think the description and the new test table disagree on the count. The description says "all 30 body and signing pairs in the table", and its Why table lists {} with the bodies that reach authentication. UNAUTHENTICATED_ROWS in tests/test_syntax_fault_message.py has 14 bodies and no {}, so the test sends 28 pairs. Against SQLite at fb0d3ea, {} to DescribeTable, unsigned and signed for the unknown key, gets the authentication error, so adding "empty-object": (b"{}", False) should pass. Could you add that row, or change the number in the description?

The new test pins two of the signings the description lists for an empty body. AUTHENTICATION_ERRORS has the unsigned and unknown key cases only. The description also says a wrong secret gets InvalidSignatureException, a credential scoped to another region gets InvalidSignatureException, and an Authorization header with no = gets IncompleteSignatureException. I checked those on SQLite: each fails on a server built from fb0d3ea with the empty body branch removed and passes at fb0d3ea, so the behaviour is right. _unauthenticated_post already takes "bad-signature". Could you add it to AUTHENTICATION_ERRORS with ("InvalidSignatureException", None), so the wrong secret case is pinned by this PR's own test?

For the stack: this head does not merge cleanly with current main (222d80a). The conflict is in crates/engine/src/lib.rs, between main's #[cfg(test)] mod test_context; and the pub use pre_dispatch line from #807, so it comes from the base and not from this PR. Keeping both lines builds, and the same tests pass on that merged tree against SQLite. CI on fb0d3ea ran against fix/1195-syntax-fault-message only, so I think it needs a run on a tree updated with main once the base lands.

I will approve once the {} row and the wrong secret case are in the test table, or the description says 28 pairs, and CI is green on a branch updated with main.

test_which_bodies_are_refused_before_authentication now sends `{}` too,
and it signs each body with the caller's key and a wrong secret as well.

DynamoDB answers a DescribeTable with the body `{}` with the
authentication error (us-east-1, 2026-11-20 and 2026-12-03). With no
signature it sends MissingAuthenticationTokenException, and for an
access key that does not exist UnrecognizedClientException. With the
caller's key and a wrong secret, it refuses the eight bodies that the
syntax check refuses with a SerializationException with no message. It
answers the other seven with InvalidSignatureException (2026-12-03, and
the empty body on 2026-11-20). ExtendDB sends the same message for this
exception, so the test compares it by equality.

The table now has 15 bodies and three signings, so the test sends 45
pairs. On a server built from this branch with the empty body branch of
handle_request removed, the three pairs with the empty body fail. The
pair with the wrong secret is one of them.
@LeeroyHannigan

Copy link
Copy Markdown
Collaborator Author

@navareamol

The {} row: 53d0c75 adds "empty-object": (b"{}", False) to UNAUTHENTICATED_ROWS. I sent {} to DescribeTable on DynamoDB on 3 December 2026, for a table that does not exist, each request twice (us-east-1). With no signature it got MissingAuthenticationTokenException. Signed for AKIAEXAMPLEEXAMPLE01, the test's unknown key, it got UnrecognizedClientException with "The security token included in the request is invalid.", as it did for AKIAIOSFODNN7EXAMPLE.

The wrong secret: 53d0c75 also adds "bad-signature" to AUTHENTICATION_ERRORS, with the message as well as the type. For a wrong secret, the service and ExtendDB send the same text: "The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details." On the same day I sent each body of the table to DynamoDB with the caller's key and a wrong secret, twice. The eight bodies that the syntax check refuses got a SerializationException with no message. {}, null, [], "x", 5 and the one-object body got InvalidSignatureException with that message. The empty body got the same on 20 and 25 November.

The test now sends 15 bodies with three signings, 45 pairs, and the description says 45. At 53d0c75 the file passes 60 tests against SQLite and 60 against PostgreSQL. I also built a server from fb0d3ea with the empty body branch removed. Against it, 3 of the 60 fail: the empty body with no signature, for the unknown key, and with the wrong secret. The {} row passes there too, because that branch changes only a body of zero bytes. With one character of the expected message changed, the 7 wrong secret pairs that reach authentication fail.

The stack and main: at main c057660 (3 December 2026), git merge-tree gives the same three conflicting files for #807 at 71b3e1b and for this head: README.md, crates/engine/src/lib.rs and crates/wasm-adapter/src/runtime.rs. This PR changes none of them. The stack takes main at #807 first. Then each branch merges its parent's new head, so CI runs on the merged trees.

@navareamol

Copy link
Copy Markdown
Collaborator

The {} row and the wrong secret case are in the test table, and the description says 45 pairs. The file has 15 bodies and three signings, and it passes 60 tests on SQLite at 53d0c75.

  1. With the empty body branch removed from handle_request, 3 of the 60 fail: the empty body unsigned, for the unknown key and with the wrong secret. The {} rows pass there, as you wrote, so they guard the order and do not detect this change. Your answers from DynamoDB for {} and for the wrong secret are your measurements, and I did not repeat them.

  2. The expected message of the wrong secret case equals the text at crates/auth/src/sigv4/verify.rs:152. With one word of that message changed, 7 of the 60 fail, all wrong secret rows of the bodies that reach authentication. The other region and the Authorization header with no = rows in the description are not in the test table. I ran them as separate cases and they pass, so that part is optional.

  3. The conflict with main is the same on fix(server): parse request bodies nested to the depth the service validates #807's head and on this head: README.md, crates/engine/src/lib.rs and crates/wasm-adapter/src/runtime.rs. This PR changes none of them, so I agree it comes from the base.

Five checks are red at 53d0c75: run-tests (stable and 1.91.1), test, mongodb-rust and mongodb-integration. The logs show secmem::tests::init_refuses_under_a_low_memlock_limit_then_starts_unlocked failing at secmem.rs:482 for the first four, and mongodb-integration fails in its gate step. The branch does not have #1522, and #1167, which has it, passes run-tests. The wire jobs pass on every backend. I could not reproduce the secmem failure on my host, so the CI log is what I am going on.

I will approve once the checks are green after the stack has taken main at #807.

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