Repository navigation
fix(engine): refuse a table name of a bad length before the lookup #1127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
LeeroyHannigan
wants to merge
11
commits into
main
Choose a base branch
from
fix/1056-table-name-length
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,389
−107
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
8f8ecca
fix(engine): refuse a table name of a bad length before the lookup
LeeroyHannigan ef3b925
Merge origin/main into fix/1056-table-name-length
LeeroyHannigan a88fa4a
refactor(core): one table_name_bounds for the deployment's name bounds
LeeroyHannigan 3592be9
refactor(engine): delete the unreachable TableName arm of PutItem
LeeroyHannigan a883891
docs: say where the TransactWriteItems name list ends
LeeroyHannigan 1dbbe5b
Merge origin/main into fix/1056-table-name-length
LeeroyHannigan aedd59a
fix(engine): answer a table name over 1024 characters with the member…
LeeroyHannigan 0806912
fix(engine): check the table names ahead of the other request checks
LeeroyHannigan 16de95b
docs: add the v1.2.0 upgrade entry of the table name checks
LeeroyHannigan af26a1f
Merge origin/main into fix/1056-table-name-length
LeeroyHannigan 059c6ca
Merge origin/main into fix/1056-table-name-length
LeeroyHannigan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,280 @@ | ||
| // Copyright 2026 ExtendDB contributors | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| //! A table name of a bad length, in the operations that look a table up by | ||
| //! it. These checks take the deployment's `[limits]` bounds, 3 to 255 | ||
| //! characters by default, as [`validate_table_name`] does. | ||
| //! | ||
| //! The service refuses such a name with `ValidationException` before the | ||
| //! lookup, and answers a member of the wrong JSON type ahead of it: `GetItem`, | ||
| //! `BatchGetItem`, `BatchWriteItem` and `TransactWriteItems` answered | ||
| //! `SerializationException` for a short name beside a member of the wrong | ||
| //! type (measured 2026-11-18). So the handlers run these checks after the | ||
| //! request is read and before the first lookup. A name outside the pattern is | ||
| //! refused earlier, before authorization, by the server's table name gate, | ||
| //! which writes its length clauses with [`length_clause`] and the service's | ||
| //! bounds. | ||
| //! | ||
| //! An empty name gets other sentences from the service, which these checks | ||
| //! leave to the code after them, except in `GetItem` and `PutItem`. | ||
| //! | ||
| //! Ahead of those bounds the service checks the bound of the `TableName` | ||
| //! member, which also takes a table ARN: 1024 characters at most. A name over | ||
| //! it gets that clause, with no value quoted, at the member as the request | ||
| //! names it: `TableName`, `RequestItems.<key>` in `BatchGetItem`, and | ||
| //! `TransactItems.<n>.member.<Op>.TableName` with `n` counted from 0. | ||
| //! `BatchWriteItem` gives the map-key sentence with the member's list. The | ||
| //! clause comes alone, ahead of a name of 2 characters, a name outside the | ||
| //! pattern and an ARN that the ARN rules refuse (measured 2026-12-03). These | ||
| //! checks give it to a name that does not start with `arn:`. A deployment | ||
| //! whose maximum is above 1024 can create longer names, so for it the bound | ||
| //! is that maximum. | ||
|
|
||
| use crate::error::{ | ||
| DynamoDbError, validation_error, validation_errors, validation_errors_detected, | ||
| }; | ||
| use crate::limits::LimitsConfig; | ||
| use crate::types::TransactWriteItem; | ||
|
|
||
| use super::validate_table_name; | ||
|
|
||
| /// The constraint list of a `RequestItems` key that is not a table name the | ||
| /// service accepts (measured 2026-10-24 for a key outside the pattern and | ||
| /// 2026-11-18 for a key of a bad length). | ||
| pub const MAP_KEYS_NAME: &str = "Map keys must satisfy constraint: \ | ||
| [Member must have length less than or equal to 255, \ | ||
| Member must have length greater than or equal to 3, \ | ||
| Member must satisfy regular expression pattern: [a-zA-Z0-9_.-]+]"; | ||
|
|
||
| /// The clause of a table name under the minimum length. It names the | ||
| /// service's minimum, 3, whatever the deployment's is, as the sentence of | ||
| /// [`validate_table_name`] does. | ||
| pub(crate) const TOO_SHORT: &str = "Member must have length greater than or equal to 3"; | ||
|
|
||
| /// The clause of a table name over the maximum length, which names the | ||
| /// service's maximum, 255, in the same way. | ||
| pub(crate) const TOO_LONG: &str = "Member must have length less than or equal to 255"; | ||
|
|
||
| /// The bound of the `TableName` member, in characters. | ||
| const MEMBER_MAX: usize = 1024; | ||
|
|
||
| /// The clauses of the `TableName` member's bounds. | ||
| const MEMBER_TOO_SHORT: &str = "Member must have length greater than or equal to 1"; | ||
| const MEMBER_TOO_LONG: &str = "Member must have length less than or equal to 1024"; | ||
|
|
||
| /// The constraint list of a `BatchWriteItem` `RequestItems` key over the | ||
| /// member's bound (measured 2026-12-03). | ||
| const MAP_KEYS_MEMBER: &str = "Map keys must satisfy constraint: \ | ||
| [Member must have length less than or equal to 1024, \ | ||
| Member must have length greater than or equal to 1]"; | ||
|
|
||
| /// The length clause a table name fails under the bounds `(min, max)`, in | ||
| /// characters, or `None` for a name within them. | ||
| #[must_use] | ||
| pub fn length_clause(name: &str, (min, max): (usize, usize)) -> Option<&'static str> { | ||
| match name.chars().count() { | ||
| n if n < min => Some(TOO_SHORT), | ||
| n if n > max => Some(TOO_LONG), | ||
| _ => None, | ||
| } | ||
| } | ||
|
|
||
| /// The deployment's table name bounds `(min, max)`: the `[limits]` values | ||
| /// `min_table_name_length` and `max_table_name_length`, 3 and 255 by default. | ||
| #[must_use] | ||
| pub fn table_name_bounds(limits: &LimitsConfig) -> (usize, usize) { | ||
| (limits.min_table_name_length, limits.max_table_name_length) | ||
| } | ||
|
|
||
| /// Where the service reports the table name of a `TransactItems` action: | ||
| /// `transactItems.<n>.member.<op>.tableName`, with `n` counted from 1 and the | ||
| /// action's member name (`ConditionCheck`) in lower camel case. | ||
| #[must_use] | ||
| pub fn transact_name_location(index: usize, member: &str) -> String { | ||
| let mut chars = member.chars(); | ||
| let op = match chars.next() { | ||
| Some(first) => first.to_ascii_lowercase().to_string() + chars.as_str(), | ||
| None => String::new(), | ||
| }; | ||
| format!("transactItems.{}.member.{op}.tableName", index + 1) | ||
| } | ||
|
|
||
| /// A name over the bound of the `TableName` member and over the | ||
| /// deployment's maximum `max`, so that a name the deployment can create is | ||
| /// never refused for it. A table ARN is left to the code after these checks. | ||
| fn over_member_bound(name: &str, max: usize) -> bool { | ||
| !name.starts_with("arn:") && name.chars().count() > MEMBER_MAX.max(max) | ||
| } | ||
|
|
||
| /// The service's message for members outside the `TableName` member's | ||
| /// bounds: one `Value at '<location>'` clause for each, with no value quoted. | ||
| fn member_error(clauses: impl IntoIterator<Item = (String, &'static str)>) -> DynamoDbError { | ||
| let clauses: Vec<String> = clauses | ||
| .into_iter() | ||
| .map(|(location, constraint)| { | ||
| format!("Value at '{location}' failed to satisfy constraint: {constraint}") | ||
| }) | ||
| .collect(); | ||
| DynamoDbError::ValidationException(validation_errors_detected(&clauses)) | ||
| } | ||
|
|
||
| /// The table name check `GetItem` and `PutItem` run before the lookup. The | ||
| /// service answers an empty name and a name over 1024 characters in both | ||
| /// with `Value at 'TableName'` and the member's bound (measured 2026-11-18 | ||
| /// and 2026-12-03). Any other name gets the answer of | ||
| /// [`validate_table_name`]. | ||
| /// | ||
| /// # Errors | ||
| /// | ||
| /// `ValidationException` for a name outside the member's bounds or one that | ||
| /// [`validate_table_name`] refuses. | ||
| pub fn validate_item_table_name(name: &str, limits: &LimitsConfig) -> Result<(), DynamoDbError> { | ||
| let constraint = if name.is_empty() { | ||
| MEMBER_TOO_SHORT | ||
| } else if over_member_bound(name, limits.max_table_name_length) { | ||
| MEMBER_TOO_LONG | ||
| } else { | ||
| return validate_table_name(name, limits); | ||
| }; | ||
| Err(member_error([("TableName".to_owned(), constraint)])) | ||
| } | ||
|
|
||
| /// A `RequestItems` key of a bad length in `operation`, `BatchGetItem` or | ||
| /// `BatchWriteItem`. A key over 1024 characters gets the member's bound (see | ||
| /// the module comment); any other gets the map-key sentence at | ||
| /// `requestItems`. Where the service quotes its rendering of the whole map in | ||
| /// `Value '...'`, this renders the key alone, as the server's table name gate | ||
| /// does for a key outside the pattern. An empty key and a table ARN are left | ||
| /// to the code after this. | ||
| /// | ||
| /// # Errors | ||
| /// | ||
| /// `ValidationException`. The keys come from a `HashMap`, whose order | ||
| /// changes from one request to the next, so they are taken in sorted order: | ||
| /// a sentence that quotes one key quotes the smallest, and `BatchGetItem` | ||
| /// lists the keys over 1024 characters sorted, where the service listed two | ||
| /// of them in either order. | ||
| pub fn validate_request_items_keys<'a>( | ||
| operation: &str, | ||
| keys: impl IntoIterator<Item = &'a String>, | ||
| limits: &LimitsConfig, | ||
| ) -> Result<(), DynamoDbError> { | ||
| let mut keys: Vec<&str> = keys | ||
| .into_iter() | ||
| .map(String::as_str) | ||
| .filter(|k| !k.is_empty() && !k.starts_with("arn:")) | ||
| .collect(); | ||
| keys.sort_unstable(); | ||
| let over: Vec<&str> = keys | ||
| .iter() | ||
| .copied() | ||
| .filter(|k| over_member_bound(k, limits.max_table_name_length)) | ||
| .collect(); | ||
| if let Some(key) = over.first() { | ||
| return Err(if operation == "BatchWriteItem" { | ||
| DynamoDbError::ValidationException(validation_error( | ||
| key, | ||
| "requestItems", | ||
| MAP_KEYS_MEMBER, | ||
| )) | ||
| } else { | ||
| member_error( | ||
| over.iter() | ||
| .map(|k| (format!("RequestItems.{k}"), MEMBER_TOO_LONG)), | ||
| ) | ||
| }); | ||
| } | ||
| let bounds = table_name_bounds(limits); | ||
| if let Some(key) = keys.iter().find(|k| length_clause(k, bounds).is_some()) { | ||
| return Err(DynamoDbError::ValidationException(validation_error( | ||
| key, | ||
| "requestItems", | ||
| MAP_KEYS_NAME, | ||
| ))); | ||
| } | ||
| Ok(()) | ||
| } | ||
|
|
||
| /// The `TransactItems` names over 1024 characters and over the deployment's | ||
| /// maximum `max`, each `(action index, member, name)` with the member as the | ||
| /// request writes it (`Put`), in the order given, at | ||
| /// `TransactItems.<n>.member.<Op>.TableName`. The service lists them alone, | ||
| /// ahead of every other name fault of the request (see the module comment). | ||
| /// | ||
| /// # Errors | ||
| /// | ||
| /// `ValidationException` listing each such name. | ||
| pub fn check_transact_member_bound<'a>( | ||
| names: impl IntoIterator<Item = (usize, &'a str, &'a str)>, | ||
| max: usize, | ||
| ) -> Result<(), DynamoDbError> { | ||
| let over: Vec<(String, &str)> = names | ||
| .into_iter() | ||
| .filter(|(_, _, name)| over_member_bound(name, max)) | ||
| .map(|(i, member, _)| { | ||
| ( | ||
| format!("TransactItems.{i}.member.{member}.TableName"), | ||
| MEMBER_TOO_LONG, | ||
| ) | ||
| }) | ||
| .collect(); | ||
| if over.is_empty() { | ||
| return Ok(()); | ||
| } | ||
| Err(member_error(over)) | ||
| } | ||
|
|
||
| /// The table names of a bad length in the actions of a `TransactWriteItems` | ||
| /// request: the names over 1024 characters (see | ||
| /// [`check_transact_member_bound`]), or else every action's fault of the | ||
| /// deployment's bounds in one message, in action order (measured | ||
| /// 2026-11-18). An empty name and a table ARN are left to the code after | ||
| /// this. | ||
| /// | ||
| /// # Errors | ||
| /// | ||
| /// `ValidationException` listing each such name. | ||
| pub fn validate_transact_write_names( | ||
| items: &[TransactWriteItem], | ||
| limits: &LimitsConfig, | ||
| ) -> Result<(), DynamoDbError> { | ||
| let mut names: Vec<(usize, &str, &str)> = Vec::new(); | ||
| for (i, item) in items.iter().enumerate() { | ||
| let members = [ | ||
| ( | ||
| "ConditionCheck", | ||
| item.condition_check.as_ref().map(|o| &o.table_name), | ||
| ), | ||
| ("Put", item.put.as_ref().map(|o| &o.table_name)), | ||
| ("Delete", item.delete.as_ref().map(|o| &o.table_name)), | ||
| ("Update", item.update.as_ref().map(|o| &o.table_name)), | ||
| ]; | ||
| for (member, name) in members { | ||
| if let Some(name) = name.filter(|n| !n.is_empty() && !n.starts_with("arn:")) { | ||
| names.push((i, member, name)); | ||
| } | ||
| } | ||
| } | ||
| check_transact_member_bound(names.iter().copied(), limits.max_table_name_length)?; | ||
| let bounds = table_name_bounds(limits); | ||
| let located: Vec<(&str, String, &str)> = names | ||
| .iter() | ||
| .filter_map(|&(i, member, name)| { | ||
| Some(( | ||
| name, | ||
| transact_name_location(i, member), | ||
| length_clause(name, bounds)?, | ||
| )) | ||
| }) | ||
| .collect(); | ||
| if located.is_empty() { | ||
| return Ok(()); | ||
| } | ||
| let faults: Vec<(&str, &str, &str)> = located | ||
| .iter() | ||
| .map(|(name, location, clause)| (*name, location.as_str(), *clause)) | ||
| .collect(); | ||
| Err(DynamoDbError::ValidationException(validation_errors( | ||
| &faults, | ||
| ))) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For a name over 1024 characters, the service answers GetItem, BatchGetItem and TransactWriteItems with
Value at 'TableName' failed to satisfy constraint: Member must have length less than or equal to 1024and no value quoted (atRequestItems.<key>, orTransactItems.<n>.member.<Op>.TableName), and in a transaction that error alone, even beside anabname; this head gives the 255 clause. At exactly 1024 the service gives the 255 clause, as this head does.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in aedd59a. A name over 1024 characters now gets the clause of the member bound, with no value quoted, at the member as the request names it. I measured each row in us-east-1 on 3 Dec, and sent each request twice:
1 validation error detected: Value at 'TableName' failed to satisfy constraint: Member must have length less than or equal to 1024.Value at 'RequestItems.<key>', one clause for each such key. With two such keys the service listed them in either order on two sends, and ExtendDB lists them sorted.requestItemswith the list[Member must have length less than or equal to 1024, Member must have length greater than or equal to 1]. ExtendDB quotes the key alone (BatchGetItem and BatchWriteItem quote a refused RequestItems key alone, where DynamoDB quotes the whole RequestItems value #1118).Value at 'TransactItems.<n>.member.<Op>.TableName', withncounted from 0, one clause for each such name. It comes alone beside anabaction, abad nameaction and an ARN of the vendors3. The gate gives this answer when it refuses the request for one of the last two.At 1024 characters GetItem and TransactWriteItems keep the 255 clause. The checks are in
crates/core/src/validation/table_name_length.rs, and the rows are intable_name_length_tests.rs, the gate test andTestTableNameLengths. A deployment whosemax_table_name_lengthis above 1024 takes that maximum as the bound, so it can still use the names it creates.