Skip to content

fix(engine): refuse a BatchGetItem table value with no Keys by path - #1301

Open
LeeroyHannigan wants to merge 5 commits into
fix/1266-batch-type-fault-firstfrom
fix/1283-batch-keys-null
Open

LeeroyHannigan wants to merge 5 commits into
fix/1266-batch-type-fault-firstfrom
fix/1283-batch-keys-null

Conversation

@LeeroyHannigan

@LeeroyHannigan LeeroyHannigan commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator

Changes since the last review

What

Within the table and key counts, a BatchGetItem table value of {} or {"Keys": null} now gets DynamoDB's ValidationException at the member path of Keys: Value null at 'requestItems.<t>.member.keys' failed to satisfy constraint: Member must not be null. Before, it got a SerializationException with the parser's text.

KeysAndAttributes in crates/core/src/types/batch.rs reads Keys as an optional list. check_batch_get in crates/engine/src/request_limits.rs runs the count checks, then refuses each table value with no Keys, in one message of at most 10 clauses through validation_refusal. It lists the tables in name order. DynamoDB lists the same clauses in an order of its own. The same names got the same order on each send, and that order was neither the name order nor the order of the request. The handler runs check_batch_get after authorization, before it reads any table.

The null clause uses NOT_NULL, which moves from the PartiQL request checks to request_limits.rs. Found::null in the PartiQL checks writes the same clause, but it builds only with the partiql feature, and this check runs in every build.

The base of this PR is #1285.

Fixes #1283

Why

These are DynamoDB's answers in us-east-1 on table names that do not exist, measured on 20, 21 and 25 November and 2 December 2026. Each request went out twice and got the same answer both times. KEYS is {"Keys": [{"pk": {"S": "a"}}]}. NULL(t) is the clause above for the table t. SE is SerializationException.

RequestItems DynamoDB ExtendDB on #1285 ExtendDB with this PR
2 tables, the second {} or {"Keys": null} NULL(the second) SE DynamoDB's answer
1 table, {} or {"ProjectionExpression": "pk"} NULL(the table) SE DynamoDB's answer
2 tables, both {} 2 validation errors detected: and NULL of each SE DynamoDB's answer
3 tables: {}, KEYS and {"Keys": null}, in two written orders 2 validation errors detected:, NULL of the first and the third, in an order of its own SE DynamoDB's clauses, in name order
...-zz, ...-a and ...-mmm, each {} 3 validation errors detected:, NULL of zz, mmm and a SE DynamoDB's clauses, in name order
11 tables, each {} 10 validation errors detected:, NULL of 10 of the 11 tables SE the first 10 in name order
1 table, {"Keys": null} with "ConsistentRead": "x" or "ProjectionExpression": 5 SE SE SE
1 table, {"Keys": []} Value at 'RequestItems.<t>.member.Keys' failed to satisfy constraint: Member must have length greater than or equal to 1 the same the same
1 table {}, and "ReturnConsumedCapacity": "X" NULL(the table), then the enum clause of returnConsumedCapacity SE the enum clause alone (#1300)
the table a* with {} NULL(a*) the server's map key clause at requestItems the same (#1300)

With this change, 11 of the 14 measured requests get DynamoDB's clauses, against 3 on #1285. The request of 11 tables gets 10 clauses too, for other tables than DynamoDB's 10. For an SE these counts compare the type only, because its texts are #1012.

This change gives a new answer to a request that is not measured. A table with no Keys can sort before a table whose parse gives another ValidationException, such as an empty ExpressionAttributeNames. That request now gets the other text, where #1285 answered SerializationException (#1300). On a MongoDB build the parse reads the tables in the written order, so there the written order decides which fault comes first.

A principal with no policy gets AccessDeniedException for a table without Keys, on #1285 and with this PR. DynamoDB's answer to that principal is not measured, because it needs a principal with no policy.

Testing done

At ce056e8, whose tree is the tree of d7c260b:

  • cargo test -p extenddb-core --lib: 1242 passed. cargo test -p extenddb-engine --lib: 980 passed. cargo test -p extenddb-wasm-adapter: 4 passed, the parity corpus test among them.
  • cargo +1.97.0 fmt --all -- --check, the two clippy commands of .github/workflows/clippy.yml with -D warnings on extenddb-core, extenddb-engine and extenddb-server, cargo +1.97.0 clippy -p extenddb-engine --lib --no-default-features -- -D warnings and cargo +1.94.0 check --all-targets on the same crates are clean.
  • python3 -m pytest --collect-only -q collects 7223 tests in tests and 742 in tests/python, with no error.
  • The unit table batch_get_tables_without_keys has 12 rows. Without the cap in validation_refusal, row 9 fails. Without the sort, rows 5 and 9 fail. With the null check before the counts, rows 10 and 11 fail.
  • Against SQLite and PostgreSQL servers built from this head: tests/python/test_batch.py, tests/test_batch_operations.py and tests/test_batch_write_validation_order.py passed 122 tests on SQLite and 122 on PostgreSQL, 77 of them in test_batch.py. On SQLite, tests/test_partiql_requests.py, tests/test_partiql_batch.py and tests/test_partiql_transaction.py passed 439 tests, with 2 expected failures. On SQLite, tests/test_authz_cross_account.py passed 19.
  • This head's test_batch.py against a server built from fix(engine): refuse a batch table value of another type before counts #1285's head: 9 failed and 68 passed. The 9 failures are the rows that expect a null clause.

Line counts against #1285: production +66 -23, tests +154 -0.

This PR adds conflicts in crates/engine/src/batch_get_item.rs with #507 and #536, and with #547, #549, #557 and #587, which stack on #536. The loops over Keys change in each. #536 also builds a KeysAndAttributes, which needs keys: Some(...) after this PR.

Not in this PR:

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 BatchGetItem table value with no Keys gets a ValidationException in place of a SerializationException, as the What section says. Other requests get the same answers as before.


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.

A BatchGetItem table value of {} or {"Keys": null} within the table
count got a SerializationException with the parser's text. DynamoDB
answers a ValidationException that names each such table at
requestItems.<table>.member.keys. It lists the tables in one message,
in table name order. It still answers a SerializationException when
another member of the value has another JSON type. These answers were
measured on 20 and 21 Nov 2026.

KeysAndAttributes now reads Keys as an optional list. The handler
refuses a table value without one after the count checks and before
it reads any table. A request over the table count keeps its answer.

Fixes #1283.

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

A BatchGetItem table value with no Keys is refused by member path at 2af9d1f, and no shape answers worse than on the base. Of 38 shapes sent twice to us-east-1 and to this head and its base on SQLite and PostgreSQL, this head matches the service's text on 17, its clause set on 3 more and its error type on 15, and the two backends agree everywhere; the ten-clause cap matches the service's 10 clauses for 11 tables. Removing the null refusal or the sort fails the tests, fmt, clippy, the 1.91.1 check and the core and engine lib tests are clean, and test_batch.py, test_batch_operations.py and test_authz_cross_account.py pass on both backends. Onto main at 222d80a the head merges cleanly and builds and passes the 1.94.0 check; the wasm parity failure is #1215's BatchWriteItem count form. No merged PR fixes #1283.

The branch conflicts with its base: it was cut from 248c7ea, and the base has since merged main (5252eda) and taken 98d471c, which adds validation_refusal in the lines refusal() rewrites here, so the green CI ran on a tree without them. Merging the base and calling validation_refusal would resolve it.

I will approve once the base is merged, the missing-Keys tables are not asserted in name order, and a table with no Keys beside a count fault answers as the service does.

Comment thread crates/engine/src/request_limits.rs Outdated
.iter()
.filter_map(|&(table, keys)| keys.is_none().then_some(table))
.collect();
missing.sort_unstable();

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 service does not list the missing-Keys tables in name order: over 16 random prefixes and 5 rows, name order held in 31 of 80 sends, a repeat of the same names gave the same order 40 of 40, and the written order made no difference (16 of 16). Run against the service, the new two-target test failed 2 of 10 and then 3 of 10 at its endswith order check (test_batch.py:445 and :487, and the unit row at line 596). Accepting any order in the tests, and saying so in the comment and the body, would hold what 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.

d7c260b changes the check. Against DynamoDB, the wire test checks the count, and that each clause is one of the expected clauses, in any order. Against ExtendDB it compares the message, with the tables in name order. The doc of check_batch_get, the test comments and the body say that DynamoDB uses an order of its own, and the unit rows are ExtendDB's order. DynamoDB's order matches #781's hash_map_order on all 7 measured requests with more than one null clause, of 25 November and 2 December.

.iter()
.map(|(table, ka)| (table.as_str(), ka.keys.as_ref().map(Vec::len)))
.collect();
check_batch_counts("BatchGetItem", &tables)?;

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.

With a per-table count fault or an over-total request beside a table with no Keys, the counts answer alone here. For {a: {"Keys": []}, b: {}} the service sends two clauses, the null clause for b and Value '[]' at 'requestItems.<a>.member.keys'; for 101 keys and {}, two clauses; for 60 and 50 keys and {}, the null clause alone, where this head sends Too many items requested. The base answers the same as this head. Removing the cap at line 146, or moving the null check ahead of the counts, still passes all 872 engine tests, so neither is pinned.

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.

I measured four of these again on 2 December. A table {} went beside {"Keys": []}, beside a table of 101 keys, beside tables of 60 and 41 keys, and into a request of 101 tables. DynamoDB gave the answers you list, both sends. On #1285 and on main the count checks run before the null check. The server's check before authorization does the same, so this PR keeps that order. #1300 tracks it, with these four requests added.

d7c260b pins the cap and the order. A row of 11 tables fails without the cap in validation_refusal, and two rows fail with the null check before the counts.

Comment thread crates/engine/src/batch_get_item.rs Outdated
.collect();
request_limits::check_batch_counts("BatchGetItem", &counts)?;
// table. The server runs the same checks before authorization. Then
// refuse a table value with no Keys list, so every table below has one.

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 null check runs after authorization: a user with no policy gets AccessDeniedException for {} here and on the base, while Keys: [] gets the ValidationException before authorization. On the service the null and count clauses come in one message, so they are likely one pass before authorization; that is inferred, since it needs a restricted principal to measure. The module doc's "return the same text" no longer holds. request_limits.rs is now 637 lines.

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.

The null check stays in the handler. DynamoDB's answer to a principal with no policy is not measured, so the order around authorization is open, as you say. d7c260b changes the module doc: both paths give the same count refusal, and only the handler refuses a table with no Keys, after authorization. request_limits.rs has 877 lines at this head.

This branch was cut from 248c7ea. The base now holds main at
01556cf and the quoted request map form of the BatchWriteItem count
refusals. It also finds a batch value of another JSON type in any table.
The base added validation_refusal in the lines that refusal() rewrote
here, and it has no count_error now.

The merge drops refusal() and count_error. check_batch_get calls
validation_refusal, which keeps the first 10 clauses, so its own cap
goes.
NOT_NULL moves from partiql/request_checks.rs to request_limits.rs,
beside AT_LEAST_ONE, as #1375 moved that constant. check_batch_get
writes its null clause with it. The PartiQL module builds only with the
partiql feature, and check_batch_get runs in every build, so the clause
cannot come from Found::null.
DynamoDB gave the tables with no Keys one order on both sends, but not
name order (measured 25 Nov and 2 Dec 2026). check_batch_get keeps the
name order, and its doc and the test comments now say so. The wire test
checks the clauses in any order against DynamoDB, and the message by
equality against ExtendDB.

A new row of 11 tables with no Keys expects the first 10 in name order.
Its wire row checks that DynamoDB names 10 of the 11. Two unit rows pin
ExtendDB's answer to a table with no Keys beside a count fault. There
DynamoDB adds the null clause, or answers it alone (#1300).

The module doc says that the null refusal comes after authorization. The
handler comment says that the reads of keys never take their default.
#1215 now writes per_table_count_error with validation_refusal, and
the base merged it. No branch above #1215 has per_table_count_error,
so no file changes.
@LeeroyHannigan

Copy link
Copy Markdown
Collaborator Author

@demohan

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