From 8f8eccac54f586b93995b62e731f6aa1f80e2e05 Mon Sep 17 00:00:00 2001 From: Lee Hannigan <29015211+LeeroyHannigan@users.noreply.github.com> Date: Wed, 18 Nov 2026 05:58:39 +0000 Subject: [PATCH 1/7] fix(engine): refuse a table name of a bad length before the lookup GetItem, BatchGetItem, BatchWriteItem and TransactWriteItems looked up a table name shorter than 3 or longer than 255 characters. They answered ResourceNotFoundException for it. DynamoDB refuses such a name with ValidationException before the lookup. It answers a member of the wrong JSON type ahead of the length. So the handlers now check the length after the request is read. They take the bounds from the deployment's limits, as CreateTable does. In TransactWriteItems, DynamoDB lists the name faults of every action in one message. Beside a name outside the pattern, the server lists the other actions' names of a bad length too. GetItem and PutItem answer an empty name with the text DynamoDB gives. DescribeTable answers an empty name with the length and pattern faults, as DynamoDB does. Measured in us-east-1 on 13, 14 and 18 Nov 2026. Fixes #1056. --- crates/core/src/error/messages.rs | 15 +- crates/core/src/validation/mod.rs | 2 + .../core/src/validation/table_name_length.rs | 160 +++++++++++++++ crates/engine/src/batch_get_item.rs | 5 + crates/engine/src/batch_write_item.rs | 5 + crates/engine/src/get_item.rs | 12 ++ crates/engine/src/partiql/mod.rs | 2 +- crates/engine/src/partiql/test_context.rs | 4 +- crates/engine/src/put_item.rs | 7 +- crates/engine/src/table_name_length_tests.rs | 180 +++++++++++++++++ crates/engine/src/transact_write_items.rs | 5 + crates/server/src/table_name_gate.rs | 190 +++++++++++++----- tests/python/test_nul_table_names.py | 180 ++++++++++++++++- 13 files changed, 702 insertions(+), 65 deletions(-) create mode 100644 crates/core/src/validation/table_name_length.rs create mode 100644 crates/engine/src/table_name_length_tests.rs diff --git a/crates/core/src/error/messages.rs b/crates/core/src/error/messages.rs index 18d3e521d..874713b62 100755 --- a/crates/core/src/error/messages.rs +++ b/crates/core/src/error/messages.rs @@ -4,6 +4,8 @@ //! Error message templates captured from real `DynamoDB`. //! These are the exact messages `DynamoDB` returns — tenet 4 (errors are contracts). +use crate::validation::table_name_length::{TOO_LONG, TOO_SHORT}; + /// Format a single validation constraint error in `DynamoDB`'s exact format. #[must_use] pub fn validation_error(value: &str, field: &str, constraint: &str) -> String { @@ -36,6 +38,8 @@ pub enum ErrorMessageKey { TableNameTooLong, TableNameNull, TableNameEmpty, + /// An empty name in `GetItem` and `PutItem` (measured 2026-11-18). + ItemTableNameEmpty, TableNameInvalidChars, TableNotFound, TableAlreadyExists, @@ -54,18 +58,17 @@ pub enum ErrorMessageKey { #[must_use] pub fn error_message(key: ErrorMessageKey, args: &[&str]) -> String { match key { - ErrorMessageKey::TableNameTooShort => { - format!("1 validation error detected: Value '{}' at 'tableName' failed to satisfy constraint: Member must have length greater than or equal to 3", args[0]) - } - ErrorMessageKey::TableNameTooLong => { - format!("1 validation error detected: Value '{}' at 'tableName' failed to satisfy constraint: Member must have length less than or equal to 255", args[0]) - } + ErrorMessageKey::TableNameTooShort => validation_error(args[0], "tableName", TOO_SHORT), + ErrorMessageKey::TableNameTooLong => validation_error(args[0], "tableName", TOO_LONG), ErrorMessageKey::TableNameNull => { "1 validation error detected: Value null at 'tableName' failed to satisfy constraint: Member must not be null".to_owned() } ErrorMessageKey::TableNameEmpty => { "1 validation error detected: Value '' at 'tableName' failed to satisfy constraint: Member must have length greater than or equal to 1".to_owned() } + ErrorMessageKey::ItemTableNameEmpty => { + "1 validation error detected: Value at 'TableName' failed to satisfy constraint: Member must have length greater than or equal to 1".to_owned() + } ErrorMessageKey::TableNameInvalidChars => { format!( "1 validation error detected: Value '{}' at 'tableName' failed to satisfy constraint: \ diff --git a/crates/core/src/validation/mod.rs b/crates/core/src/validation/mod.rs index 9c1bcbb21..e1153d19a 100755 --- a/crates/core/src/validation/mod.rs +++ b/crates/core/src/validation/mod.rs @@ -23,6 +23,8 @@ pub use warm_throughput::{ validate_warm_throughput_on_update, }; +pub mod table_name_length; + use crate::error::{DynamoDbError, ErrorMessageKey, error_message}; use crate::limits::LimitsConfig; use crate::types::{ diff --git a/crates/core/src/validation/table_name_length.rs b/crates/core/src/validation/table_name_length.rs new file mode 100644 index 000000000..23fbdcd1b --- /dev/null +++ b/crates/core/src/validation/table_name_length.rs @@ -0,0 +1,160 @@ +// 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`. + +use crate::error::{ + DynamoDbError, ErrorMessageKey, error_message, validation_error, validation_errors, +}; +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 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, + } +} + +/// Where the service reports the table name of a `TransactItems` action: +/// `transactItems..member..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) +} + +/// The table name check `GetItem` and `PutItem` run before the lookup. The +/// service answers an empty name in both with `Value at 'TableName'` and a +/// length of at least 1 (measured 2026-11-18). Any other name gets the answer +/// of [`validate_table_name`]. +/// +/// # Errors +/// +/// `ValidationException` for an empty name or one that +/// [`validate_table_name`] refuses. +pub fn validate_item_table_name(name: &str, limits: &LimitsConfig) -> Result<(), DynamoDbError> { + if name.is_empty() { + return Err(DynamoDbError::ValidationException(error_message( + ErrorMessageKey::ItemTableNameEmpty, + &[], + ))); + } + validate_table_name(name, limits) +} + +/// A `RequestItems` key of a bad length, refused with the service's sentence +/// at `requestItems`. The service quotes its rendering of the whole map in +/// `Value '...'`, and 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` for the smallest such key. The keys come from a +/// `HashMap`, whose order changes from one request to the next. +pub fn validate_request_items_keys<'a>( + keys: impl IntoIterator, + limits: &LimitsConfig, +) -> Result<(), DynamoDbError> { + let bounds = (limits.min_table_name_length, limits.max_table_name_length); + let refused = keys + .into_iter() + .filter(|k| !k.is_empty() && !k.starts_with("arn:") && length_clause(k, bounds).is_some()) + .min(); + if let Some(key) = refused { + return Err(DynamoDbError::ValidationException(validation_error( + key, + "requestItems", + MAP_KEYS_NAME, + ))); + } + Ok(()) +} + +/// The table names of a bad length in the actions of a `TransactWriteItems` +/// request. The service lists every action's fault 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<(&str, String)> = 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((name, transact_name_location(i, member))); + } + } + } + let bounds = (limits.min_table_name_length, limits.max_table_name_length); + let faults: Vec<(&str, &str, &str)> = names + .iter() + .filter_map(|(name, location)| { + Some((*name, location.as_str(), length_clause(name, bounds)?)) + }) + .collect(); + if faults.is_empty() { + return Ok(()); + } + Err(DynamoDbError::ValidationException(validation_errors( + &faults, + ))) +} diff --git a/crates/engine/src/batch_get_item.rs b/crates/engine/src/batch_get_item.rs index 263ce6c0b..9280c95fa 100755 --- a/crates/engine/src/batch_get_item.rs +++ b/crates/engine/src/batch_get_item.rs @@ -165,6 +165,11 @@ pub async fn handle_batch_get_item( extenddb_core::validation::number::operations::batch_get_keys(keys)?; } + extenddb_core::validation::table_name_length::validate_request_items_keys( + input.request_items.keys(), + &ctx.limits, + )?; + let mut responses: HashMap> = HashMap::new(); let mut total_rcu: f64 = 0.0; let mut total_pre_proj_bytes: usize = 0; diff --git a/crates/engine/src/batch_write_item.rs b/crates/engine/src/batch_write_item.rs index 3806e0e44..1818393a3 100755 --- a/crates/engine/src/batch_write_item.rs +++ b/crates/engine/src/batch_write_item.rs @@ -93,6 +93,11 @@ pub async fn handle_batch_write_item( // both, the service answered either fault (measured 2026-11-11). extenddb_core::validation::number::operations::batch_write_item(&input)?; + extenddb_core::validation::table_name_length::validate_request_items_keys( + input.request_items.keys(), + &ctx.limits, + )?; + // Read every table's key info before anything is written. A lookup that // failed is reported where `check_batch` reaches its table, so the first // fault reported is the one the checks reach first. diff --git a/crates/engine/src/get_item.rs b/crates/engine/src/get_item.rs index 60dbb274c..64576dee1 100755 --- a/crates/engine/src/get_item.rs +++ b/crates/engine/src/get_item.rs @@ -125,6 +125,14 @@ pub async fn handle_get_item( None => None, }; + // See core's table_name_length for this order. An ARN is checked after the lookup. + if !input.table_name.starts_with("arn:") { + extenddb_core::validation::table_name_length::validate_item_table_name( + &input.table_name, + &ctx.limits, + )?; + } + let key_info = ctx .table_key_info(&input.table_name) .await @@ -172,3 +180,7 @@ pub async fn handle_get_item( }, }) } + +#[cfg(all(test, feature = "partiql"))] +#[path = "table_name_length_tests.rs"] +mod table_name_length_tests; diff --git a/crates/engine/src/partiql/mod.rs b/crates/engine/src/partiql/mod.rs index fb5e21044..dd7d0b0d9 100644 --- a/crates/engine/src/partiql/mod.rs +++ b/crates/engine/src/partiql/mod.rs @@ -57,7 +57,7 @@ mod returning; mod select; mod snapshot; #[cfg(test)] -mod test_context; +pub(crate) mod test_context; mod transaction; mod write; diff --git a/crates/engine/src/partiql/test_context.rs b/crates/engine/src/partiql/test_context.rs index 443514af0..2c2a241e7 100644 --- a/crates/engine/src/partiql/test_context.rs +++ b/crates/engine/src/partiql/test_context.rs @@ -21,7 +21,7 @@ use crate::{ }; /// Run `future` to completion on a runtime of its own. -pub(super) fn block_on(future: F) -> F::Output { +pub(crate) fn block_on(future: F) -> F::Output { tokio::runtime::Builder::new_current_thread() .enable_all() .build() @@ -30,7 +30,7 @@ pub(super) fn block_on(future: F) -> F::Output { } /// A context whose item authorizer is `authorizer`. -pub(super) async fn context(authorizer: Option>) -> OperationContext { +pub(crate) async fn context(authorizer: Option>) -> OperationContext { let storage = SqliteEngine::new(":memory:", 1, "us-east-1", 409_600) .await .expect("an in-memory database opens"); diff --git a/crates/engine/src/put_item.rs b/crates/engine/src/put_item.rs index 39b708ea0..afe8a3927 100755 --- a/crates/engine/src/put_item.rs +++ b/crates/engine/src/put_item.rs @@ -31,12 +31,15 @@ pub async fn handle_put_item( ) -> Result { // Validate table name from raw body first (takes priority over enum errors) if let Some(table_name) = body.get("TableName").and_then(|v| v.as_str()) { - extenddb_core::validation::validate_table_name(table_name, &ctx.limits)?; + extenddb_core::validation::table_name_length::validate_item_table_name( + table_name, + &ctx.limits, + )?; } else if body .get("TableName") .is_some_and(serde_json::Value::is_string) { - // empty string — caught by validate_table_name above + // An empty string is refused by validate_item_table_name above. } else if body.get("TableName").is_none() || body .get("TableName") diff --git a/crates/engine/src/table_name_length_tests.rs b/crates/engine/src/table_name_length_tests.rs new file mode 100644 index 000000000..a4554c72d --- /dev/null +++ b/crates/engine/src/table_name_length_tests.rs @@ -0,0 +1,180 @@ +// Copyright 2026 ExtendDB contributors +// SPDX-License-Identifier: Apache-2.0 + +//! Table names shorter than 3 or longer than 255 characters (issue #1056). +//! +//! Each row is the service's answer, measured on 2026-11-13, 2026-11-14 and +//! 2026-11-18, except that a `RequestItems` row renders the key alone where +//! the service quotes its rendering of the whole map. The context's catalog +//! is an empty in-memory database, so a request that reached a table lookup +//! would get none of these answers. + +use std::sync::Arc; + +use serde_json::{Value, json}; + +use extenddb_core::error::DynamoDbError; +use extenddb_core::limits::LimitsConfig; +use extenddb_storage::server_components::ServerComponentsOptions; +use extenddb_storage_sqlite::SqliteConfig; + +use crate::OperationContext; +use crate::partiql::test_context::{block_on, context}; + +const LEN3: &str = "Member must have length greater than or equal to 3"; +const LEN255: &str = "Member must have length less than or equal to 255"; +const MAP_KEYS: &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_.-]+]"; + +fn at(value: &str, location: &str, clause: &str) -> String { + format!("Value '{value}' at '{location}' failed to satisfy constraint: {clause}") +} + +fn one(value: &str, location: &str, clause: &str) -> Option { + Some(format!( + "1 validation error detected: {}", + at(value, location, clause) + )) +} + +fn key(pk: &str) -> Value { + json!({ "pk": { "S": pk }, "sk": { "S": "b" } }) +} + +/// `None` stands for `SerializationException`: the service answers a member +/// of the wrong type ahead of the name, with a message ExtendDB does not +/// match. +fn rows() -> Vec<(&'static str, Value, Option)> { + let n256 = "n".repeat(256); + let k256 = "k".repeat(256); + let put = |t: &str, pk: &str| json!({ "Put": { "TableName": t, "Item": key(pk) } }); + vec![ + ( + "GetItem", + json!({ "TableName": "ab", "Key": { "pk": { "S": "a" } } }), + one("ab", "tableName", LEN3), + ), + ( + "BatchGetItem", + json!({ "RequestItems": { k256.as_str(): { "ConsistentRead": true, + "ExpressionAttributeNames": { "#p": "pk" }, "Keys": [{ "pk": { "S": "a" } }], + "ProjectionExpression": "#p" } } }), + one(&k256, "requestItems", MAP_KEYS), + ), + ( + "BatchWriteItem", + json!({ "RequestItems": { "ab": [{ "PutRequest": { "Item": { "pk": { "S": "a" } } } }] } }), + one("ab", "requestItems", MAP_KEYS), + ), + ( + "TransactWriteItems", + json!({ "TransactItems": [put("ab", "a"), + { "Delete": { "TableName": n256, "Key": key("c") } }] }), + Some(format!( + "2 validation errors detected: {}; {}", + at("ab", "transactItems.1.member.put.tableName", LEN3), + at(&n256, "transactItems.2.member.delete.tableName", LEN255) + )), + ), + ("GetItem", json!({ "TableName": "ab", "Key": "x" }), None), + ( + "BatchGetItem", + json!({ "RequestItems": { "ab": { "Keys": "x" } } }), + None, + ), + ( + "BatchWriteItem", + json!({ "RequestItems": { "ab": "x" } }), + None, + ), + ( + "TransactWriteItems", + json!({ "TransactItems": [{ "Put": { "TableName": "ab", "Item": "x" } }] }), + None, + ), + ] +} + +#[test] +fn a_name_of_a_bad_length_is_refused_before_the_lookup() { + block_on(async { + let ctx = context(None).await; + for (op, body, expected) in rows() { + let row = format!("{op} {body}"); + match (crate::dispatch(op, body, &ctx, "").await, expected) { + (Err(DynamoDbError::ValidationException(m)), Some(want)) => { + assert_eq!(m, want, "{row}"); + } + (Err(DynamoDbError::SerializationException(_)), None) => {} + (Err(other), _) => panic!("{row}: {other:?}"), + (Ok(_), _) => panic!("{row}: answered without an error"), + } + } + }); +} + +/// A deployment whose `[limits]` bounds are 1 and 300 characters creates the +/// tables `ab` and one of 256 characters, and each operation accepts them. +#[test] +fn the_deployment_bounds_decide_which_lengths_are_refused() { + block_on(async { + let config = SqliteConfig { + path: ":memory:".to_owned(), + pool_size: 1, + }; + let mut options = ServerComponentsOptions::default(); + options.release = "test"; + let components = + (extenddb_storage_sqlite::backend().server_components)(&config, "us-east-1", options) + .await + .unwrap_or_else(|e| panic!("server components: {e:?}")); + let account_id = components.catalog_store.default_account_id().await; + let account_id = account_id.unwrap().expect("the bootstrapped account"); + components + .catalog_store + .set_setting("control_plane_delay_seconds", "0") + .await + .unwrap(); + let ctx = OperationContext { + storage: components.engine, + limits: Arc::new(LimitsConfig { + min_table_name_length: 1, + max_table_name_length: 300, + ..LimitsConfig::default() + }), + account_id: Arc::from(account_id), + ..context(None).await + }; + let n256 = "n".repeat(256); + let item = json!({ "pk": { "S": "a" } }); + for name in ["ab", n256.as_str()] { + for (op, body) in [ + ( + "CreateTable", + json!({ "TableName": name, "BillingMode": "PAY_PER_REQUEST", + "KeySchema": [{ "AttributeName": "pk", "KeyType": "HASH" }], + "AttributeDefinitions": [{ "AttributeName": "pk", "AttributeType": "S" }] }), + ), + ("GetItem", json!({ "TableName": name, "Key": item })), + ( + "BatchGetItem", + json!({ "RequestItems": { name: { "Keys": [item] } } }), + ), + ( + "BatchWriteItem", + json!({ "RequestItems": { name: [{ "PutRequest": { "Item": item } }] } }), + ), + ( + "TransactWriteItems", + json!({ "TransactItems": [{ "Put": { "TableName": name, "Item": item } }] }), + ), + ] { + if let Err(e) = crate::dispatch(op, body, &ctx, "").await { + panic!("{op} {name}: {e:?}"); + } + } + } + }); +} diff --git a/crates/engine/src/transact_write_items.rs b/crates/engine/src/transact_write_items.rs index 360ed2ffa..da7e4d671 100755 --- a/crates/engine/src/transact_write_items.rs +++ b/crates/engine/src/transact_write_items.rs @@ -94,6 +94,11 @@ pub async fn handle_transact_write_items( validate_member_attribute_name_sizes(twi, &ctx.limits)?; } + extenddb_core::validation::table_name_length::validate_transact_write_names( + &input.transact_items, + &ctx.limits, + )?; + // Resolve table key info, validate inputs, parse expressions, and check // for duplicate targets — all in a single pass to avoid redundant // `table_key_info` lookups. diff --git a/crates/server/src/table_name_gate.rs b/crates/server/src/table_name_gate.rs index 1268878ed..165a381cb 100644 --- a/crates/server/src/table_name_gate.rs +++ b/crates/server/src/table_name_gate.rs @@ -27,8 +27,11 @@ //! `exclusiveStartTableName`, `indexName` for `Query`, `Scan` and `SearchVectors`, and //! `transactItems..member..tableName` (1-based, `put`, `get`, //! `delete`, `update`, `conditionCheck`). A name inside the pattern but of a -//! bad length is left to the engine handlers, whose answer the service's -//! matches already. +//! bad length is left to the engine handlers, for the reason given in +//! `extenddb_core::validation::table_name_length`. Beside a name outside the +//! pattern, `TransactWriteItems` lists the other actions' names of a bad +//! length here (measured 2026-11-13 and 2026-11-14). An empty +//! `DescribeTable` name fails both clauses (measured 2026-11-18). //! - `ListStreams` has its own validator: `TableName must be at least 3 //! characters long and at most 255 characters long`, measured for a U+0000 //! name, and on 2026-11-04 for a table ARN and for `abc:def`; applied to @@ -63,23 +66,27 @@ //! member's own sentence (derived), as a bare name outside the pattern does. //! `ListStreams` refuses every value outside the pattern, as measured. -use extenddb_core::error::DynamoDbError; +use extenddb_core::error::{DynamoDbError, validation_error, validation_errors}; +use extenddb_core::validation::table_name_length::{ + MAP_KEYS_NAME, length_clause, transact_name_location, +}; use serde_json::Value; use crate::arn_gate::{self, PATTERN, in_pattern}; -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_.-]+]"; - const LIST_STREAMS_NAME: &str = "TableName must be at least 3 characters long and at most 255 characters long"; +/// The service's table name bounds. The gate lists a length clause only +/// beside a pattern fault, and that request is refused whatever the +/// deployment's bounds. +const NAME_BOUNDS: (usize, usize) = (3, 255); + /// Refuse a table name outside the service's character pattern, in any field /// the operation carries one, before the name is used in any lookup. A -/// missing, non-string or empty name passes. `account_id` is the caller's -/// account, which the control-plane ARN rules compare with the ARN's. +/// missing, non-string or empty name passes, except an empty `DescribeTable` +/// name. `account_id` is the caller's account, which the control-plane ARN +/// rules compare with the ARN's. pub(crate) fn check_table_name_chars( operation: &str, input: &Value, @@ -87,9 +94,9 @@ pub(crate) fn check_table_name_chars( ) -> Result<(), DynamoDbError> { match operation { "BatchGetItem" | "BatchWriteItem" => check_request_items_keys(operation, input), - "TransactGetItems" => check_transact_items(input, &["Get"]), + "TransactGetItems" => check_transact_items(input, &["Get"], false), "TransactWriteItems" => { - check_transact_items(input, &["Put", "Delete", "Update", "ConditionCheck"]) + check_transact_items(input, &["Put", "Delete", "Update", "ConditionCheck"], true) } "TagResource" | "UntagResource" | "ListTagsOfResource" => { with_str(input, "ResourceArn", arn_gate::check_tag_resource_arn) @@ -172,10 +179,7 @@ fn pattern_clause() -> String { } fn one_error(value: &str, location: &str, constraint: &str) -> DynamoDbError { - DynamoDbError::ValidationException(format!( - "1 validation error detected: Value '{value}' at '{location}' failed to satisfy \ - constraint: {constraint}" - )) + DynamoDbError::ValidationException(validation_error(value, location, constraint)) } /// A table name field: a bare name outside the pattern is refused with the @@ -193,7 +197,9 @@ fn check_name( if name.starts_with("arn:") { return arn_gate::check_table_name_arn(operation, name, account_id); } - if name.is_empty() || in_pattern(name) { + // The service reads an empty DescribeTable name as one that fails the + // length and the pattern (measured 2026-11-18). + if in_pattern(name) && !(name.is_empty() && operation == "DescribeTable") { return Ok(()); } Err(bare_name_error(name, location)) @@ -218,29 +224,30 @@ fn check_name_member(value: Option<&Value>, location: &str) -> Result<(), Dynamo /// The service lists every failed constraint of a member in one message, the /// length clause before the pattern clause. fn bare_name_error(name: &str, location: &str) -> DynamoDbError { - let length = name.chars().count(); - let mut clauses: Vec = Vec::with_capacity(2); - if length < 3 { - clauses.push("Member must have length greater than or equal to 3".to_owned()); - } else if length > 255 { - clauses.push("Member must have length less than or equal to 255".to_owned()); + bare_names_error(&[(name, location.to_owned())]) +} + +/// [`bare_name_error`] for several members, in the order given. A name inside +/// the pattern contributes its length clause alone. +fn bare_names_error(names: &[(&str, String)]) -> DynamoDbError { + let pattern = pattern_clause(); + let mut faults: Vec<(&str, &str, &str)> = Vec::new(); + for (name, location) in names { + if let Some(clause) = length_clause(name, NAME_BOUNDS) { + faults.push((name, location, clause)); + } + if name.is_empty() || !in_pattern(name) { + faults.push((name, location, &pattern)); + } } - clauses.push(pattern_clause()); - let n = clauses.len(); - DynamoDbError::ValidationException(format!( - "{n} validation error{} detected: {}", - if n == 1 { "" } else { "s" }, - clauses - .iter() - .map(|c| format!("Value '{name}' at '{location}' failed to satisfy constraint: {c}")) - .collect::>() - .join("; ") - )) + DynamoDbError::ValidationException(validation_errors(&faults)) } /// A `RequestItems` key outside the pattern, or an ARN key that the ARN rules /// refuse. The sentence from `at 'requestItems'` onward is the service's; the /// offending key alone is rendered where the service renders the whole map. +/// The engine handlers give a key of a bad length the same sentence, after +/// the request is read. /// /// `BatchWriteItem` refuses a key for its account segment only when the /// segment carries U+0000; any other bad account segment is passed on to the @@ -276,11 +283,21 @@ fn check_request_items_keys(operation: &str, input: &Value) -> Result<(), Dynamo } /// A `TransactItems` member whose sub-operation names a table outside the -/// pattern, or by an ARN that the ARN rules refuse. -fn check_transact_items(input: &Value, subs: &[&str]) -> Result<(), DynamoDbError> { +/// pattern, or by an ARN that the ARN rules refuse. With `list_lengths` +/// (`TransactWriteItems`) the message lists every action's name outside the +/// pattern and every name of a bad length, as the service does (measured +/// 2026-11-13 and 2026-11-14). Names of a bad length alone are left to the +/// engine, which checks them after the request is read. +fn check_transact_items( + input: &Value, + subs: &[&str], + list_lengths: bool, +) -> Result<(), DynamoDbError> { let Some(items) = input.get("TransactItems").and_then(Value::as_array) else { return Ok(()); }; + let mut names: Vec<(&str, String)> = Vec::new(); + let mut outside = false; for (i, item) in items.iter().enumerate() { for sub in subs { let Some(name) = item @@ -293,27 +310,26 @@ fn check_transact_items(input: &Value, subs: &[&str]) -> Result<(), DynamoDbErro if name.is_empty() { continue; } - let location = format!( - "transactItems.{}.member.{}.tableName", - i + 1, - lower_camel(sub) - ); + let location = transact_name_location(i, sub); if name.starts_with("arn:") { - arn_gate::check_transact_member_arn(name, &location)?; + if let Err(e) = arn_gate::check_transact_member_arn(name, &location) { + return Err(if outside { bare_names_error(&names) } else { e }); + } } else if !in_pattern(name) { - return Err(bare_name_error(name, &location)); + if !list_lengths { + return Err(bare_name_error(name, &location)); + } + outside = true; + names.push((name, location)); + } else if list_lengths && length_clause(name, NAME_BOUNDS).is_some() { + names.push((name, location)); } } } - Ok(()) -} - -fn lower_camel(s: &str) -> String { - let mut c = s.chars(); - match c.next() { - Some(f) => f.to_ascii_lowercase().to_string() + c.as_str(), - None => String::new(), + if outside { + return Err(bare_names_error(&names)); } + Ok(()) } #[cfg(test)] @@ -700,7 +716,7 @@ mod tests { let m = message( "TransactWriteItems", json!({ "TransactItems": [ - { "Put": { "TableName": "ok", "Item": {} } }, + { "Put": { "TableName": "okay", "Item": {} } }, { "Delete": { "TableName": NUL, "Key": {} } }, ] }), ) @@ -748,4 +764,74 @@ mod tests { .is_none() ); } + + /// Issue #1056 rows the gate answers (measured 2026-11-13, 2026-11-14 and + /// 2026-11-18). A name of a bad length alone passes on to the engine, and + /// every operation but `DescribeTable` passes an empty name on. + #[test] + fn bad_lengths_beside_a_pattern_fault_and_the_empty_describe_table_name() { + let len = "Member must have length greater than or equal to 3"; + let at = |v: &str, l: &str, c: &str| { + format!("Value '{v}' at '{l}' failed to satisfy constraint: {c}") + }; + let put = |t: &str| json!({ "Put": { "TableName": t, "Item": {} } }); + let del = |t: &str| json!({ "Delete": { "TableName": t, "Key": {} } }); + let n256 = "n".repeat(256); + let rows = [ + ( + "DescribeTable", + json!({ "TableName": "" }), + Some(format!( + "2 validation errors detected: {}; {}", + at("", "tableName", len), + at("", "tableName", PAT) + )), + ), + ( + "TransactWriteItems", + json!({ "TransactItems": [put("ab"), del("bad name")] }), + Some(format!( + "2 validation errors detected: {}; {}", + at("ab", "transactItems.1.member.put.tableName", len), + at("bad name", "transactItems.2.member.delete.tableName", PAT) + )), + ), + ( + "TransactWriteItems", + json!({ "TransactItems": [put("ab"), del(&n256)] }), + None, + ), + ("GetItem", json!({ "TableName": "ab" }), None), + ( + "BatchGetItem", + json!({ "RequestItems": { "ab": {} } }), + None, + ), + ( + "BatchWriteItem", + json!({ "RequestItems": { "ab": [] } }), + None, + ), + ("CreateTable", json!({ "TableName": "", "Tags": "x" }), None), + ( + "CreateTable", + json!({ "TableName": n256, "Tags": "x" }), + None, + ), + ]; + for (op, input, expected) in rows { + assert_eq!(message(op, input.clone()), expected, "{op} {input}"); + } + for op in [ + "CreateTable", + "UpdateTable", + "DeleteTable", + "PutItem", + "GetItem", + "Query", + "DescribeTimeToLive", + ] { + assert_eq!(message(op, json!({ "TableName": "" })), None, "{op}"); + } + } } diff --git a/tests/python/test_nul_table_names.py b/tests/python/test_nul_table_names.py index 4837c6a3f..5a3150f2d 100644 --- a/tests/python/test_nul_table_names.py +++ b/tests/python/test_nul_table_names.py @@ -1,7 +1,7 @@ # Copyright 2026 ExtendDB contributors # SPDX-License-Identifier: Apache-2.0 -"""U+0000 in index names and table names. +"""U+0000 in index names and table names, and table names of a bad length. DynamoDB refuses U+0000 inside an index name or a table name with the member pattern ValidationException. Measured against the service with SDK parameter @@ -26,7 +26,13 @@ import pytest from botocore.exceptions import ClientError -from helpers import assert_member_pattern, unique_name, wait_for_active, wait_for_deleted +from helpers import ( + assert_member_pattern, + assert_validation, + unique_name, + wait_for_active, + wait_for_deleted, +) NUL = "\u0000" PATTERN = "Member must satisfy regular expression pattern: [a-zA-Z0-9_.-]+" @@ -270,3 +276,173 @@ def test_tag_operations_with_nul_arn_segment_are_refused(self, raw_client, nul_a assert resp["Error"]["Message"] == ( f"Invalid TableArn: Invalid ResourceArn provided as input {nul_arn}" ) + + +N256 = "n" * 256 +K256 = "k" * 256 +LEN3 = "Member must have length greater than or equal to 3" +LEN255 = "Member must have length less than or equal to 255" +EMPTY = ( + "1 validation error detected: Value at 'TableName' failed to satisfy constraint: " + "Member must have length greater than or equal to 1" +) + + +def _at(value: str, location: str, clause: str) -> str: + return f"Value '{value}' at '{location}' failed to satisfy constraint: {clause}" + + +def _one(value: str, location: str, clause: str) -> str: + return f"1 validation error detected: {_at(value, location, clause)}" + + +def _key(pk: str) -> dict: + return {"pk": {"S": pk}, "sk": {"S": "b"}} + + +def _put(table: str, pk: str) -> dict: + return {"Put": {"TableName": table, "Item": _key(pk)}} + + +# Issue #1056: a table name shorter than 3 or longer than 255 characters, and +# an empty one, measured on 2026-11-13, 2026-11-14 and 2026-11-18 (us-east-1). +# Each row is (call, expected): a message, or ("requestItems", key) for the +# map-key sentence, whose quoted value is compared as in +# TestNulInNestedTableNames. `t` is a table keyed on pk and sk. +LENGTH_ROWS = [ + pytest.param( + lambda c, t: c.get_item(TableName="ab", Key={"pk": {"S": "a"}}), + _one("ab", "tableName", LEN3), + id="GetItem-short", + ), + pytest.param( + lambda c, t: c.get_item(TableName=N256, Key=_key("a")), + _one(N256, "tableName", LEN255), + id="GetItem-long", + ), + pytest.param( + lambda c, t: c.get_item(TableName="", Key={"pk": {"S": "a"}}), EMPTY, id="GetItem-empty" + ), + pytest.param( + lambda c, t: c.put_item(TableName="", Item={"pk": {"S": "a"}}), EMPTY, id="PutItem-empty" + ), + pytest.param( + lambda c, t: c.describe_table(TableName=""), + f"2 validation errors detected: {_at('', 'tableName', LEN3)}; {_at('', 'tableName', PATTERN)}", + id="DescribeTable-empty", + ), + pytest.param( + lambda c, t: c.transact_write_items( + TransactItems=[ + _put(t, "a"), + { + "Update": { + "TableName": "ab", + "Key": _key("c"), + "UpdateExpression": "SET v = :v", + "ExpressionAttributeValues": {":v": {"S": "x"}}, + } + }, + ] + ), + _one("ab", "transactItems.2.member.update.tableName", LEN3), + id="TransactWriteItems-short", + ), + pytest.param( + lambda c, t: c.transact_write_items( + TransactItems=[ + _put(t, "a"), + _put(t, "c"), + {"Delete": {"TableName": N256, "Key": _key("d")}}, + ] + ), + _one(N256, "transactItems.3.member.delete.tableName", LEN255), + id="TransactWriteItems-long", + ), + pytest.param( + lambda c, t: c.transact_write_items( + TransactItems=[_put("ab", "a"), {"Delete": {"TableName": N256, "Key": _key("c")}}] + ), + "2 validation errors detected: " + f"{_at('ab', 'transactItems.1.member.put.tableName', LEN3)}; " + f"{_at(N256, 'transactItems.2.member.delete.tableName', LEN255)}", + id="TransactWriteItems-short-and-long", + ), + pytest.param( + lambda c, t: c.transact_write_items( + TransactItems=[_put("ab", "a"), {"Delete": {"TableName": "bad name", "Key": _key("c")}}] + ), + "2 validation errors detected: " + f"{_at('ab', 'transactItems.1.member.put.tableName', LEN3)}; " + f"{_at('bad name', 'transactItems.2.member.delete.tableName', PATTERN)}", + id="TransactWriteItems-short-and-pattern", + ), + pytest.param( + lambda c, t: c.batch_get_item(RequestItems={"ab": {"Keys": [{"pk": {"S": "a"}}]}}), + ("requestItems", "ab"), + id="BatchGetItem-short", + ), + pytest.param( + lambda c, t: c.batch_get_item(RequestItems={"ab": {"Keys": [{"pk": {"S": 'a"b\\c\nd'}}]}}), + ("requestItems", "ab"), + id="BatchGetItem-short-escaped-value", + ), + pytest.param( + lambda c, t: c.batch_get_item( + RequestItems={ + K256: { + "ConsistentRead": True, + "ExpressionAttributeNames": {"#p": "pk"}, + "Keys": [{"pk": {"S": "a"}}], + "ProjectionExpression": "#p", + } + } + ), + ("requestItems", K256), + id="BatchGetItem-long", + ), + pytest.param( + lambda c, t: c.batch_write_item( + RequestItems={"ab": [{"PutRequest": {"Item": {"pk": {"S": "a"}}}}]} + ), + ("requestItems", "ab"), + id="BatchWriteItem-short", + ), +] + + +class TestTableNameLengths: + """The service refuses these names with ValidationException before it + looks a table up; the TransactWriteItems rows list every action's fault.""" + + @pytest.fixture(scope="class") + def keyed_table(self, raw_client): + name = unique_name("len") + raw_client.create_table( + TableName=name, + BillingMode="PAY_PER_REQUEST", + KeySchema=[ + {"AttributeName": "pk", "KeyType": "HASH"}, + {"AttributeName": "sk", "KeyType": "RANGE"}, + ], + AttributeDefinitions=[ + {"AttributeName": "pk", "AttributeType": "S"}, + {"AttributeName": "sk", "AttributeType": "S"}, + ], + ) + wait_for_active(raw_client, name) + yield name + try: + raw_client.delete_table(TableName=name) + wait_for_deleted(raw_client, name) + except Exception: + pass + + @pytest.mark.parametrize("call,expected", LENGTH_ROWS) + def test_a_name_of_a_bad_length_is_refused(self, raw_client, keyed_table, call, expected): + with pytest.raises(ClientError) as exc: + call(raw_client, keyed_table) + if isinstance(expected, tuple): + TestNulInNestedTableNames._request_items_error(exc.value, expected[1]) + else: + assert_validation(exc.value, expected) From a88fa4a2b237766b37566409b5b4a6990da5d7f6 Mon Sep 17 00:00:00 2001 From: Lee Hannigan <29015211+LeeroyHannigan@users.noreply.github.com> Date: Wed, 25 Nov 2026 11:04:18 +0000 Subject: [PATCH 2/7] refactor(core): one table_name_bounds for the deployment's name bounds validate_request_items_keys and validate_transact_write_names each built the pair (min_table_name_length, max_table_name_length) from the limits. The backup requests had a function, table_name_bounds, that builds the same pair. That function moves to extenddb_core::validation::table_name_length. The two core checks and the backup requests call it there. --- crates/core/src/validation/table_name_length.rs | 11 +++++++++-- crates/engine/src/backup_requests.rs | 7 +------ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/crates/core/src/validation/table_name_length.rs b/crates/core/src/validation/table_name_length.rs index 23fbdcd1b..1b4227416 100644 --- a/crates/core/src/validation/table_name_length.rs +++ b/crates/core/src/validation/table_name_length.rs @@ -54,6 +54,13 @@ pub fn length_clause(name: &str, (min, max): (usize, usize)) -> Option<&'static } } +/// 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..member..tableName`, with `n` counted from 1 and the /// action's member name (`ConditionCheck`) in lower camel case. @@ -100,7 +107,7 @@ pub fn validate_request_items_keys<'a>( keys: impl IntoIterator, limits: &LimitsConfig, ) -> Result<(), DynamoDbError> { - let bounds = (limits.min_table_name_length, limits.max_table_name_length); + let bounds = table_name_bounds(limits); let refused = keys .into_iter() .filter(|k| !k.is_empty() && !k.starts_with("arn:") && length_clause(k, bounds).is_some()) @@ -144,7 +151,7 @@ pub fn validate_transact_write_names( } } } - let bounds = (limits.min_table_name_length, limits.max_table_name_length); + let bounds = table_name_bounds(limits); let faults: Vec<(&str, &str, &str)> = names .iter() .filter_map(|(name, location)| { diff --git a/crates/engine/src/backup_requests.rs b/crates/engine/src/backup_requests.rs index 8da9f4748..35b7c5736 100644 --- a/crates/engine/src/backup_requests.rs +++ b/crates/engine/src/backup_requests.rs @@ -21,6 +21,7 @@ use extenddb_core::error::DynamoDbError; use extenddb_core::limits::LimitsConfig; use extenddb_core::types::BackupSummary; +use extenddb_core::validation::table_name_length::table_name_bounds; use extenddb_storage::backup_catalog::TimeBounds; use extenddb_storage::error::StorageError; use extenddb_storage::{BackupCatalog, LegacyBackupReader}; @@ -135,12 +136,6 @@ pub(crate) fn validate_name_member( } } -/// The length bounds for a `TableName` member: the deployment's, which -/// default to the model's 3 to 255. -fn table_name_bounds(limits: &LimitsConfig) -> (usize, usize) { - (limits.min_table_name_length, limits.max_table_name_length) -} - /// The `TableName` of `CreateBackup` and `ListBackups`, which the service /// accepts as the table's name or its ARN (measured on DynamoDB; the model /// gives the member the `TableName` shape, max 255, so an SDK built from it From 3592be97bbc79977a55f2a51f864cc38278655b7 Mon Sep 17 00:00:00 2001 From: Lee Hannigan <29015211+LeeroyHannigan@users.noreply.github.com> Date: Wed, 25 Nov 2026 11:04:18 +0000 Subject: [PATCH 3/7] refactor(engine): delete the unreachable TableName arm of PutItem The first branch of handle_put_item takes a TableName that is a string. The second branch also matched a string, so it never ran. This change deletes the second branch and its comment. --- crates/engine/src/put_item.rs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/crates/engine/src/put_item.rs b/crates/engine/src/put_item.rs index afe8a3927..3f7ecb7e3 100755 --- a/crates/engine/src/put_item.rs +++ b/crates/engine/src/put_item.rs @@ -35,11 +35,6 @@ pub async fn handle_put_item( table_name, &ctx.limits, )?; - } else if body - .get("TableName") - .is_some_and(serde_json::Value::is_string) - { - // An empty string is refused by validate_item_table_name above. } else if body.get("TableName").is_none() || body .get("TableName") From a8838915827df5c37c2248c973fae1e0677e8006 Mon Sep 17 00:00:00 2001 From: Lee Hannigan <29015211+LeeroyHannigan@users.noreply.github.com> Date: Wed, 25 Nov 2026 11:04:18 +0000 Subject: [PATCH 4/7] docs: say where the TransactWriteItems name list ends check_transact_items lists the names of the actions up to the first ARN that the ARN rules refuse. Its comment said that it lists every action. On 25 Nov 2026 DynamoDB listed the fault of such an ARN and the faults of the later actions in the same message. The comment now says where the list ends. The security manual said that the server authorizes a name that breaks only a length bound first, with one exception for ListStreams. The table name gate now refuses an empty DescribeTable name before authorization, so the manual names that exception too. --- crates/server/src/table_name_gate.rs | 7 +++++-- docs/manuals/10-security-model.md | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/crates/server/src/table_name_gate.rs b/crates/server/src/table_name_gate.rs index 165a381cb..04a136df2 100644 --- a/crates/server/src/table_name_gate.rs +++ b/crates/server/src/table_name_gate.rs @@ -286,8 +286,11 @@ fn check_request_items_keys(operation: &str, input: &Value) -> Result<(), Dynamo /// pattern, or by an ARN that the ARN rules refuse. With `list_lengths` /// (`TransactWriteItems`) the message lists every action's name outside the /// pattern and every name of a bad length, as the service does (measured -/// 2026-11-13 and 2026-11-14). Names of a bad length alone are left to the -/// engine, which checks them after the request is read. +/// 2026-11-13 and 2026-11-14), up to the first ARN that the ARN rules refuse. +/// The list ends at that ARN. The service also lists the ARN's fault and the +/// later actions' faults (measured 2026-11-25), and this check leaves them +/// out. Names of a bad length alone are left to the engine, which checks them +/// after the request is read. fn check_transact_items( input: &Value, subs: &[&str], diff --git a/docs/manuals/10-security-model.md b/docs/manuals/10-security-model.md index b3569ef53..2f8d1e52d 100755 --- a/docs/manuals/10-security-model.md +++ b/docs/manuals/10-security-model.md @@ -153,7 +153,7 @@ When `auth.provider = "builtin"`, every authenticated DynamoDB API request is au - `DescribeEndpoints`, which needs a signed request and no permission. - `RestoreTableToPointInTime`, and an `UpdateContinuousBackups` that enables point-in-time recovery, which are refused because point-in-time recovery is not supported. -- A request that the service also answers before its IAM decision: a table name, index name or ARN outside the model's constraints, an ARN of the wrong kind or in another account, a stream ARN in another partition or region, a batch or transaction with no items or too many, and a shard iterator the server did not issue (see [Differences from DynamoDB](../differences-from-dynamodb.md)). A name or ARN that breaks only a length bound, an empty one included, is authorized first, except a `ListStreams` `TableName` of 1, 2 or more than 255 characters, which is refused first. +- A request that the service also answers before its IAM decision: a table name, index name or ARN outside the model's constraints, an ARN of the wrong kind or in another account, a stream ARN in another partition or region, a batch or transaction with no items or too many, and a shard iterator the server did not issue (see [Differences from DynamoDB](../differences-from-dynamodb.md)). A name or ARN that breaks only a length bound, an empty one included, is authorized first, except a `ListStreams` `TableName` of 1, 2 or more than 255 characters and an empty `DescribeTable` `TableName`, which are refused first. - A PartiQL request that is refused before any of its statements is authorized: a member outside its constraints, or a statement that does not parse or breaks a rule of its form. The server authorizes a PartiQL request per statement. - A request the server cannot authorize because of a fault, such as a failed key lookup, which gets a server error. From aedd59acae043dac98348f6e1d19acf28cc987eb Mon Sep 17 00:00:00 2001 From: Lee Hannigan <29015211+LeeroyHannigan@users.noreply.github.com> Date: Thu, 3 Dec 2026 09:16:58 +0000 Subject: [PATCH 5/7] fix(engine): answer a table name over 1024 characters with the member bound DynamoDB checks the TableName member against 1024 characters before it checks the table name. It answers a name over that bound with the clause of the member alone, with no value quoted (measured 2026-12-03): - GetItem and PutItem: Value at 'TableName'. - BatchGetItem: Value at 'RequestItems.', one clause for each such key. - BatchWriteItem: the map keys sentence at requestItems, with the list of the member bounds, 1024 and 1. - TransactWriteItems: Value at 'TransactItems..member..TableName', with n counted from 0, one clause for each such name. The clause comes alone beside a name of 2 characters, a name outside the pattern and an ARN that the ARN rules refuse. A name of 1024 characters keeps the 255 clause. The engine checks give these answers after the handler reads the request, as for the other lengths. When the table name gate of the server refuses a TransactWriteItems request, it gives this answer in place of its own. A deployment whose max_table_name_length is above 1024 takes that maximum as the bound. validate_item_table_name writes the empty name sentence of GetItem and PutItem with the same code, so the ItemTableNameEmpty key goes. The new rows also hold the empty GetItem name and the sorted choice of key in BatchGetItem. The WebAssembly build has no gate, so four corpus cases and docs/webassembly.md record its answers to such names outside the pattern. --- crates/core/src/error/messages.rs | 5 - .../core/src/validation/table_name_length.rs | 179 ++++++++++++++---- crates/engine/src/batch_get_item.rs | 1 + crates/engine/src/batch_write_item.rs | 1 + crates/engine/src/table_name_length_tests.rs | 115 +++++++++-- crates/server/src/table_name_gate.rs | 50 ++++- crates/wasm-adapter/parity/corpus.json | 104 ++++++++++ docs/webassembly.md | 10 +- tests/python/test_nul_table_names.py | 88 ++++++++- 9 files changed, 495 insertions(+), 58 deletions(-) diff --git a/crates/core/src/error/messages.rs b/crates/core/src/error/messages.rs index 6beb88743..b16bbb546 100755 --- a/crates/core/src/error/messages.rs +++ b/crates/core/src/error/messages.rs @@ -52,8 +52,6 @@ pub enum ErrorMessageKey { TableNameTooLong, TableNameNull, TableNameEmpty, - /// An empty name in `GetItem` and `PutItem` (measured 2026-11-18). - ItemTableNameEmpty, TableNameInvalidChars, TableNotFound, TableAlreadyExists, @@ -83,9 +81,6 @@ pub fn error_message(key: ErrorMessageKey, args: &[&str]) -> String { ErrorMessageKey::TableNameEmpty => { "1 validation error detected: Value '' at 'tableName' failed to satisfy constraint: Member must have length greater than or equal to 1".to_owned() } - ErrorMessageKey::ItemTableNameEmpty => { - "1 validation error detected: Value at 'TableName' failed to satisfy constraint: Member must have length greater than or equal to 1".to_owned() - } ErrorMessageKey::TableNameInvalidChars => { format!( "1 validation error detected: Value '{}' at 'tableName' failed to satisfy constraint: \ diff --git a/crates/core/src/validation/table_name_length.rs b/crates/core/src/validation/table_name_length.rs index 1b4227416..f99784917 100644 --- a/crates/core/src/validation/table_name_length.rs +++ b/crates/core/src/validation/table_name_length.rs @@ -17,9 +17,21 @@ //! //! 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.` in `BatchGetItem`, and +//! `TransactItems..member..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, ErrorMessageKey, error_message, validation_error, validation_errors, + DynamoDbError, validation_error, validation_errors, validation_errors_detected, }; use crate::limits::LimitsConfig; use crate::types::TransactWriteItem; @@ -43,6 +55,19 @@ pub(crate) const TOO_SHORT: &str = "Member must have length greater than or equa /// 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] @@ -74,45 +99,93 @@ pub fn transact_name_location(index: usize, member: &str) -> String { 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 ''` clause for each, with no value quoted. +fn member_error(clauses: impl IntoIterator) -> DynamoDbError { + let clauses: Vec = 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 in both with `Value at 'TableName'` and a -/// length of at least 1 (measured 2026-11-18). Any other name gets the answer -/// of [`validate_table_name`]. +/// 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 an empty name or one that +/// `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> { - if name.is_empty() { - return Err(DynamoDbError::ValidationException(error_message( - ErrorMessageKey::ItemTableNameEmpty, - &[], - ))); - } - validate_table_name(name, limits) + 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, refused with the service's sentence -/// at `requestItems`. The service quotes its rendering of the whole map in -/// `Value '...'`, and 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. +/// 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` for the smallest such key. The keys come from a -/// `HashMap`, whose order changes from one request to the next. +/// `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, limits: &LimitsConfig, ) -> Result<(), DynamoDbError> { - let bounds = table_name_bounds(limits); - let refused = keys + let mut keys: Vec<&str> = keys .into_iter() - .filter(|k| !k.is_empty() && !k.starts_with("arn:") && length_clause(k, bounds).is_some()) - .min(); - if let Some(key) = refused { + .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", @@ -122,10 +195,41 @@ pub fn validate_request_items_keys<'a>( 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..member..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, + 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 service lists every action's fault in one message, in action -/// order (measured 2026-11-18). An empty name and a table ARN are left to the -/// code after this. +/// 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 /// @@ -134,7 +238,7 @@ pub fn validate_transact_write_names( items: &[TransactWriteItem], limits: &LimitsConfig, ) -> Result<(), DynamoDbError> { - let mut names: Vec<(&str, String)> = Vec::new(); + let mut names: Vec<(usize, &str, &str)> = Vec::new(); for (i, item) in items.iter().enumerate() { let members = [ ( @@ -147,20 +251,29 @@ pub fn validate_transact_write_names( ]; for (member, name) in members { if let Some(name) = name.filter(|n| !n.is_empty() && !n.starts_with("arn:")) { - names.push((name, transact_name_location(i, member))); + names.push((i, member, name)); } } } + check_transact_member_bound(names.iter().copied(), limits.max_table_name_length)?; let bounds = table_name_bounds(limits); - let faults: Vec<(&str, &str, &str)> = names + let located: Vec<(&str, String, &str)> = names .iter() - .filter_map(|(name, location)| { - Some((*name, location.as_str(), length_clause(name, bounds)?)) + .filter_map(|&(i, member, name)| { + Some(( + name, + transact_name_location(i, member), + length_clause(name, bounds)?, + )) }) .collect(); - if faults.is_empty() { + 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, ))) diff --git a/crates/engine/src/batch_get_item.rs b/crates/engine/src/batch_get_item.rs index 9280c95fa..05e9b1fd8 100755 --- a/crates/engine/src/batch_get_item.rs +++ b/crates/engine/src/batch_get_item.rs @@ -166,6 +166,7 @@ pub async fn handle_batch_get_item( } extenddb_core::validation::table_name_length::validate_request_items_keys( + "BatchGetItem", input.request_items.keys(), &ctx.limits, )?; diff --git a/crates/engine/src/batch_write_item.rs b/crates/engine/src/batch_write_item.rs index 1818393a3..8cc7f4477 100755 --- a/crates/engine/src/batch_write_item.rs +++ b/crates/engine/src/batch_write_item.rs @@ -94,6 +94,7 @@ pub async fn handle_batch_write_item( extenddb_core::validation::number::operations::batch_write_item(&input)?; extenddb_core::validation::table_name_length::validate_request_items_keys( + "BatchWriteItem", input.request_items.keys(), &ctx.limits, )?; diff --git a/crates/engine/src/table_name_length_tests.rs b/crates/engine/src/table_name_length_tests.rs index a4554c72d..095658aa3 100644 --- a/crates/engine/src/table_name_length_tests.rs +++ b/crates/engine/src/table_name_length_tests.rs @@ -1,12 +1,15 @@ // Copyright 2026 ExtendDB contributors // SPDX-License-Identifier: Apache-2.0 -//! Table names shorter than 3 or longer than 255 characters (issue #1056). +//! Table names shorter than 3 or longer than 255 characters (issue #1056), +//! and over the 1024 characters of the `TableName` member. //! -//! Each row is the service's answer, measured on 2026-11-13, 2026-11-14 and -//! 2026-11-18, except that a `RequestItems` row renders the key alone where -//! the service quotes its rendering of the whole map. The context's catalog -//! is an empty in-memory database, so a request that reached a table lookup +//! Each row is the service's answer, measured on 2026-11-13, 2026-11-14, +//! 2026-11-18 and 2026-12-03, except that a `RequestItems` row renders the +//! key alone where the service quotes its rendering of the whole map, and the +//! `BatchGetItem` row of two keys over 1024 characters lists them sorted, +//! where the service listed them in either order. The context's catalog is +//! an empty in-memory database, so a request that reached a table lookup //! would get none of these answers. use std::sync::Arc; @@ -23,10 +26,14 @@ use crate::partiql::test_context::{block_on, context}; const LEN3: &str = "Member must have length greater than or equal to 3"; const LEN255: &str = "Member must have length less than or equal to 255"; +const LEN1024: &str = "Member must have length less than or equal to 1024"; const MAP_KEYS: &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_.-]+]"; +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]"; fn at(value: &str, location: &str, clause: &str) -> String { format!("Value '{value}' at '{location}' failed to satisfy constraint: {clause}") @@ -43,14 +50,96 @@ fn key(pk: &str) -> Value { json!({ "pk": { "S": pk }, "sk": { "S": "b" } }) } +/// The member's clauses, `Value at ''` with no value quoted. +fn member(locations: &[&str], clause: &str) -> Option { + let clauses: Vec = locations + .iter() + .map(|l| format!("Value at '{l}' failed to satisfy constraint: {clause}")) + .collect(); + Some(extenddb_core::error::validation_errors_detected(&clauses)) +} + /// `None` stands for `SerializationException`: the service answers a member /// of the wrong type ahead of the name, with a message ExtendDB does not /// match. fn rows() -> Vec<(&'static str, Value, Option)> { let n256 = "n".repeat(256); let k256 = "k".repeat(256); + let (a1024, a1025, b1025) = ("a".repeat(1024), "a".repeat(1025), "b".repeat(1025)); let put = |t: &str, pk: &str| json!({ "Put": { "TableName": t, "Item": key(pk) } }); - vec![ + let del = |t: &str, pk: &str| json!({ "Delete": { "TableName": t, "Key": key(pk) } }); + let a_key = json!({ "pk": { "S": "a" } }); + let keys = || json!({ "Keys": [{ "pk": { "S": "a" } }] }); + let write = || json!([{ "PutRequest": { "Item": { "pk": { "S": "a" } } } }]); + let bgi_a = format!("RequestItems.{a1025}"); + let bgi_b = format!("RequestItems.{b1025}"); + let mut rows = vec![ + ( + "GetItem", + json!({ "TableName": a1025, "Key": a_key }), + member(&["TableName"], LEN1024), + ), + ( + "GetItem", + json!({ "TableName": a1024, "Key": a_key }), + one(&a1024, "tableName", LEN255), + ), + ( + "GetItem", + json!({ "TableName": "", "Key": a_key }), + member( + &["TableName"], + "Member must have length greater than or equal to 1", + ), + ), + ( + "PutItem", + json!({ "TableName": a1025, "Item": a_key }), + member(&["TableName"], LEN1024), + ), + ( + "BatchGetItem", + json!({ "RequestItems": { b1025.as_str(): keys(), a1025.as_str(): keys() } }), + member(&[&bgi_a, &bgi_b], LEN1024), + ), + ( + "BatchGetItem", + json!({ "RequestItems": { "ab": keys(), a1025.as_str(): keys() } }), + member(&[&bgi_a], LEN1024), + ), + ( + "BatchGetItem", + json!({ "RequestItems": { "zz": keys(), "ab": keys() } }), + one("ab", "requestItems", MAP_KEYS), + ), + ( + "BatchWriteItem", + json!({ "RequestItems": { "ab": write(), a1025.as_str(): write() } }), + one(&a1025, "requestItems", MAP_KEYS_MEMBER), + ), + ( + "TransactWriteItems", + json!({ "TransactItems": [put("ab", "a"), del(&a1025, "b")] }), + member(&["TransactItems.1.member.Delete.TableName"], LEN1024), + ), + ( + "TransactWriteItems", + json!({ "TransactItems": [put(&a1025, "a"), del(&b1025, "b")] }), + member( + &[ + "TransactItems.0.member.Put.TableName", + "TransactItems.1.member.Delete.TableName", + ], + LEN1024, + ), + ), + ( + "TransactWriteItems", + json!({ "TransactItems": [put(&a1024, "a")] }), + one(&a1024, "transactItems.1.member.put.tableName", LEN255), + ), + ]; + rows.extend(vec![ ( "GetItem", json!({ "TableName": "ab", "Key": { "pk": { "S": "a" } } }), @@ -94,7 +183,8 @@ fn rows() -> Vec<(&'static str, Value, Option)> { json!({ "TransactItems": [{ "Put": { "TableName": "ab", "Item": "x" } }] }), None, ), - ] + ]); + rows } #[test] @@ -115,8 +205,9 @@ fn a_name_of_a_bad_length_is_refused_before_the_lookup() { }); } -/// A deployment whose `[limits]` bounds are 1 and 300 characters creates the -/// tables `ab` and one of 256 characters, and each operation accepts them. +/// A deployment whose `[limits]` bounds are 1 and 1100 characters creates the +/// tables `ab` and ones of 256 and 1025 characters, and each operation accepts +/// them. #[test] fn the_deployment_bounds_decide_which_lengths_are_refused() { block_on(async { @@ -141,15 +232,15 @@ fn the_deployment_bounds_decide_which_lengths_are_refused() { storage: components.engine, limits: Arc::new(LimitsConfig { min_table_name_length: 1, - max_table_name_length: 300, + max_table_name_length: 1100, ..LimitsConfig::default() }), account_id: Arc::from(account_id), ..context(None).await }; - let n256 = "n".repeat(256); + let (n256, n1025) = ("n".repeat(256), "n".repeat(1025)); let item = json!({ "pk": { "S": "a" } }); - for name in ["ab", n256.as_str()] { + for name in ["ab", n256.as_str(), n1025.as_str()] { for (op, body) in [ ( "CreateTable", diff --git a/crates/server/src/table_name_gate.rs b/crates/server/src/table_name_gate.rs index 04a136df2..8b10dbc2d 100644 --- a/crates/server/src/table_name_gate.rs +++ b/crates/server/src/table_name_gate.rs @@ -96,7 +96,11 @@ pub(crate) fn check_table_name_chars( "BatchGetItem" | "BatchWriteItem" => check_request_items_keys(operation, input), "TransactGetItems" => check_transact_items(input, &["Get"], false), "TransactWriteItems" => { - check_transact_items(input, &["Put", "Delete", "Update", "ConditionCheck"], true) + let subs = ["Put", "Delete", "Update", "ConditionCheck"]; + check_transact_items(input, &subs, true).or_else(|e| { + transact_member_bound(input, &subs)?; + Err(e) + }) } "TagResource" | "UntagResource" | "ListTagsOfResource" => { with_str(input, "ResourceArn", arn_gate::check_tag_resource_arn) @@ -335,6 +339,28 @@ fn check_transact_items( Ok(()) } +/// The names over 1024 characters in the `TransactItems` members `subs`. The +/// service answers them alone, ahead of a name outside the pattern and an ARN +/// that the ARN rules refuse (measured 2026-12-03), so they replace the +/// answer of [`check_transact_items`] when it refuses the request. As there, +/// the bounds are the service's. +fn transact_member_bound(input: &Value, subs: &[&str]) -> Result<(), DynamoDbError> { + let items = input.get("TransactItems").and_then(Value::as_array); + extenddb_core::validation::table_name_length::check_transact_member_bound( + items + .into_iter() + .flatten() + .enumerate() + .flat_map(|(i, item)| { + subs.iter().filter_map(move |sub| { + let name = item.get(sub)?.get("TableName")?.as_str()?; + Some((i, *sub, name)) + }) + }), + NAME_BOUNDS.1, + ) +} + #[cfg(test)] mod tests { use super::*; @@ -780,6 +806,12 @@ mod tests { let put = |t: &str| json!({ "Put": { "TableName": t, "Item": {} } }); let del = |t: &str| json!({ "Delete": { "TableName": t, "Key": {} } }); let n256 = "n".repeat(256); + // Measured 2026-12-03: a name over 1024 characters is answered alone. + let a1025 = "a".repeat(1025); + let over = + "1 validation error detected: Value at 'TransactItems.1.member.Delete.TableName' \ + failed to satisfy constraint: Member must have length less than or equal to 1024" + .to_owned(); let rows = [ ( "DescribeTable", @@ -804,6 +836,22 @@ mod tests { json!({ "TransactItems": [put("ab"), del(&n256)] }), None, ), + ( + "TransactWriteItems", + json!({ "TransactItems": [put("bad name"), del(&a1025)] }), + Some(over.clone()), + ), + ( + "TransactWriteItems", + json!({ "TransactItems": [put("arn:aws:s3:us-east-1:123456789012:table/abc"), + del(&a1025)] }), + Some(over), + ), + ( + "TransactWriteItems", + json!({ "TransactItems": [put("ab"), del(&a1025)] }), + None, + ), ("GetItem", json!({ "TableName": "ab" }), None), ( "BatchGetItem", diff --git a/crates/wasm-adapter/parity/corpus.json b/crates/wasm-adapter/parity/corpus.json index 84e4d908f..68358a60a 100644 --- a/crates/wasm-adapter/parity/corpus.json +++ b/crates/wasm-adapter/parity/corpus.json @@ -3692,6 +3692,25 @@ } ] }, + { + "name": "table names: GetItem with a 1025-character TableName outside the pattern answers the bound of the member", + "op": "GetItem", + "body": { + "TableName": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa!", + "Key": { + "pk": { + "S": "x" + } + } + }, + "error": "ValidationException", + "checks": [ + { + "path": "/message", + "equals": "1 validation error detected: Value at 'TableName' failed to satisfy constraint: Member must have length less than or equal to 1024" + } + ] + }, { "name": "table names: BatchWriteItem with a RequestItems key outside the pattern answers ResourceNotFoundException", "op": "BatchWriteItem", @@ -3744,6 +3763,56 @@ } ] }, + { + "name": "table names: BatchWriteItem with a 1025-character RequestItems key outside the pattern answers the map keys sentence of the member", + "op": "BatchWriteItem", + "body": { + "RequestItems": { + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa!": [ + { + "PutRequest": { + "Item": { + "pk": { + "S": "x" + } + } + } + } + ] + } + }, + "error": "ValidationException", + "checks": [ + { + "path": "/message", + "equals": "1 validation error detected: Value 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa!' at 'requestItems' failed to satisfy constraint: 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]" + } + ] + }, + { + "name": "table names: BatchGetItem with a 1025-character RequestItems key outside the pattern answers the bound of the member", + "op": "BatchGetItem", + "body": { + "RequestItems": { + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa!": { + "Keys": [ + { + "pk": { + "S": "x" + } + } + ] + } + } + }, + "error": "ValidationException", + "checks": [ + { + "path": "/message", + "equals": "1 validation error detected: Value at 'RequestItems.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa!' failed to satisfy constraint: Member must have length less than or equal to 1024" + } + ] + }, { "name": "table names: TransactWriteItems with a member TableName outside the pattern answers ResourceNotFoundException", "op": "TransactWriteItems", @@ -3794,6 +3863,41 @@ } ] }, + { + "name": "table names: TransactWriteItems with a 1025-character member TableName outside the pattern answers the bound of the member", + "op": "TransactWriteItems", + "body": { + "TransactItems": [ + { + "Put": { + "TableName": "a!", + "Item": { + "pk": { + "S": "x" + } + } + } + }, + { + "Put": { + "TableName": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa!", + "Item": { + "pk": { + "S": "x" + } + } + } + } + ] + }, + "error": "ValidationException", + "checks": [ + { + "path": "/message", + "equals": "1 validation error detected: Value at 'TransactItems.1.member.Put.TableName' failed to satisfy constraint: Member must have length less than or equal to 1024" + } + ] + }, { "name": "table names: PutItem with a TableName outside the pattern answers the pattern clause", "op": "PutItem", diff --git a/docs/webassembly.md b/docs/webassembly.md index 1834d654b..05ad4eb9f 100644 --- a/docs/webassembly.md +++ b/docs/webassembly.md @@ -298,7 +298,11 @@ check refuses, the answer is for the first of them in that order. On **table names** answer also lists every other member's name outside the pattern and every member's name shorter than 3 or longer than 255 characters, all in that order, up to the first ARN that the **table ARNs** -check refuses. +check refuses. A member's name over 1024 characters changes that answer on +both builds: it lists each such name alone, as "Value at +'TransactItems.<n>.member.<Op>.TableName' failed to satisfy constraint: +Member must have length less than or equal to 1024", with `` counted from 0 +and `` written as the request writes it. Three rows read a placeholder from elsewhere: the `ListBackups` row of **table ARNs** takes `` from the ARN's `table/` resource, **GetRecords iterator scope** takes `` from the @@ -333,9 +337,9 @@ someone edits it. | **body size** | any request whose body is over 16 MiB | `RequestEntityTooLargeException` (HTTP 413) "Request size has exceeded the maximum allowed size" | the request: it has no size limit, so `ListTables` with a 17 MiB body answers `{"TableNames":[]}` | | **signature** | a request without a SigV4 signature the server can verify with a key it issued and, outside developer mode, one its IAM policies do not allow | its authentication errors, such as `MissingAuthenticationToken`, `IncompleteSignatureException`, `UnrecognizedClientException` and `InvalidSignatureException`, and its authorization errors | the request, under account `000000000000` | | **table names** | a non-empty `TableName` outside the pattern (`bad name!`) on `Query`, `Scan`, `SearchVectors` and `UpdateTable` | `ValidationException` "1 validation error detected: Value '<name>' at 'tableName' failed to satisfy constraint: Member must satisfy regular expression pattern: [a-zA-Z0-9_.-]+"; for a name shorter than 3 or longer than 255 characters, "2 validation errors detected: ", the length clause ("Member must have length greater than or equal to 3" or "… less than or equal to 255") and then the pattern clause, joined by "; " | `ResourceNotFoundException` "Requested resource not found" | -| | a non-empty `RequestItems` key outside the pattern on `BatchGetItem` and `BatchWriteItem` | the same, at 'requestItems', with the constraint "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_.-]+]" | `ResourceNotFoundException` "Requested resource not found", except when a key is shorter than 3 or longer than 255 characters: then the engine's length check gives the same sentence, for the smallest such key in byte order | +| | a non-empty `RequestItems` key outside the pattern on `BatchGetItem` and `BatchWriteItem` | the same, at 'requestItems', with the constraint "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_.-]+]" | `ResourceNotFoundException` "Requested resource not found", except when a key is shorter than 3 or longer than 255 characters: then the engine's length check gives the same sentence, for the smallest such key in byte order. A key over 1024 characters gets the bound of the member instead: on `BatchGetItem` "1 validation error detected: Value at 'RequestItems.<key>' failed to satisfy constraint: Member must have length less than or equal to 1024", one clause for each such key in byte order, and on `BatchWriteItem` the sentence at 'requestItems' with the constraint "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]", for the smallest such key | | | a non-empty `TableName` outside the pattern in a `TransactItems` member on `TransactGetItems` and `TransactWriteItems` | the same, at 'transactItems.<n>.member.<op>.tableName', with `` counted from 1 and `` one of `get`, `put`, `delete`, `update` and `conditionCheck` | `ResourceNotFoundException` "Requested resource not found", except on `TransactWriteItems` when a member's name is shorter than 3 or longer than 255 characters: then the engine's length check gives the length clause alone for each such member, in member order | -| | a non-empty `TableName` outside the pattern on `GetItem`, `PutItem`, `UpdateItem`, `DeleteItem`, `CreateTable`, `DescribeTable`, `DeleteTable`, `DescribeTimeToLive` and `UpdateTimeToLive` | the answer at 'tableName' above | the engine's name check, which measures the name in bytes: for a name shorter than 3 or longer than 255 bytes, its length clause alone ("1 validation error detected: Value '<name>' at 'tableName' failed to satisfy constraint: Member must have length greater than or equal to 3", or "… less than or equal to 255"), and otherwise the pattern clause alone, which is the server's answer only when the name also has 3 to 255 characters (`éa`, 2 characters in 3 bytes, gets the pattern clause alone) | +| | a non-empty `TableName` outside the pattern on `GetItem`, `PutItem`, `UpdateItem`, `DeleteItem`, `CreateTable`, `DescribeTable`, `DeleteTable`, `DescribeTimeToLive` and `UpdateTimeToLive` | the answer at 'tableName' above | the engine's name check, which measures the name in bytes: for a name shorter than 3 or longer than 255 bytes, its length clause alone ("1 validation error detected: Value '<name>' at 'tableName' failed to satisfy constraint: Member must have length greater than or equal to 3", or "… less than or equal to 255"), and otherwise the pattern clause alone, which is the server's answer only when the name also has 3 to 255 characters (`éa`, 2 characters in 3 bytes, gets the pattern clause alone). On `GetItem` and `PutItem` a name over 1024 characters gets "1 validation error detected: Value at 'TableName' failed to satisfy constraint: Member must have length less than or equal to 1024" instead | | | a non-empty `TableName` outside the pattern on `DescribeContinuousBackups`, `UpdateContinuousBackups` and `ListBackups`, except an `UpdateContinuousBackups` that enables point-in-time recovery, which `admit` refuses first on both builds (see "What it refuses") | the answer at 'tableName' above | the same answer: their handlers count characters too | | | a non-empty `TableName` outside the pattern on `DescribeLimits` and `GetRecords`, which take none (nor do the operations this build refuses by name, under "What it refuses") | the answer at 'tableName' above | the operation's answer to the rest of the request: `DescribeLimits` answers its limits, and `GetRecords` answers for its `ShardIterator` | | | a non-empty `ExclusiveStartTableName` outside the pattern on `ListTables` (a value starting with `arn:` is refused only when it carries U+0000) | the same, at 'exclusiveStartTableName' | `ValidationException` "1 validation error detected: Value '<name>' at 'tableName' failed to satisfy constraint: Member must satisfy regular expression pattern: [a-zA-Z0-9_.-]+", with no length clause | diff --git a/tests/python/test_nul_table_names.py b/tests/python/test_nul_table_names.py index 5a3150f2d..c84900604 100644 --- a/tests/python/test_nul_table_names.py +++ b/tests/python/test_nul_table_names.py @@ -178,13 +178,13 @@ class TestNulInNestedTableNames: """ @staticmethod - def _request_items_error(exc: ClientError, key: str) -> None: + def _request_items_error(exc: ClientError, key: str, constraint: str = MAP_KEYS) -> None: resp = exc.response assert resp["ResponseMetadata"]["HTTPStatusCode"] == 400 assert resp["Error"]["Code"] == "ValidationException" msg = resp["Error"]["Message"] assert msg.startswith("1 validation error detected: Value '"), msg - assert msg.endswith(f"' at 'requestItems' failed to satisfy constraint: {MAP_KEYS}"), msg + assert msg.endswith(f"' at 'requestItems' failed to satisfy constraint: {constraint}"), msg value = msg[len("1 validation error detected: Value '") : msg.rindex("' at 'requestItems'")] assert key.replace(NUL, "") in value.replace(NUL, "").replace("\\u0000", ""), msg @@ -286,6 +286,12 @@ def test_tag_operations_with_nul_arn_segment_are_refused(self, raw_client, nul_a "1 validation error detected: Value at 'TableName' failed to satisfy constraint: " "Member must have length greater than or equal to 1" ) +A1024 = "a" * 1024 +A1025 = "a" * 1025 +MAP_KEYS_MEMBER = ( + "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]" +) def _at(value: str, location: str, clause: str) -> str: @@ -304,11 +310,26 @@ def _put(table: str, pk: str) -> dict: return {"Put": {"TableName": table, "Item": _key(pk)}} +def _over(location: str) -> str: + """A name over the 1024 characters of the TableName member.""" + return ( + f"1 validation error detected: Value at '{location}' failed to satisfy constraint: " + "Member must have length less than or equal to 1024" + ) + + +def _pk(pk: str) -> dict: + return {"pk": {"S": pk}} + + # Issue #1056: a table name shorter than 3 or longer than 255 characters, and # an empty one, measured on 2026-11-13, 2026-11-14 and 2026-11-18 (us-east-1). +# The rows from GetItem-over-1024 on were measured on 2026-12-03: a name over +# 1024 characters, and the faults that a name of a bad length comes ahead of. # Each row is (call, expected): a message, or ("requestItems", key) for the # map-key sentence, whose quoted value is compared as in -# TestNulInNestedTableNames. `t` is a table keyed on pk and sk. +# TestNulInNestedTableNames, with the constraint list as a third item when it +# is not MAP_KEYS. `t` is a table keyed on pk and sk. LENGTH_ROWS = [ pytest.param( lambda c, t: c.get_item(TableName="ab", Key={"pk": {"S": "a"}}), @@ -408,6 +429,65 @@ def _put(table: str, pk: str) -> dict: ("requestItems", "ab"), id="BatchWriteItem-short", ), + pytest.param( + lambda c, t: c.get_item(TableName=A1025, Key=_pk("a")), + _over("TableName"), + id="GetItem-over-1024", + ), + pytest.param( + lambda c, t: c.get_item(TableName=A1024, Key=_pk("a")), + _one(A1024, "tableName", LEN255), + id="GetItem-1024", + ), + pytest.param( + lambda c, t: c.put_item(TableName=A1025, Item=_pk("a")), + _over("TableName"), + id="PutItem-over-1024", + ), + pytest.param( + lambda c, t: c.batch_get_item( + RequestItems={"ab": {"Keys": [_pk("a")]}, A1025: {"Keys": [_pk("a")]}} + ), + _over(f"RequestItems.{A1025}"), + id="BatchGetItem-over-1024-beside-short", + ), + pytest.param( + lambda c, t: c.batch_write_item( + RequestItems={ + "ab": [{"PutRequest": {"Item": _pk("a")}}], + A1025: [{"PutRequest": {"Item": _pk("a")}}], + } + ), + ("requestItems", A1025, MAP_KEYS_MEMBER), + id="BatchWriteItem-over-1024-beside-short", + ), + pytest.param( + lambda c, t: c.transact_write_items( + TransactItems=[ + {"Put": {"TableName": "ab", "Item": _pk("a")}}, + {"Delete": {"TableName": A1025, "Key": _pk("b")}}, + ] + ), + _over("TransactItems.1.member.Delete.TableName"), + id="TransactWriteItems-over-1024-beside-short", + ), + pytest.param( + lambda c, t: c.transact_write_items( + TransactItems=[ + {"Put": {"TableName": "bad name", "Item": _pk("a")}}, + {"Delete": {"TableName": A1025, "Key": _pk("b")}}, + ] + ), + _over("TransactItems.1.member.Delete.TableName"), + id="TransactWriteItems-over-1024-beside-pattern", + ), + pytest.param( + lambda c, t: c.transact_write_items( + TransactItems=[{"Put": {"TableName": A1024, "Item": _pk("a")}}] + ), + _one(A1024, "transactItems.1.member.put.tableName", LEN255), + id="TransactWriteItems-1024", + ), ] @@ -443,6 +523,6 @@ def test_a_name_of_a_bad_length_is_refused(self, raw_client, keyed_table, call, with pytest.raises(ClientError) as exc: call(raw_client, keyed_table) if isinstance(expected, tuple): - TestNulInNestedTableNames._request_items_error(exc.value, expected[1]) + TestNulInNestedTableNames._request_items_error(exc.value, *expected[1:]) else: assert_validation(exc.value, expected) From 0806912392706052448e1c2917e1d2c90b9d7d8a Mon Sep 17 00:00:00 2001 From: Lee Hannigan <29015211+LeeroyHannigan@users.noreply.github.com> Date: Thu, 3 Dec 2026 09:17:29 +0000 Subject: [PATCH 6/7] fix(engine): check the table names ahead of the other request checks DynamoDB answers a table name of a bad length ahead of these faults (measured 2026-12-03, each request sent twice): - TransactWriteItems: a 65536-byte attribute name in a Put item, a 65536-byte ExpressionAttributeNames value, and an action with two members. - BatchWriteItem: a 65536-byte attribute name, a WriteRequest that holds no request, and a number that the service cannot read. A 37-character ClientRequestToken comes ahead of the name, and ahead of an action with two members. So TransactWriteItems now checks the token, then the names, then that each action holds one operation, and then the attribute name sizes. BatchWriteItem checks the keys after the counts and ahead of its other checks. The BatchWriteItem number row is a row of #1121, and the row of the token beside two members is a row of #1463. Both issues stay open for their other rows. --- crates/engine/src/batch_write_item.rs | 15 +++-- crates/engine/src/table_name_length_tests.rs | 64 ++++++++++++++++++++ crates/engine/src/transact_write_items.rs | 40 ++++++------ tests/python/test_nul_table_names.py | 53 ++++++++++++++++ 4 files changed, 149 insertions(+), 23 deletions(-) diff --git a/crates/engine/src/batch_write_item.rs b/crates/engine/src/batch_write_item.rs index 8cc7f4477..ee20d4dbe 100755 --- a/crates/engine/src/batch_write_item.rs +++ b/crates/engine/src/batch_write_item.rs @@ -58,6 +58,15 @@ pub async fn handle_batch_write_item( .collect(); request_limits::check_batch_counts("BatchWriteItem", &counts)?; + // A key of a bad length comes ahead of a WriteRequest that holds no + // request, an attribute name over the size limit and a number the service + // cannot read (measured 2026-12-03). + extenddb_core::validation::table_name_length::validate_request_items_keys( + "BatchWriteItem", + input.request_items.keys(), + &ctx.limits, + )?; + // Validate: each WriteRequest has exactly one of PutRequest or DeleteRequest for reqs in input.request_items.values() { for wr in reqs { @@ -93,12 +102,6 @@ pub async fn handle_batch_write_item( // both, the service answered either fault (measured 2026-11-11). extenddb_core::validation::number::operations::batch_write_item(&input)?; - extenddb_core::validation::table_name_length::validate_request_items_keys( - "BatchWriteItem", - input.request_items.keys(), - &ctx.limits, - )?; - // Read every table's key info before anything is written. A lookup that // failed is reported where `check_batch` reaches its table, so the first // fault reported is the one the checks reach first. diff --git a/crates/engine/src/table_name_length_tests.rs b/crates/engine/src/table_name_length_tests.rs index 095658aa3..cc3dcdf54 100644 --- a/crates/engine/src/table_name_length_tests.rs +++ b/crates/engine/src/table_name_length_tests.rs @@ -59,6 +59,69 @@ fn member(locations: &[&str], clause: &str) -> Option { Some(extenddb_core::error::validation_errors_detected(&clauses)) } +/// The rows of the order of the name checks (measured 2026-12-03): a name of +/// a bad length is answered ahead of the faults that follow it in each row, +/// and a 37-character `ClientRequestToken` ahead of the name. +fn order_rows() -> Vec<(&'static str, Value, Option)> { + let x65536 = "x".repeat(65536); + let token = "t".repeat(37); + let token_fault = member( + &["ClientRequestToken"], + "Member must have length less than or equal to 36", + ); + let ab_put = one("ab", "transactItems.1.member.put.tableName", LEN3); + let ab_key = one("ab", "requestItems", MAP_KEYS); + let twi = |items: Value| json!({ "TransactItems": items }); + let bwi = |requests: Value| json!({ "RequestItems": { "ab": requests } }); + vec![ + ( + "TransactWriteItems", + twi(json!([{ "Put": { "TableName": "ab", + "Item": { "pk": { "S": "a" }, x65536.as_str(): { "S": "v" } } } }])), + ab_put.clone(), + ), + ( + "TransactWriteItems", + twi(json!([{ "Update": { "TableName": "ab", "Key": key("a"), + "UpdateExpression": "SET #n = :v", "ExpressionAttributeNames": { "#n": x65536 }, + "ExpressionAttributeValues": { ":v": { "S": "x" } } } }])), + one("ab", "transactItems.1.member.update.tableName", LEN3), + ), + ( + "TransactWriteItems", + twi(json!([{ "Put": { "TableName": "ab", "Item": key("a") }, + "Delete": { "TableName": "abc", "Key": key("a") } }])), + ab_put, + ), + ( + "TransactWriteItems", + json!({ "ClientRequestToken": token, + "TransactItems": [{ "Put": { "TableName": "ab", "Item": key("a") } }] }), + token_fault.clone(), + ), + ( + "TransactWriteItems", + json!({ "ClientRequestToken": token, "TransactItems": [{ + "Put": { "TableName": "abc", "Item": key("a") }, + "Delete": { "TableName": "abc", "Key": key("a") } }] }), + token_fault, + ), + ( + "BatchWriteItem", + bwi( + json!([{ "PutRequest": { "Item": { "pk": { "S": "a" }, x65536.as_str(): { "S": "v" } } } }]), + ), + ab_key.clone(), + ), + ("BatchWriteItem", bwi(json!([{}])), ab_key.clone()), + ( + "BatchWriteItem", + bwi(json!([{ "PutRequest": { "Item": { "pk": { "S": "a" }, "v": { "N": "x" } } } }])), + ab_key, + ), + ] +} + /// `None` stands for `SerializationException`: the service answers a member /// of the wrong type ahead of the name, with a message ExtendDB does not /// match. @@ -139,6 +202,7 @@ fn rows() -> Vec<(&'static str, Value, Option)> { one(&a1024, "transactItems.1.member.put.tableName", LEN255), ), ]; + rows.extend(order_rows()); rows.extend(vec![ ( "GetItem", diff --git a/crates/engine/src/transact_write_items.rs b/crates/engine/src/transact_write_items.rs index bf1f7628b..ad0f6876b 100755 --- a/crates/engine/src/transact_write_items.rs +++ b/crates/engine/src/transact_write_items.rs @@ -69,6 +69,29 @@ pub async fn handle_transact_write_items( // before authorization. request_limits::check_transact_count(input.transact_items.len(), "TransactWriteItem")?; + // The client request token's length is checked after the item count and + // the enum members read during deserialization, and ahead of the table + // names, the one-operation check and each item's own checks (measured + // 2026-10-27: a 37-character token is reported ahead of a missing table, + // a condition syntax error and a malformed key number; measured + // 2026-11-11: ahead of an attribute name over the size limit and a + // number the service cannot read; measured 2026-12-03: ahead of a table + // name of 2 characters and an action with two members). DynamoDB checks + // it ahead of the count and the enum members too, and lists it with a + // count fault or a table name over 1024 characters in one message + // (measured 2026-11-24 and 2026-12-03). + if let Some(ref token) = input.client_request_token { + validate_client_request_token(token)?; + } + + // A table name of a bad length comes ahead of an action with two members, + // an attribute name over the size limit and an `ExpressionAttributeNames` + // value over it (measured 2026-12-03). + extenddb_core::validation::table_name_length::validate_transact_write_names( + &input.transact_items, + &ctx.limits, + )?; + // Validate each item has exactly one operation for (i, twi) in input.transact_items.iter().enumerate() { let count = [ @@ -87,18 +110,6 @@ pub async fn handle_transact_write_items( } } - // The client request token's length is checked after the item count, - // the one-operation check above and the enum members read during - // deserialization, and ahead of each item's own checks (measured - // 2026-10-27: a 37-character token is reported ahead of a missing table, - // a condition syntax error and a malformed key number; measured - // 2026-11-11: ahead of an attribute name over the size limit and a - // number the service cannot read). DynamoDB checks it ahead of all three, - // and lists it with a count fault in one message (measured 2026-11-24). - if let Some(ref token) = input.client_request_token { - validate_client_request_token(token)?; - } - // Attribute names over the size limit are request-shape validation of // each member, run for every member in request order before any member's // table lookup: a request whose first member names a missing table @@ -107,11 +118,6 @@ pub async fn handle_transact_write_items( validate_member_attribute_name_sizes(twi, &ctx.limits)?; } - extenddb_core::validation::table_name_length::validate_transact_write_names( - &input.transact_items, - &ctx.limits, - )?; - // Resolve table key info, validate inputs, parse expressions, and check // for duplicate targets — all in a single pass to avoid redundant // `table_key_info` lookups. diff --git a/tests/python/test_nul_table_names.py b/tests/python/test_nul_table_names.py index c84900604..3a3c0f081 100644 --- a/tests/python/test_nul_table_names.py +++ b/tests/python/test_nul_table_names.py @@ -288,6 +288,7 @@ def test_tag_operations_with_nul_arn_segment_are_refused(self, raw_client, nul_a ) A1024 = "a" * 1024 A1025 = "a" * 1025 +X65536 = "x" * 65536 MAP_KEYS_MEMBER = ( "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]" @@ -488,6 +489,58 @@ def _pk(pk: str) -> dict: _one(A1024, "transactItems.1.member.put.tableName", LEN255), id="TransactWriteItems-1024", ), + pytest.param( + lambda c, t: c.transact_write_items( + TransactItems=[{"Put": {"TableName": "ab", "Item": {**_pk("a"), X65536: {"S": "v"}}}}] + ), + _one("ab", "transactItems.1.member.put.tableName", LEN3), + id="TransactWriteItems-short-before-attribute-name", + ), + pytest.param( + lambda c, t: c.transact_write_items( + TransactItems=[ + { + "Update": { + "TableName": "ab", + "Key": _pk("a"), + "UpdateExpression": "SET #n = :v", + "ExpressionAttributeNames": {"#n": X65536}, + "ExpressionAttributeValues": {":v": {"S": "x"}}, + } + } + ] + ), + _one("ab", "transactItems.1.member.update.tableName", LEN3), + id="TransactWriteItems-short-before-expression-name", + ), + pytest.param( + lambda c, t: c.transact_write_items( + TransactItems=[ + { + "Put": {"TableName": "ab", "Item": _pk("a")}, + "Delete": {"TableName": f"{t}-absent", "Key": _pk("a")}, + } + ] + ), + _one("ab", "transactItems.1.member.put.tableName", LEN3), + id="TransactWriteItems-short-before-two-members", + ), + pytest.param( + lambda c, t: c.transact_write_items( + ClientRequestToken="t" * 37, + TransactItems=[{"Put": {"TableName": "ab", "Item": _pk("a")}}], + ), + "1 validation error detected: Value at 'ClientRequestToken' failed to satisfy constraint: " + "Member must have length less than or equal to 36", + id="TransactWriteItems-token-before-short", + ), + pytest.param( + lambda c, t: c.batch_write_item( + RequestItems={"ab": [{"PutRequest": {"Item": {**_pk("a"), X65536: {"S": "v"}}}}]} + ), + ("requestItems", "ab"), + id="BatchWriteItem-short-before-attribute-name", + ), ] From 16de95b24dec556d5c14d97b82009db97015fad7 Mon Sep 17 00:00:00 2001 From: Lee Hannigan <29015211+LeeroyHannigan@users.noreply.github.com> Date: Thu, 3 Dec 2026 09:18:06 +0000 Subject: [PATCH 7/7] docs: add the v1.2.0 upgrade entry of the table name checks The upgrade manual lists the answers that change with this branch. GetItem, BatchGetItem, BatchWriteItem and TransactWriteItems refuse a table name of a bad length before the lookup. A name over 1024 characters gets the member bound, and an empty name gets the texts of DynamoDB. The name checks come ahead of the other request checks. The entry goes above the v1.2.0 entries of main, as the newest one. --- docs/manuals/07-upgrade-manual.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/docs/manuals/07-upgrade-manual.md b/docs/manuals/07-upgrade-manual.md index feeabbd76..8c3e159aa 100755 --- a/docs/manuals/07-upgrade-manual.md +++ b/docs/manuals/07-upgrade-manual.md @@ -392,6 +392,17 @@ Catalog upgrades change the schema; behavior changes alter how the running serve interprets existing data or configuration. Review these before upgrading a live deployment, even when no catalog migration is required. +### v1.2.0: item and batch requests refuse a table name of a bad length before the lookup + +**What changed** (#1127, refs #1056). GetItem, BatchGetItem, BatchWriteItem and TransactWriteItems refuse a table name of a bad length with `ValidationException` and DynamoDB's texts (measured 2026-11-13 to 2026-12-03). 1.1.0 answered `ResourceNotFoundException`, `Requested resource not found`, after the table lookup. On every backend: + +- A name outside the deployment's `[limits]` bounds, 3 and 255 characters by default, gets the length clause at `tableName` in GetItem. BatchGetItem and BatchWriteItem give the map-key sentence at `requestItems`. TransactWriteItems lists the length clause of each such action at `transactItems..member..tableName`. +- A name over 1024 characters gets `Value at '' failed to satisfy constraint: Member must have length less than or equal to 1024`, with no value quoted, at `TableName`, `RequestItems.` or `TransactItems..member..TableName`. BatchWriteItem gives the map-key sentence with the list `[Member must have length less than or equal to 1024, Member must have length greater than or equal to 1]`. PutItem gives this answer too, where 1.1.0 gave the 255 clause. A deployment whose `max_table_name_length` is above 1024 takes that maximum as the bound. +- An empty name in GetItem and PutItem gets `1 validation error detected: Value at 'TableName' failed to satisfy constraint: Member must have length greater than or equal to 1`. An empty DescribeTable name gets the length clause and the pattern clause in one message, before authorization. +- TransactWriteItems checks the names after the `ClientRequestToken` and ahead of the check that each action holds one operation, and ahead of the attribute name sizes. The token comes ahead of that check too. BatchWriteItem checks the keys ahead of a WriteRequest that holds no request, the attribute name sizes and the numbers. 1.1.0 answered those other faults. + +**Who is affected.** Clients that match `ResourceNotFoundException` for such a name, or the texts that 1.1.0 gave to the requests above. No catalog migration or configuration change is required. After a rollback to 1.1.0 the earlier answers return. + ### v1.2.0: on MongoDB, a DELETING table keeps its tags for `aws:ResourceTag` until its catalog document goes **What changed** (#604). On MongoDB, DeleteTable removes a table's tags and its catalog document in one transaction, as its last step. 1.1.0 removed the tags before the stream cleanup and the catalog delete, so for that part of the `DELETING` window, and after a DeleteTable that stopped there, a request whose policy reads `aws:ResourceTag` (DescribeTable, a second DeleteTable) found none of the table's tags when the server read them from storage. 1.2.0 finds them until the document goes. ListTagsOfResource is not affected: it answers `ResourceNotFoundException` for a table that is not `ACTIVE`, as in 1.1.0.