Skip to content

fix(server): check the table name length of a table ARN - #1282

Open
LeeroyHannigan wants to merge 1 commit into
mainfrom
fix/1221-arn-table-name-length
Open

LeeroyHannigan wants to merge 1 commit into
mainfrom
fix/1221-arn-table-name-length

Conversation

@LeeroyHannigan

Copy link
Copy Markdown
Collaborator

What

A table ARN whose table name is shorter than 3 or longer than 255 now gets DynamoDB's length text. This covers a TableName, a transaction member and a RequestItems key. The texts are Table name of ARN must have length greater than or equal to 3 (MIN) and Table name of ARN must have length less than or equal to 255 (MAX), at the member's path.

Before this change, the empty name of table/ got the Valid ARN format is ... text, because arn::parse reads no empty name. A name of 1, 2 or more than 255 characters got a bare-name text, ResourceNotFoundException, TableNotFoundException or the pattern text. The answer depended on the operation.

The check is in table_arn_fault in crates/server/src/arn_gate.rs. It comes after the vendor and region checks and before the pattern check. On the item operations it also comes before the account check. The control-plane operations still answer an ARN of another account first. Each text has one copy, in arn_constraint.

DynamoDB counts the name in two units:

  • CreateTable, DescribeTable, UpdateTable, DeleteTable, DescribeTimeToLive, UpdateTimeToLive, DescribeContinuousBackups, UpdateContinuousBackups, CreateBackup and ListBackups count UTF-16 code units.
  • The item operations and the transaction members count UTF-8 bytes.

No helper in crates/ counts either unit, so the check uses encode_utf16().count() and str::len.

A RequestItems key of BatchGetItem or BatchWriteItem takes the same check, with the map-key constraint list at requestItems. DynamoDB answers these keys with that list.

Fixes #1221

Why

These are DynamoDB's answers, measured in us-east-1 on 20 and 21 November 2026. Each request went out twice and got the same answer both times. Each ARN is a table ARN of the caller's account in us-east-1, with the table name of the first column. PAT is Table name of ARN must satisfy regular expression pattern: [a-zA-Z0-9_.-]+. Every answer is a ValidationException at tableName unless the cell names another type.

Table name of the ARN DescribeTable GetItem ExtendDB before, DescribeTable and GetItem
empty MIN MIN the Valid ARN format is ... text on both
a or ab MIN MIN the bare-name pattern text, and ResourceNotFoundException
256 times x MAX MAX the bare-name Member must have length less than or equal to 255, and ResourceNotFoundException
a* MIN MIN PAT on both
one U+1F600, 2 code units and 4 bytes MIN PAT PAT on both
85 times U+1F600, 170 code units and 340 bytes PAT MAX PAT on both
128 times U+1F600, 256 code units MAX MAX PAT on both
a b PAT PAT PAT on both

The same measurement has these rows too:

  • CreateBackup, ListBackups, DescribeContinuousBackups and UpdateTimeToLive answer as DescribeTable. PutItem, DeleteItem, UpdateItem, Query, Scan and the transaction members answer as GetItem, at the member's path.
  • An empty name in an ARN of the account 12345 gets MIN on GetItem. On DescribeTable it gets AccessDeniedException, Access is denied, as before. An empty name with an upper case region or the vendor s3 gets DynamoDB's region or vendor text, where ExtendDB gave the Valid ARN format is ... text.
  • As a RequestItems key, a table ARN with the name a, ab or 256 times x gets the map-key constraint list at requestItems. Before this change, ExtendDB sent such a key to the handler, and the request got ResourceNotFoundException. With the name ab, a key of another account got AccessDeniedException in both operations, and a key of a malformed account got it in BatchWriteItem. DynamoDB answers the list.

With this change, ExtendDB gives 78 of the 80 measured rows DynamoDB's exception type and constraint text. The base gives 31 of them.

Testing done

  • cargo test -p extenddb-server --lib: 514 passed. On this host 5 backup_store::tests fail on every branch, because uid 65534 owns /local/home. The unit tests of arn_gate.rs and table_name_gate.rs pass.
  • cargo +1.97.0 clippy -p extenddb-server --all-targets -- -D warnings and cargo +1.97.0 fmt --all -- --check are clean.
  • Against ExtendDB on SQLite, tests/python/test_nul_arn_shapes.py passed 54 tests. Its tables hold the new length rows for DescribeTable, GetItem and TransactGetItems.
  • The 80 measured rows went to a SQLite server built from this commit and got the answers stated here. Every answer was HTTP 400.

Line counts: production +40 -14, tests +109 -13.

This PR adds no conflict with the open PRs.

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


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 table ARN in TableName with an empty table name got the Valid ARN
format text, since arn::parse reads no empty name. A table name of 1, 2
or over 255 characters passed the gate or got the pattern text.

For an empty or short name, DynamoDB answers at 'tableName' with
"Table name of ARN must have length greater than or equal to 3".
For a long name it answers
"Table name of ARN must have length less than or equal to 255".

The gate checks the length after the vendor and the region and before
the pattern. On the item operations it also comes before the account
check. The control-plane operations still answer an ARN of another
account first. They count the table name in UTF-16 code units. The
item operations and the transaction members count it in UTF-8 bytes.
A RequestItems key that is a table ARN takes the same check, with its
map-key constraint list.

Measured against DynamoDB in us-east-1 on 2026-11-20 and 2026-11-21.

Fixes #1221.

@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 table ARN's name length is checked at 5bef195, and a name of ab or 256 characters inside an ARN now gets the service's Table name of ARN must have length ... text. With 1,560 rows sent twice to us-east-1 and twice each to this head and main on SQLite and PostgreSQL, the two live rounds and the two backends agree on every row; this head matches the service on 1,054 rows and main on 758, and of the 553 rows it changes, 328 now match, 193 still differ and 32 that main answered as the service does no longer do (below). Byte and character counting match the service for every multibyte and emoji name (UTF-8 bytes on item operations and transaction members, UTF-16 units on the control plane), and index, stream and backup ARNs, the s3 vendor, upper-case regions and PartiQL match too. Ten of eleven controls fail as they should, the 6 new Python rows fail on main and pass here and live, fmt, both clippy sets, 519 server tests and the 1.91.1 check are clean, and CI is green on 58 of 58. It merges onto main at 222d80a without conflict, builds and passes the 1.94.0 check there, and answers all 1,560 rows as this head; with #1127 it merges cleanly, and 47 of #1127's rows move toward the service with none away. No merged PR fixes #1221.

I will approve once the four shapes below answer as the service and main do, and the RequestItems key length path has a test.

return Some(ArnFault::Region);
}
if !in_pattern(&res.table) {
let length = if control_plane {

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 length check now runs ahead of faults the service reports first. With an empty account (arn:aws:dynamodb:us-east-1::table/ab), the service and main give Invalid subscriber ID and this head the length text (10 rows regress, 15 more differ); an account that is present but wrong (12345, 13 digits) does come after the length, as the body says. For CreateBackup with a us-west-2 ARN and ab or 256 characters, the service and main give Invalid AWS region in '<arn>' (backup.rs:398) and this head the length text; 23 more rows on other operations differ for the same reason, which is older and filed as #794.

let table = match parse(arn) {
Some(res) if res.sub.is_none() => res.table,
// `parse` reads no empty table segment.
None if f.resource == "table/" => String::new(),

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 an empty partition or an empty region and an empty name, the service and main give the Valid ARN format is ... text and this head the length text (13 rows regress), and the same shapes with ab or 256 characters differ on 36 more. The order in the module doc at lines 7-10 and at line 412 would change with this.

}
if key.starts_with("arn:") {
let refused = match arn_gate::table_arn_fault(key) {
let refused = match arn_gate::table_arn_fault(key, false) {

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.

For a BatchWriteItem key that is an ARN of another or a malformed account with a bad-length name, the service and main answer AccessDeniedException (5 of 5 sends), and this head the map-key list (8 rows). The body's claim that the service answers the list here holds for BatchGetItem only. Passing bad-length ARN keys through to the handler leaves all 22 gate tests passing, and the Python file has no batch row, so a test here would hold the path.

};
match length {
..3 => return Some(ArnFault::ShortTable),
256.. => return Some(ArnFault::LongTable),

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.

For a whole ARN over 1,024 characters, the service answers Value at 'TableName' failed to satisfy constraint: Member must have length less than or equal to 1024 and this head the 255 text (50 rows); at exactly 1,024 this head is right. One check of the whole value's length would also cover the same case for plain names that our review of #1127 raises.

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.

A table ARN with an empty name part gets the Valid ARN format text, where DynamoDB answers that the table name of the ARN is shorter than 3 characters

2 participants