Skip to content

fix(scan): check the numbers in ExpressionAttributeValues as the service does - #562

Open
LeeroyHannigan wants to merge 52 commits into
mainfrom
fix/scan-number-check
Open

LeeroyHannigan wants to merge 52 commits into
mainfrom
fix/scan-number-check

Conversation

@LeeroyHannigan

@LeeroyHannigan LeeroyHannigan commented Oct 25, 2026 •

Copy link
Copy Markdown
Collaborator

Changes since the last review

LJMart11 reviewed 4c08c09 on 3 Dec. One commit comes after that review:

LJMart11 reviewed 009c4c1 before that. Two commits came between the two reviews:

  • 4c08c09 adds the upgrade manual entry that LJMart11 asked for to docs/manuals/07-upgrade-manual.md. Its heading is "v1.2.0: Scan checks its values against the number rules, before the table lookup and the IAM decision". It comes after the three v1.2.0 entries of main. It gives the number check with the 1.1.0 answers that it replaces. It also gives the order of the checks with the new Limit text, and the checks before the IAM decision. The entry names the dates of the DynamoDB measurements.
  • 4811268 merges main at c057660, 20 commits after the main commit of the last merge. No file conflicted. Git merged crates/engine/src/lib.rs and crates/server/src/request_helpers.rs with no overlap: fix(query): refuse key condition values over the key size limits #481 adds a test module in the first, and fix(core): answer a request with no Authorization header as DynamoDB does #1290 changes extract_operation in the second. Testing done gives the gates at 4c08c09.

These changes came before the review of 009c4c1:

What

Scan now checks the N values in ExpressionAttributeValues at request time. A filter on {"N": "bob"}, a bob nested in an L, an M or an NS, 1e200, a 39-digit value or an empty N answered 200 with Count: 0. Each now answers the service's ValidationException before ExtendDB reads any row, whether or not an expression reads the value. The texts are The parameter cannot be converted to a numeric value: bob, the overflow, underflow and 38-digit texts, and The parameter cannot be converted to a numeric value: for an empty N.

The checks run in validate_scan_request_body (crates/engine/src/scan_request.rs) on the raw request body, before ExtendDB deserializes the body and looks the table up. For a body whose ExpressionAttributeValues the service can read, they run in the order the service uses:

  1. the range checks on Limit (at least 1), Segment (0 to 999999) and TotalSegments (1 to 1000000), each when present, the first fault in that order
  2. the ReturnConsumedCapacity enum
  3. the expression and non-expression parameter mix (AttributesToGet, ScanFilter, ConditionalOperator against ProjectionExpression, FilterExpression)
  4. the ExpressionAttributeNames checks: an empty map, an invalid key and an empty name
  5. every number in ExpressionAttributeValues, nested ones and NS members included
  6. an empty set and a set with a duplicate member
  7. the Select enum

An invalid Select beside an invalid ReturnConsumedCapacity answers the ReturnConsumedCapacity text alone, as on the service. Step 1 uses the Limit text that Query uses and the Segment and TotalSegments texts of main. The service's range texts are #563, which #850 brings.

The service cannot read some values as one type. These are a null, {}, an unknown type descriptor, two descriptors, and a descriptor with a null payload, at any L or M depth. Beside such a value the service answers in another order, which #544 encodes in unreadable_value_checks. After the range checks, Scan calls that function. It reports an invalid Select and an invalid ReturnConsumedCapacity together, then checks the mix, the names and the values. The function now takes the mix check as an argument, so Scan passes its own members. So {"Select": "BAD", "ReturnConsumedCapacity": "BAD", "FilterExpression": "a = :a", "ExpressionAttributeValues": {":a": {}}} answers both enum texts in one message, as on the service and on main. A null beside Select: "bad" answers the Select text.

When a check fails, #544's shape_fault_first deserializes each member of the body, and each value, on its own. Scan passes it the body from readable_for_shape_check, which replaces the parts of a value that the service cannot read. A SerializationException for a member of the wrong JSON type is then the answer, in any member order. A null value is not a shape fault. A number in Limit, Segment or TotalSegments is not one either: the service reads Segment: 1.5 and TotalSegments: 2.5 beside Select: "NOPE" and answers the Select text. A string that the service reads as a boolean in ConsistentRead is not a shape fault since #544's round 2.

The server runs validate_scan_request_body in authorize_request (crates/server/src/request_helpers.rs) beside the Query check, after the cross-account refusal and before the IAM decision. A malformed Scan from a principal that may not Scan the table now gets the request's ValidationException, as on the service, where it got AccessDeniedException. The checks read only the request body.

The handler still makes the undefined value, unused value and filter syntax checks, after the request-time checks. It also makes the Segment pairing checks and the IndexName, ConsistentRead, Select with ProjectionExpression and ExclusiveStartKey checks. On the service the filter checks come ahead of Select. The pairing check comes ahead of the table lookup and the IAM decision there. #1391 tracks both.

scan_request.rs takes LIMIT_BELOW_ONE, the two enum member lists, validate_names, validate_expression_attribute_value_numbers, unreadable_value_checks, readable_for_shape_check, shape_fault_first and sorted_entries from query_key_values.rs. Its own code is the Scan parameter mix, the range checks and validate_sets. That set check reads each value with the AttributeValue deserializer and keeps the ValidationException it raises.

Why

Scan served a filter on an N value that is not a number. The service refuses the request (#545).

Closes #545

Differences that remain

Overlaps with other PRs

Testing done

Measured on the service

Amazon DynamoDB in us-east-1, raw signed Scan requests with the members in the order written, each sent twice with the same answer both times. The 2026-11-23 and 2026-12-03 requests went to a table name that does not exist. The 2026-11-19 requests went to a table keyed on pk and sk, both S. The rows of the DescribeTable role came from a role allowed only dynamodb:DescribeTable on it.

Body (beside TableName) Time (UTC) DynamoDB
ReturnConsumedCapacity: "NOPE" beside a mix of FilterExpression with ScanFilter, AttributesToGet or ConditionalOperator 2026-11-23 13:59, 2026-11-19 16:14 the ReturnConsumedCapacity text
:n {"N": "bob"} beside the names {"a": "b"}, {} or {"#a": ""} 2026-11-23 13:59, 2026-11-19 16:14 the names text
Select: "NOPE" beside a duplicate or empty NS, a duplicate SS or BS, or a duplicate NS in an L 2026-11-23 13:59, 2026-11-19 16:15 the set text
a duplicate NS or an empty NS beside :n {"N": "bob"} 2026-11-19 16:15 the set text in one request, the number text in the other
Select: "bad" beside a null, {"L": [null]} or {"S": null} 2026-11-23 13:59 and 16:34 the Select text
Select: "BAD", ReturnConsumedCapacity: "BAD", :a {} 2026-11-23 14:03 both enum texts in one message
Limit: 1.5, Select: "BAD", ReturnConsumedCapacity: "BAD" 2026-11-23 14:03 both enum texts in one message
ScanFilter, FilterExpression, :x {"X": "1"} 2026-11-23 16:47 the mix text
Limit: 0, :u {"X": "1"}, Select: 5 2026-11-23 13:59 SerializationException NUMBER_VALUE cannot be converted to String
Segment: 1.5, TotalSegments: 2, Select: "NOPE" 2026-11-23 16:34 the Select text
Segment: 0, TotalSegments: 2.5, Select: "NOPE" 2026-11-23 16:34 the Select text
FilterExpression: "a = :a OR a = :n", :a {}, :n {"N": "bob"} 2026-11-23 16:34 ExpressionAttributeValues contains invalid value: The parameter cannot be converted to a numeric value: bob for key :n
:n {"N": "1e9999999999"} and {"N": "1e-9999999999"} read by the filter 2026-11-23 16:34 the overflow and underflow texts
the six Segment and TotalSegments rows of test_segment_ranges, each beside :n {"N": "bob"} 2026-11-23 13:59 and 16:47 1 validation error detected: Value at 'Segment' ... or ... 'TotalSegments' ...
Limit: 0, Segment: -1, TotalSegments: 1000001 beside :n {"N": "bob"} 2026-11-19 16:15 the three range texts in one message
Segment: 5, TotalSegments: 2 2026-11-23 16:34 the pairing text
Segment: 0, TotalSegments: 1 2026-11-23 16:34 ResourceNotFoundException, so the request passes the checks
Select: "bad" beside FilterExpression: "a = :undef" 2026-11-23 13:59 the undefined value text
the nine malformed bodies of test_scan_checks_before_authorization.py, from the DescribeTable role 2026-11-19 16:34 the ValidationException of each body
a valid body from the DescribeTable role 2026-11-19 16:34 AccessDeniedException
:n {"N": "bob"} read by FilterExpression: "a = :n", and the same value in a request with no expression 2026-12-03 15:40 the number text
Limit: 0, ReturnConsumedCapacity: "NOPE", or the names {"a": "b"} beside FilterExpression: "attribute_exists(a)" 2026-12-03 15:40 the Limit, ReturnConsumedCapacity or names text

Tests

  • crates/engine/src/scan_request/tests.rs: eight unit tests. The new rows sit in one data table, names_sets_and_unreadable_values_are_reported_in_the_measured_order, and each row asserts the full text by equality. cargo +1.97.0 test -p extenddb-engine --lib: 922 passed at ad5f485.
  • tests/test_scan_number_values.py: 89 wire tests that run against either the service or ExtendDB. Where ExtendDB's text differs from the service's, the row has both and names the issue. The range rows, the pairing row, the duplicate set row and the {} beside bob row do that. TestRequestOrder holds the new rows. test_two_bad_numbers_report_one_of_them still accepts either value: the service's pick varied between two runs, and Two faults in one request map: ExtendDB can report another member than the service #1013 tracks its order.
  • tests/test_scan_checks_before_authorization.py: one test that only ExtendDB runs. It sends nine malformed bodies as a user allowed only DescribeTable, then a valid body. Its account and user setup is the ManagementPrincipals base class, which tests/test_query_leading_keys_values.py now shares.
  • .github/workflows/integration.yml collects both wire files in the jobs run-integration and run-integration-sqlite.

Controls

Each control put back one old line, or took out one new check, then ran the tests:

  • ReturnConsumedCapacity after the mix: the mix unit test fails.
  • No names check: the measured-row table fails on its names row.
  • No set check: the table fails on its duplicate row.
  • No path for a value the service cannot read: the table fails on its null row.
  • The shape check on the raw body: the table fails on its null row with a SerializationException.
  • The Limit arm of shape_fault_first without Segment and TotalSegments: the table fails on its Segment: 1.5 row.
  • The scan module of f98573d on the merged base: cargo check fails with E0308 (it passes a HashMap<String, AttributeValue> where the function takes the raw map).
  • A server with four changes: the Scan arm of authorize_request removed, the pairing check off, the Segment text changed, and the mix ahead of ReturnConsumedCapacity. Seven wire tests fail, each for its own change: the authorization test, two test_segment_ranges rows, three test_return_consumed_capacity_beats_parameter_mix rows and the pairing row. The other 83 pass.

Gates

At c06130a, the head of this description:

  • cargo +1.97.0 fmt --all -- --check: clean.
  • The two clippy commands of .github/workflows/clippy.yml with -D warnings, on the whole workspace: no warnings.
  • cargo +1.97.0 clippy -p extenddb-engine -p extenddb-server --all-targets -- -W clippy::pedantic: no warning on a line this PR adds.
  • cargo +1.97.0 test --lib -p extenddb-engine -p extenddb-server: the engine gives 989 passed. The server gives 521 passed and 5 failed. The five are the backup_store tests that fail on this host only, as the block of 6f722f7 says.
  • cargo +1.97.0 test -p extenddb-wasm-adapter: 3 passed, and the parity corpus test passed.
  • cargo +1.97.0 test -p extenddb-storage-postgres --test doc_version_literals: 3 passed.
  • The two Scan wire files and tests/test_query_leading_keys_values.py hold 92 tests. Against a SQLite and a PostgreSQL server built from c06130a, 92 passed on each.
  • fix(storage-sqlite): keep each partition key in one parallel Scan segment #1087 changes the SQLite Scan. Its Scan wire files tests/test_scan_segments.py and tests/test_read_paging.py, with tests/test_query_scan.py, tests/python/test_query_scan.py and tests/python/test_scan_edge_cases.py, passed 220 tests on each of the two servers.
  • python3 -m pytest --collect-only -q collects 7431 tests in tests/ and 820 in tests/python with no error.

At 4c08c09:

  • cargo +1.97.0 fmt --all -- --check: clean.
  • The two clippy commands of .github/workflows/clippy.yml with -D warnings, on the whole workspace: no warnings.
  • cargo +1.97.0 clippy -p extenddb-engine -p extenddb-server --all-targets -- -W clippy::pedantic: no warning on a line this PR adds.
  • cargo +1.94.0 check -p extenddb-engine -p extenddb-server --all-targets: no warnings. 1.94.0 is the rust-version of main.
  • cargo +1.97.0 test --lib -p extenddb-engine -p extenddb-server: the engine gives 989 passed. The server gives 521 passed and 5 failed. The five are the backup_store tests that fail on this host only, as the next block says.
  • cargo +1.97.0 test -p extenddb-wasm-adapter: 3 passed, and the parity corpus test passed. The clippy step of .github/workflows/wasm.yml is clean.
  • cargo +1.97.0 test -p extenddb-storage-postgres --test doc_version_literals: 3 passed.
  • The two Scan wire files and the three Query wire files of fix(query): check Query values against the key schema and the number rules #544 hold 419 tests. Against a SQLite and a PostgreSQL server built from 4c08c09, 419 passed on each.
  • python3 -m pytest --collect-only -q collects 7394 tests in tests/ and 820 in tests/python with no error.

At 6f722f7:

  • cargo +1.97.0 fmt --all -- --check: clean.
  • cargo +1.97.0 clippy -p extenddb-engine -p extenddb-server --all-targets -- -D warnings, with and without --features extenddb-engine/backup-test-hooks: no warnings.
  • cargo +1.97.0 clippy ... -W clippy::pedantic: no warning on a line this PR changes.
  • cargo +1.91.1 check -p extenddb-engine -p extenddb-server --all-targets: no warnings.
  • cargo +1.97.0 test -p extenddb-server: 513 passed. Five backup_store tests fail on this host only, because /local/home belongs to uid 65534 and the spool checks refuse a directory under it. This PR does not change that file.
  • The two Scan wire files and the three Query wire files of fix(query): check Query values against the key schema and the number rules #544 against a SQLite server built from 6f722f7: 401 passed.

At ad5f485, the merge of #544's third round:

  • cargo +1.97.0 fmt --all -- --check: clean.
  • cargo +1.97.0 clippy -p extenddb-core -p extenddb-engine -p extenddb-server --all-targets -- -D warnings, and -p extenddb-engine with --features extenddb-engine/backup-test-hooks: no warnings.
  • cargo +1.91.1 check -p extenddb-core -p extenddb-engine -p extenddb-server --all-targets: no warnings.
  • cargo +1.97.0 test -p extenddb-engine --lib: 922 passed.
  • The same five wire files against a SQLite server built from ad5f485: 419 passed, the 401 above and the 18 rows fix(query): check Query values against the key schema and the number rules #544's third round adds.
  • python3 -m pytest --collect-only -q collects tests/ (7010) and tests/python (672) with no error.

The production code adds 267 lines and removes 102, and the tests add 1,238 lines and remove 7. The upgrade manual entry adds 19 lines.

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. There is no wire, Storage trait, auth model or on-disk change.

Breaking changes

A client sees the service's answers for some Scan requests that ExtendDB answered another way:

  • A Scan with an N value in ExpressionAttributeValues that is not a number gets a 400 ValidationException. A filter a = :n with {"N": "bob"} got 200 with Count: 0, and ResourceNotFoundException on a table that does not exist.
  • A Scan with Limit 0 gets 1 validation error detected: Value at 'Limit' failed to satisfy constraint: Member must have value greater than or equal to 1, the text of Query. It got Value '0' at 'limit' in that text, and ResourceNotFoundException on a table that does not exist.
  • A Scan that fails one of the checks above, from a principal that may not Scan the table, gets its ValidationException, where it got AccessDeniedException.
  • A Scan with more than one fault can get another ValidationException than before, in the order above.

The v1.2.0 entry of docs/manuals/07-upgrade-manual.md lists these changes.


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.

…rules

A Query with a KeyConditionExpression did not check a key condition value's
type against the key attribute's AttributeDefinitions type, and did not check
that an N value in ExpressionAttributeValues is a number. The storage layer
compared the value's inner text with the stored key and ignored the type tag,
so {"N": "bob"} on an S partition key read the bob partition while
authorization bound no dynamodb:LeadingKeys value to it, and a sort key value
of another type answered InternalServerError on SQLite.

Add the two checks the service applies before it reads a row, on the
expression path (crates/engine/src/query_key_values.rs):

- an N value in ExpressionAttributeValues that is not a number answers
  "The parameter cannot be converted to a numeric value: <value>" (the
  overflow and 38-digit texts for those cases; an empty value answers the
  message with the colon). The check covers the whole map, including NS
  members and values nested in L and M, whether the key condition, the
  filter or nothing reads them, with the walk PutItem and UpdateItem already
  use. It runs at request time after the Limit and expression parameter mix
  checks and before the table lookup, which moves those two checks ahead of
  the table lookup as well. The server runs the same request-time checks
  ahead of the IAM decision, so a principal under any LeadingKeys fence form
  gets ValidationException and no items;
- a key condition value whose type is not the key attribute's type answers
  "One or more parameter values were invalid: Condition parameter type does
  not match schema type", for the partition key, the sort key under every
  comparison operator, both BETWEEN bounds, the begins_with prefix and
  multi-attribute index keys, after the key schema, filter, projection,
  unused value and Select checks and before the ExclusiveStartKey check. When
  a compared placeholder is undefined the check returns without a verdict and
  the undefined placeholder is reported.

Measured on the service on 2026-10-24 (113 requests, each sent twice). The
legacy KeyConditions path is unchanged; its checks land with #507. Scan is
unchanged. Unit tests at the checks and a dual-target wire test file,
tests/test_query_key_value_types.py, which fails on main.
… service's order

The server ran its pre-IAM checks only when the body deserialized as
QueryInput, and the engine checked the ReturnConsumedCapacity and Select
enums before them, so a Query carrying an invalid Select and an N value
that is not a number answered the Select message, or AccessDeniedException
for a principal whose LeadingKeys fence needs a value. The checks now read
the raw body in the service's order, measured 2026-10-24: Limit, the
expression and non-expression parameter mix, ReturnConsumedCapacity, every
number in ExpressionAttributeValues, then Select. The engine and the server
run the same function.
…ort a shape fault ahead of the request-time checks

The request-time number check refused an N value written with a Unicode
decimal digit (fullwidth, Arabic-Indic, Devanagari) that the service accepts
as the digit it stands for, so a Query that returns rows on the service
answered ValidationException here. The check now folds every general
category Nd digit to ASCII before the number rules run and echoes the value
as the request wrote it when the rules refuse it; the Nd zero code points of
Unicode 15.0 live in a module of their own. The fold applies to the check
only: the handler and the server's key binding read the value as written.
The write paths are unchanged.

The checks run on the raw body before deserialization, so a field of the
wrong JSON type elsewhere in the body (a string ExpressionAttributeValues
beside a Limit of 0, a string ExpressionAttributeNames beside a malformed N,
a numeric Select) answered the check's ValidationException where the service
and the previous release answered SerializationException. When a check fails,
the body is now deserialized as the typed input and a SerializationException
from that is returned instead; a ValidationException the deserializer raises
does not preempt the check, and a body that passes every check is not
deserialized twice. The server's call before dispatch goes through the same
function.

Measured against the service on 2026-10-25 (11:31 UTC) on tables with S/N
and S/S keys, each request twice. Unit tests cover the digit table, the
folded check and the shape-fault order; the wire file gains the measured
rows for both.
…ks, and assert only acceptance for Unicode digits

The shape-fault pass returned the deserializer's SerializationException for an
AttributeValue with an unknown type descriptor, so Limit 0 beside {"X": "1"}
changed class. The service answers the Limit ValidationException for that
body (measured 2026-10-25), and the check's answer is returned again.

The Unicode digit tests asserted that a key condition or filter written with
a Unicode digit reads the item stored with the ASCII digit. This change makes
the request-time check accept such a value; it does not change how the
handler reads it, so the tests assert only that the value is accepted. A new
test checks that a partition key value written with Unicode digits returns no
item of a partition a ForAllValues LeadingKeys fence keeps the caller from.
…time

Scan did not check that the N values in ExpressionAttributeValues are
numbers, so a filter on {"N": "bob"}, a nested one in an L, M or NS, an
overflow, an underflow, a 39 digit value or an empty N answered 200 with
Count 0. The service refuses each with the same ValidationException text
Query uses, whether or not an expression reads the value.

Move the early Scan checks to a request-time function on the raw body,
in the order measured on 2026-10-25: the Limit, Segment and TotalSegments
ranges (one aggregated message, "Value at 'Limit'" with no value echoed),
the expression and non-expression parameter mix, the ReturnConsumedCapacity
enum, every number in ExpressionAttributeValues, then the Select enum.
Both enums invalid now answers the ReturnConsumedCapacity error alone, as
the service does; the earlier aggregation of the two no longer matched it.
The Segment pairing checks stay in the handler after the table lookup.

The two Scan tests that asserted the old segment range text now assert the
measured text.
…tion

Every N value shape the service refuses on Scan (a word, a nested L, M or
NS member, overflow, underflow, 39 digits, empty, a leading space), read by
the filter or by nothing, and the order against every other early check:
the Limit, Segment and TotalSegments ranges, the parameter mix and the
ReturnConsumedCapacity enum ahead of it; the Select enum, the Segment
pairing, the table lookup, IndexName, ConsistentRead, Select with
ProjectionExpression, ExclusiveStartKey, undefined placeholder and filter
syntax checks behind it. Expected texts measured on 2026-10-25.
… accept Unicode decimal digits

The range checks on Limit, Segment and TotalSegments reported every fault in
one aggregated message with a capitalised field name and no value for all
three fields. The service uses that form for a Limit inside the int32 range
and saturates the value into the older form below it (Limit -2147483649
answers Value '-2147483648' at 'limit'); the Segment and TotalSegments texts
and the aggregation are a separate question. The checks now report the first
fault in the order Limit, Segment, TotalSegments; Limit follows the measured
int32 rule and the two segment fields keep the texts of the previous release.
The two assertions in tests/test_query_scan.py go back to the previous text.

A field of the wrong JSON type in another field (a string
ExpressionAttributeValues beside Limit 0, a string TotalSegments beside
Segment -1, a string ExpressionAttributeNames beside a malformed N, an object
AttributesToGet beside ProjectionExpression) answered the check's
ValidationException where the service and the previous release answer
SerializationException. When a check fails the body is deserialized as the
typed input and a SerializationException from that is returned instead, with
the helper the Query path uses.

A Unicode decimal digit in an N value passes the request-time check shared
with Query, as it does on the service. The filter compares the value as the
request wrote it, as on the previous release.

The unit test for the parameter mix no longer asserts that an empty
ScanFilter beside a FilterExpression passes, which the service refuses as a
parameter mix; the engine's handling of an empty ScanFilter and an empty
AttributesToGet is unchanged and covered by a separate issue.

Measured against the service on 2026-10-25 (10:38, 10:55 and 11:31 UTC),
each request twice.
Conflict in crates/server/src/request_helpers.rs (authorize_request): main
moves the ARN shape checks and the GetRecords iterator decode ahead of the
dev-mode return. The resolution keeps the main version and puts the Query
request checks of this branch after the tag ARN shape check and before
validate_operation_arns. Thus the Query checks also run in dev mode.
Main changes resolve_multipart to take the HASH and the RANGE attribute
names (#429). The multi-attribute HASH test now gives r as the RANGE
attribute, as its attribute definitions do.
…l as the service does

On a single-attribute key schema, the later check of this branch now reports a
wrong type in a key condition expression, as the service does. The early check
from main still runs there for legacy KeyConditions, which the later check
skips. The begins_with refusal now reads the type of the value instead of the
type of the sort key.
…rder comments

Two new rows send begins_with with an N value on an attribute that is not in
the key schema. One row uses a table with an S sort key and the other uses a
table with an N sort key. The service refuses both requests with the
begins_with operand type message.

The comments in handle_query now say that the classifier checks the values of
legacy KeyConditions. They also say which attribute definitions it uses for
each kind of key schema. The doc of resolve_key_schema_with now says where the
service reports a wrong type on a single-attribute key schema (measured
2026-11-06).
When a request-time check fails, shape_fault_first deserializes each
member on its own. It reports a member of the wrong JSON type ahead of
the check, as the service does. It counted two nulls as such a member.
ScanIndexForward: null beside Select: "NOPE" answered
SerializationException here, where the service and main answer the
Select text. ExpressionAttributeNames: {"#a": null} beside an invalid
Select or ReturnConsumedCapacity did the same.

The service reads a null member as an absent one and a null name as an
empty name, which it reports after these checks. shape_fault_first now
skips a null member, with the rule present() already applies to the
parameter mix, and reads ExpressionAttributeNames without its null
names. The handler's deserializer still refuses both nulls.

I measured the service answers on 2026-11-24, each body twice. On
d7e6ff3, the 3 new unit rows fail, and the 3 new rows in
tests/test_query_value_shapes.py fail.
For an ExpressionAttributeValues value with two type descriptors,
first_fault reads each payload and names the first fault ahead of the
more than one datatypes text. It read the numbers only. The service
also refuses an empty set and a set with a duplicate member there.
{"SS": ["a", "a"], "N": "1"} answered the more than one datatypes text
here, where the service answers "Input collection [a, a] contains
duplicates." for :z, and {"NS": ["1", "1"], "S": "x"} answers "Input
collection contains duplicates".

first_fault now takes these set faults too, on this path only. It reads
SS ahead of the numbers, so {"SS": ["a", "a"], "N": "bob"} answers the
duplicate text. It reads NS after its own numbers, so {"NS": ["1", "1"],
"N": "bob"} answers the numeric text. The SS and BS texts come from the
AttributeValue deserializer. The NS text and its check move from core's
partiql module to validation::number, so a build without the partiql
feature has them. The deserializer still reports a set with a duplicate
member and no second descriptor, as before.

I measured the service answers on 2026-11-24, each body twice. On
0e0f078, 12 of the 15 new unit rows fail, and 12 of the 15 new rows
in tests/test_query_value_shapes.py fail. The 3 rows that answer the
numeric text pass there and pin what does not change.
Brings in 0e0f078, 35910e9 and the merge of main at 44cd436.

One conflict, in crates/engine/src/query_key_values.rs, in the shape
fault walk. This branch widens the number arm to Limit, Segment and
TotalSegments where the other branch adds the ExpressionAttributeNames
arm. The merge keeps both arms.
Main is at 14ade59. This branch last had main at 018715e, through
fix/query-key-value-types. Since then, these eleven commits merged
into main: #1280, #1009, #596, #1173, #398, #428, #544, #567, #584,
#588 and #864.

#544 is the squash of fix/query-key-value-types, which was the base
branch of this PR. This branch already holds the last head of that
branch, 31c5f3d. Main has the same version of each conflicted file as
31c5f3d. So each conflict hunk has the lines of #544 on one side.
The other side has the change of this branch to the same lines. The
merge keeps the version of this branch in each file:

- crates/engine/src/query_key_values.rs: this branch makes two
  constants and four functions pub(crate) for the Scan checks, and
  re-exports three functions of unreadable.rs. It reads a number in
  Segment and TotalSegments as it reads one in Limit, with the dates
  in the doc comment of shape_fault_first. It passes
  validate_no_parameter_mix to unreadable_value_checks.
- crates/engine/src/query_key_values/unreadable.rs: this branch makes
  three functions pub(crate). unreadable_value_checks takes the
  parameter mix check as a parameter, so this branch deletes the
  import of validate_no_parameter_mix.
- crates/server/src/request_helpers.rs: this branch runs the Scan
  request checks before the IAM decision, as main does for Query.
- tests/test_query_leading_keys_values.py: this branch moves the setup
  of TestLeadingKeysWithAnInvalidKeyValue to the base class
  ManagementPrincipals, which
  tests/test_scan_checks_before_authorization.py imports.

Git merged crates/engine/src/lib.rs with no conflict. Main compiles
three modules only off wasm32 (backup, import_export_io and
private_fs), and adds the modules backup_requests and pre_dispatch.
This branch adds the module scan_request and changes the doc comment
of validate_enum_fields.

@LJMart11 LJMart11 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Reviewed at 009c4c1. Engine (986) and server (526) lib tests passed at this head, and removing each request-time Scan check in scan_request.rs fails at least one unit test. The open item is upgrade documentation for the client-visible Scan changes.

Docs — outside the diff

  1. docs/manuals/07-upgrade-manual.md:385 — Please add a Behavior Changes by Release entry in docs/manuals/07-upgrade-manual.md for the two breaking changes the PR body lists. A Scan with a non-numeric N in ExpressionAttributeValues now gets 400 where it got 200 with Count: 0, and a malformed Scan from a principal denied Scan now gets ValidationException where it got AccessDeniedException. Main's SearchVectors entry at line 423, from #1449 in this merge, records the same pre-IAM change for that operation. A matching Scan entry under line 385 would close this.

Main is at c057660, 20 commits after 5026c89, the main commit of
the last merge (009c4c1). No file conflicted.

Two files that this branch changes also change on main. Git merged both
with no overlap:

- crates/engine/src/lib.rs: #481 adds the query_key_size_tests module
  next to the scan_request module of this branch.
- crates/server/src/request_helpers.rs: #1290 changes how
  extract_operation builds the MissingAuthenticationToken error. This
  branch changes authorize_request.
The breaking changes of this branch had no entry in the upgrade manual.
The new v1.2.0 entry comes after the three v1.2.0 entries of main. It
lists:

- the number check on the values of ExpressionAttributeValues, with the
  1.1.0 answers that it replaces
- the order of the checks before the table lookup, and the Limit text
- the checks before the IAM decision, which answer ValidationException
  where 1.1.0 answered AccessDeniedException
@LeeroyHannigan

Copy link
Copy Markdown
Collaborator Author

@LJMart11

  1. 4c08c09 adds the entry "v1.2.0: Scan checks its values against the number rules, before the table lookup and the IAM decision" to docs/manuals/07-upgrade-manual.md, at line 419. 4811268 merges main first, so the entry comes after main's three v1.2.0 entries.

    The entry covers both changes. A non-numeric N in ExpressionAttributeValues gets 400 ValidationException, where 1.1.0 answered 200 with Count: 0 for a = :n. A Scan that fails one of the request checks gets that ValidationException ahead of the IAM decision. In 1.1.0 a caller that may not Scan the table got AccessDeniedException. The entry also gives the order of the checks and the new Limit text, each with the 1.1.0 answer that it replaces.

@LJMart11 LJMart11 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Checked at 4c08c09 against the list from 009c4c1.

The follow-up adds the v1.2.0 Scan entry to the upgrade manual and merges main. The entry sits under Behavior Changes by Release and covers the number check, the new check order, the Limit text and the checks before the IAM decision. The Scan wire tests (test_scan_number_values.py, test_scan_checks_before_authorization.py) passed 90 of 90 against a SQLite build of the head, and the engine lib tests passed 989 under Rust 1.94.0.

Previous items: 1 fixed.

Main is at 5826e1b, three commits past c057660: #1531, #1466 and
#1087. In docs/manuals/07-upgrade-manual.md, #1531 adds a v1.2.0 entry
at the top of "Behavior Changes by Release", and git merged it with no
conflict. #1087 adds its v1.2.0 entry after the other v1.2.0 entries of
main, where this branch has its entry. That is the one conflict. The
merge keeps both entries without change: the entry of #1087 first, then
the entry of this branch, before the v1.1.0 entries.

No other file has changes on both sides. #1087 changes how SQLite puts
items in parallel Scan segments. This branch changes the Scan request
checks in crates/engine, and #1087 changes no file in that crate.
@LJMart11

LJMart11 commented Dec 4, 2026

Copy link
Copy Markdown

Checked at 4c08c09 against the list from 009c4c1. The head moved again to c06130a; this reviewer stops after two rounds and leaves the rest to a person.

Fixed:

  • item 1

Disputed: none.

Needs-human: none.

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

v1 Needed for the 1.0 release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Scan does not check that ExpressionAttributeValues numbers are numbers

3 participants