diff --git a/crates/core/src/error/messages.rs b/crates/core/src/error/messages.rs index 5bbe22e92..b16bbb546 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 { @@ -71,12 +73,8 @@ 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() } diff --git a/crates/core/src/validation/mod.rs b/crates/core/src/validation/mod.rs index 697ea0732..de99679c3 100755 --- a/crates/core/src/validation/mod.rs +++ b/crates/core/src/validation/mod.rs @@ -25,6 +25,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..f99784917 --- /dev/null +++ b/crates/core/src/validation/table_name_length.rs @@ -0,0 +1,280 @@ +// Copyright 2026 ExtendDB contributors +// SPDX-License-Identifier: Apache-2.0 + +//! A table name of a bad length, in the operations that look a table up by +//! it. These checks take the deployment's `[limits]` bounds, 3 to 255 +//! characters by default, as [`validate_table_name`] does. +//! +//! The service refuses such a name with `ValidationException` before the +//! lookup, and answers a member of the wrong JSON type ahead of it: `GetItem`, +//! `BatchGetItem`, `BatchWriteItem` and `TransactWriteItems` answered +//! `SerializationException` for a short name beside a member of the wrong +//! type (measured 2026-11-18). So the handlers run these checks after the +//! request is read and before the first lookup. A name outside the pattern is +//! refused earlier, before authorization, by the server's table name gate, +//! which writes its length clauses with [`length_clause`] and the service's +//! bounds. +//! +//! An empty name gets other sentences from the service, which these checks +//! leave to the code after them, except in `GetItem` and `PutItem`. +//! +//! Ahead of those bounds the service checks the bound of the `TableName` +//! member, which also takes a table ARN: 1024 characters at most. A name over +//! it gets that clause, with no value quoted, at the member as the request +//! names it: `TableName`, `RequestItems.` 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, validation_error, validation_errors, validation_errors_detected, +}; +use crate::limits::LimitsConfig; +use crate::types::TransactWriteItem; + +use super::validate_table_name; + +/// The constraint list of a `RequestItems` key that is not a table name the +/// service accepts (measured 2026-10-24 for a key outside the pattern and +/// 2026-11-18 for a key of a bad length). +pub const MAP_KEYS_NAME: &str = "Map keys must satisfy constraint: \ + [Member must have length less than or equal to 255, \ + Member must have length greater than or equal to 3, \ + Member must satisfy regular expression pattern: [a-zA-Z0-9_.-]+]"; + +/// The clause of a table name under the minimum length. It names the +/// service's minimum, 3, whatever the deployment's is, as the sentence of +/// [`validate_table_name`] does. +pub(crate) const TOO_SHORT: &str = "Member must have length greater than or equal to 3"; + +/// The clause of a table name over the maximum length, which names the +/// service's maximum, 255, in the same way. +pub(crate) const TOO_LONG: &str = "Member must have length less than or equal to 255"; + +/// The bound of the `TableName` member, in characters. +const MEMBER_MAX: usize = 1024; + +/// The clauses of the `TableName` member's bounds. +const MEMBER_TOO_SHORT: &str = "Member must have length greater than or equal to 1"; +const MEMBER_TOO_LONG: &str = "Member must have length less than or equal to 1024"; + +/// The constraint list of a `BatchWriteItem` `RequestItems` key over the +/// member's bound (measured 2026-12-03). +const MAP_KEYS_MEMBER: &str = "Map keys must satisfy constraint: \ + [Member must have length less than or equal to 1024, \ + Member must have length greater than or equal to 1]"; + +/// The length clause a table name fails under the bounds `(min, max)`, in +/// characters, or `None` for a name within them. +#[must_use] +pub fn length_clause(name: &str, (min, max): (usize, usize)) -> Option<&'static str> { + match name.chars().count() { + n if n < min => Some(TOO_SHORT), + n if n > max => Some(TOO_LONG), + _ => None, + } +} + +/// The deployment's table name bounds `(min, max)`: the `[limits]` values +/// `min_table_name_length` and `max_table_name_length`, 3 and 255 by default. +#[must_use] +pub fn table_name_bounds(limits: &LimitsConfig) -> (usize, usize) { + (limits.min_table_name_length, limits.max_table_name_length) +} + +/// Where the service reports the table name of a `TransactItems` action: +/// `transactItems..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) +} + +/// 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 and a name over 1024 characters in both +/// with `Value at 'TableName'` and the member's bound (measured 2026-11-18 +/// and 2026-12-03). Any other name gets the answer of +/// [`validate_table_name`]. +/// +/// # Errors +/// +/// `ValidationException` for a name outside the member's bounds or one that +/// [`validate_table_name`] refuses. +pub fn validate_item_table_name(name: &str, limits: &LimitsConfig) -> Result<(), DynamoDbError> { + let constraint = if name.is_empty() { + MEMBER_TOO_SHORT + } else if over_member_bound(name, limits.max_table_name_length) { + MEMBER_TOO_LONG + } else { + return validate_table_name(name, limits); + }; + Err(member_error([("TableName".to_owned(), constraint)])) +} + +/// A `RequestItems` key of a bad length in `operation`, `BatchGetItem` or +/// `BatchWriteItem`. A key over 1024 characters gets the member's bound (see +/// the module comment); any other gets the map-key sentence at +/// `requestItems`. Where the service quotes its rendering of the whole map in +/// `Value '...'`, this renders the key alone, as the server's table name gate +/// does for a key outside the pattern. An empty key and a table ARN are left +/// to the code after this. +/// +/// # Errors +/// +/// `ValidationException`. The keys come from a `HashMap`, whose order +/// changes from one request to the next, so they are taken in sorted order: +/// a sentence that quotes one key quotes the smallest, and `BatchGetItem` +/// lists the keys over 1024 characters sorted, where the service listed two +/// of them in either order. +pub fn validate_request_items_keys<'a>( + operation: &str, + keys: impl IntoIterator, + limits: &LimitsConfig, +) -> Result<(), DynamoDbError> { + let mut keys: Vec<&str> = keys + .into_iter() + .map(String::as_str) + .filter(|k| !k.is_empty() && !k.starts_with("arn:")) + .collect(); + keys.sort_unstable(); + let over: Vec<&str> = keys + .iter() + .copied() + .filter(|k| over_member_bound(k, limits.max_table_name_length)) + .collect(); + if let Some(key) = over.first() { + return Err(if operation == "BatchWriteItem" { + DynamoDbError::ValidationException(validation_error( + key, + "requestItems", + MAP_KEYS_MEMBER, + )) + } else { + member_error( + over.iter() + .map(|k| (format!("RequestItems.{k}"), MEMBER_TOO_LONG)), + ) + }); + } + let bounds = table_name_bounds(limits); + if let Some(key) = keys.iter().find(|k| length_clause(k, bounds).is_some()) { + return Err(DynamoDbError::ValidationException(validation_error( + key, + "requestItems", + MAP_KEYS_NAME, + ))); + } + Ok(()) +} + +/// The `TransactItems` names over 1024 characters and over the deployment's +/// maximum `max`, each `(action index, member, name)` with the member as the +/// request writes it (`Put`), in the order given, at +/// `TransactItems..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 names over 1024 characters (see +/// [`check_transact_member_bound`]), or else every action's fault of the +/// deployment's bounds in one message, in action order (measured +/// 2026-11-18). An empty name and a table ARN are left to the code after +/// this. +/// +/// # Errors +/// +/// `ValidationException` listing each such name. +pub fn validate_transact_write_names( + items: &[TransactWriteItem], + limits: &LimitsConfig, +) -> Result<(), DynamoDbError> { + let mut names: Vec<(usize, &str, &str)> = Vec::new(); + for (i, item) in items.iter().enumerate() { + let members = [ + ( + "ConditionCheck", + item.condition_check.as_ref().map(|o| &o.table_name), + ), + ("Put", item.put.as_ref().map(|o| &o.table_name)), + ("Delete", item.delete.as_ref().map(|o| &o.table_name)), + ("Update", item.update.as_ref().map(|o| &o.table_name)), + ]; + for (member, name) in members { + if let Some(name) = name.filter(|n| !n.is_empty() && !n.starts_with("arn:")) { + names.push((i, member, name)); + } + } + } + check_transact_member_bound(names.iter().copied(), limits.max_table_name_length)?; + let bounds = table_name_bounds(limits); + let located: Vec<(&str, String, &str)> = names + .iter() + .filter_map(|&(i, member, name)| { + Some(( + name, + transact_name_location(i, member), + length_clause(name, bounds)?, + )) + }) + .collect(); + if located.is_empty() { + return Ok(()); + } + let faults: Vec<(&str, &str, &str)> = located + .iter() + .map(|(name, location, clause)| (*name, location.as_str(), *clause)) + .collect(); + Err(DynamoDbError::ValidationException(validation_errors( + &faults, + ))) +} diff --git a/crates/engine/src/backup_requests.rs b/crates/engine/src/backup_requests.rs index 8ca775c97..b4058c40c 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_core::validation::validate_name_member; use extenddb_storage::backup_catalog::TimeBounds; use extenddb_storage::error::StorageError; @@ -87,13 +88,6 @@ pub(crate) fn required_str<'a>( }) } -/// The length bounds for a `TableName` member: the deployment's, which -/// default to the model's 3 to 255. `CreateTable` takes the same bounds, so a -/// table the deployment could create can be backed up and listed. -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 diff --git a/crates/engine/src/batch_get_item.rs b/crates/engine/src/batch_get_item.rs index 263ce6c0b..05e9b1fd8 100755 --- a/crates/engine/src/batch_get_item.rs +++ b/crates/engine/src/batch_get_item.rs @@ -165,6 +165,12 @@ 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( + "BatchGetItem", + 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..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 { 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 d3439eb8a..f83f83d24 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 e14b530ae..238fbd646 100644 --- a/crates/engine/src/partiql/test_context.rs +++ b/crates/engine/src/partiql/test_context.rs @@ -16,7 +16,7 @@ use extenddb_core::error::DynamoDbError; use crate::{ItemAccess, ItemAuthorization, ItemAuthorizer, OperationContext}; /// 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() @@ -25,7 +25,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 mut ctx = crate::test_context::context_on(crate::test_context::memory_engine().await, "000000000000"); ctx.authorized_key_info.insert("t".to_owned(), None); diff --git a/crates/engine/src/put_item.rs b/crates/engine/src/put_item.rs index 39b708ea0..3f7ecb7e3 100755 --- a/crates/engine/src/put_item.rs +++ b/crates/engine/src/put_item.rs @@ -31,12 +31,10 @@ 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)?; - } else if body - .get("TableName") - .is_some_and(serde_json::Value::is_string) - { - // empty string — caught by validate_table_name above + extenddb_core::validation::table_name_length::validate_item_table_name( + table_name, + &ctx.limits, + )?; } 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..cc3dcdf54 --- /dev/null +++ b/crates/engine/src/table_name_length_tests.rs @@ -0,0 +1,335 @@ +// Copyright 2026 ExtendDB contributors +// SPDX-License-Identifier: Apache-2.0 + +//! 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, +//! 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; + +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 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}") +} + +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" } }) +} + +/// 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)) +} + +/// 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. +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) } }); + 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(order_rows()); + rows.extend(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, + ), + ]); + rows +} + +#[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 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 { + 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: 1100, + ..LimitsConfig::default() + }), + account_id: Arc::from(account_id), + ..context(None).await + }; + let (n256, n1025) = ("n".repeat(256), "n".repeat(1025)); + let item = json!({ "pk": { "S": "a" } }); + for name in ["ab", n256.as_str(), n1025.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 0405baa97..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 diff --git a/crates/server/src/table_name_gate.rs b/crates/server/src/table_name_gate.rs index 5ab9ebda7..b5c3ef1a7 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,13 @@ 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"]) + 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) @@ -188,10 +199,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 @@ -209,7 +217,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)) @@ -234,29 +244,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 @@ -292,11 +303,24 @@ 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), 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], + 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 @@ -309,27 +333,48 @@ 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)); } } } + if outside { + return Err(bare_names_error(&names)); + } 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(), - } +/// 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)] @@ -750,7 +795,7 @@ mod tests { let m = message( "TransactWriteItems", json!({ "TransactItems": [ - { "Put": { "TableName": "ok", "Item": {} } }, + { "Put": { "TableName": "okay", "Item": {} } }, { "Delete": { "TableName": NUL, "Key": {} } }, ] }), ) @@ -798,4 +843,96 @@ 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); + // 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", + 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, + ), + ( + "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", + 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/crates/wasm-adapter/parity/corpus.json b/crates/wasm-adapter/parity/corpus.json index ff2303048..afdd81dbc 100644 --- a/crates/wasm-adapter/parity/corpus.json +++ b/crates/wasm-adapter/parity/corpus.json @@ -2592,7 +2592,7 @@ ] }, { - "name": "table names: GetItem with a TableName outside the pattern answers ResourceNotFoundException", + "name": "table names: GetItem with a TableName outside the pattern answers the pattern clause", "op": "GetItem", "body": { "TableName": "bad name!", @@ -2602,11 +2602,11 @@ } } }, - "error": "ResourceNotFoundException", + "error": "ValidationException", "checks": [ { "path": "/message", - "equals": "Requested resource not found" + "equals": "1 validation error detected: Value 'bad name!' at 'tableName' failed to satisfy constraint: Member must satisfy regular expression pattern: [a-zA-Z0-9_.-]+" } ] }, @@ -3671,7 +3671,7 @@ ] }, { - "name": "table names: GetItem with a two-character TableName outside the pattern answers ResourceNotFoundException", + "name": "table names: GetItem with a two-character TableName outside the pattern answers the length clause alone", "op": "GetItem", "body": { "TableName": "a!", @@ -3681,16 +3681,16 @@ } } }, - "error": "ResourceNotFoundException", + "error": "ValidationException", "checks": [ { "path": "/message", - "equals": "Requested resource not found" + "equals": "1 validation error detected: Value 'a!' at 'tableName' failed to satisfy constraint: Member must have length greater than or equal to 3" } ] }, { - "name": "table names: GetItem with a 301-character TableName outside the pattern answers ResourceNotFoundException", + "name": "table names: GetItem with a 301-character TableName outside the pattern answers the length clause alone", "op": "GetItem", "body": { "TableName": "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy!", @@ -3700,11 +3700,30 @@ } } }, - "error": "ResourceNotFoundException", + "error": "ValidationException", "checks": [ { "path": "/message", - "equals": "Requested resource not found" + "equals": "1 validation error detected: Value 'yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy!' at 'tableName' failed to satisfy constraint: Member must have length less than or equal to 255" + } + ] + }, + { + "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" } ] }, @@ -3734,6 +3753,82 @@ } ] }, + { + "name": "table names: BatchWriteItem with a two-character RequestItems key outside the pattern answers the map keys sentence", + "op": "BatchWriteItem", + "body": { + "RequestItems": { + "a!": [ + { + "PutRequest": { + "Item": { + "pk": { + "S": "x" + } + } + } + } + ] + } + }, + "error": "ValidationException", + "checks": [ + { + "path": "/message", + "equals": "1 validation error detected: Value 'a!' at 'requestItems' failed to satisfy 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_.-]+]" + } + ] + }, + { + "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", @@ -3759,6 +3854,66 @@ } ] }, + { + "name": "table names: TransactWriteItems with a two-character member TableName outside the pattern answers the length clause alone", + "op": "TransactWriteItems", + "body": { + "TransactItems": [ + { + "Put": { + "TableName": "a!", + "Item": { + "pk": { + "S": "x" + } + } + } + } + ] + }, + "error": "ValidationException", + "checks": [ + { + "path": "/message", + "equals": "1 validation error detected: Value 'a!' at 'transactItems.1.member.put.tableName' failed to satisfy constraint: Member must have length greater than or equal to 3" + } + ] + }, + { + "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", @@ -4000,7 +4155,7 @@ ] }, { - "name": "table names: GetItem with an empty TableName answers ResourceNotFoundException", + "name": "table names: GetItem with an empty TableName answers the length clause at TableName", "op": "GetItem", "body": { "TableName": "", @@ -4010,11 +4165,25 @@ } } }, - "error": "ResourceNotFoundException", + "error": "ValidationException", "checks": [ { "path": "/message", - "equals": "Requested resource not found" + "equals": "1 validation error detected: Value at 'TableName' failed to satisfy constraint: Member must have length greater than or equal to 1" + } + ] + }, + { + "name": "table names: DescribeTable with an empty TableName answers the length clause of an empty name", + "op": "DescribeTable", + "body": { + "TableName": "" + }, + "error": "ValidationException", + "checks": [ + { + "path": "/message", + "equals": "1 validation error detected: Value '' at 'tableName' failed to satisfy constraint: Member must have length greater than or equal to 1" } ] }, diff --git a/docs/manuals/07-upgrade-manual.md b/docs/manuals/07-upgrade-manual.md index f970cf6c9..db4b9217e 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: UpdateTable and DescribeTable answer `UPDATING` while a change applies, and UpdateTable refuses a second capacity change in that time **What changed** (#1093, closes #1043). Two answers change, as DynamoDB gives them (measured 2026-11-13, 2026-11-14 and 2026-11-17): diff --git a/docs/manuals/10-security-model.md b/docs/manuals/10-security-model.md index ba0740c35..1603c7f6b 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. diff --git a/docs/webassembly.md b/docs/webassembly.md index e7dc53e04..05ad4eb9f 100644 --- a/docs/webassembly.md +++ b/docs/webassembly.md @@ -293,14 +293,24 @@ MongoDB backend, whose `bson` dependency turns on `serde_json`'s reads `TransactItems` members in order, and within a member its `Put`, `Delete`, `Update` and `ConditionCheck` in that order. Where a batch or transaction sends several values that the **table names** or **table ARNs** -check refuses, the answer is for the first of them in that order. +check refuses, the answer is for the first of them in that order. On +`TransactWriteItems`, when that value is a name outside the pattern, the +**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. 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 iterator's ARN field, and **accounts** says what its ``, `` and `` stand for. "The pattern" is `[a-zA-Z0-9_.-]+`. The **table names** and **index names** checks pass a name that is empty, missing or not a string, -so their rows cover only non-empty names. This build's answer +except an empty `DescribeTable` name, so their rows cover only non-empty names +and that one. This build's answer is the one to a request that is otherwise well formed. The server makes these checks before the handler reads the rest of the body, so where the rest of the body is something the handler refuses, this build gives the handler's error for @@ -326,16 +336,17 @@ 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 `GetItem`, `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" | -| | 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" | -| | a non-empty `TableName` outside the pattern on `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) | +| **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 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). 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 | | | a non-empty `TableCreationParameters.TableName` outside the pattern on `ImportTable` (as above for `arn:`) | the same, at 'tableCreationParameters.tableName' | `ValidationException` "Import is disabled. Configure [import] paths in extenddb.toml to enable." | | | a non-empty `TargetTableName` outside the pattern on `RestoreTableFromBackup` (as above for `arn:`); the server checks the `BackupArn` first (see **BackupArn kind**) | the same, at 'targetTableName' | the refusal of the operation (see "What it refuses") | | | a non-empty `TableName` on `ListStreams` that is outside the pattern, has 1, 2 or more than 255 characters, or is an ARN | `ValidationException` "TableName must be at least 3 characters long and at most 255 characters long" | `{"Streams":[]}` | +| | an empty `TableName` on `DescribeTable` | `ValidationException` "2 validation errors detected: Value '' at 'tableName' failed to satisfy constraint: Member must have length greater than or equal to 3; Value '' at 'tableName' failed to satisfy constraint: Member must satisfy regular expression pattern: [a-zA-Z0-9_.-]+" | `ValidationException` "1 validation error detected: Value '' at 'tableName' failed to satisfy constraint: Member must have length greater than or equal to 1" | | **index names** | a non-empty `IndexName` outside the pattern (`bad index!`) on `Query`, `Scan` and `SearchVectors` | `ValidationException` "1 validation error detected: Value '<name>' at 'indexName' failed to satisfy constraint: Member must satisfy regular expression pattern: [a-zA-Z0-9_.-]+" | `ValidationException` "The table does not have the specified index: <name>", and `ResourceNotFoundException` "Requested resource not found" when the table does not exist | | **table ARNs** | a `TableName`, a `RequestItems` key or a `TransactItems` member's `TableName` that starts with `arn:` and is not a plain table ARN (`arn:bogus`, an index, stream or backup ARN), names another vendor (`arn:aws:s3:…:table/T`), has a region with a character outside `[a-z0-9-]`, a table segment outside the pattern, or an account segment that is not 12 digits; on `GetItem`, `Query`, `Scan`, `SearchVectors`, `UpdateTable`, `BatchGetItem`, `BatchWriteItem`, `TransactGetItems` and `TransactWriteItems` | `ValidationException` "1 validation error detected: Value '<arn>' at '<member>' failed to satisfy constraint: <reason>", with the first of these reasons that applies: "Valid ARN format is 'arn:<awsPartition>:<vendor>:<region>:<subscriber>:resourceType/resourceName', …", "Invalid vendor code", "Invalid AWS region", "Table name of ARN must satisfy regular expression pattern: [a-zA-Z0-9_.-]+", "Invalid subscriber ID"; at 'requestItems' the constraint is "Map keys must satisfy constraint: [Valid resource name or resource arn must be given. …]". On `BatchWriteItem` an account fault gets the **accounts** answer instead, unless the account carries U+0000. On `CreateTable`, `DescribeTable`, `UpdateTable`, `DeleteTable`, `DescribeTimeToLive`, `UpdateTimeToLive`, `DescribeContinuousBackups`, `UpdateContinuousBackups`, `CreateBackup` and `ListBackups` (but not an `UpdateContinuousBackups` that enables point-in-time recovery, which `admit` refuses first) the account comes first: a `TableName` ARN of five fields whose account field is not the caller's gets the **accounts** answer whatever else is wrong with it, and in the caller's account a vendor or region fault is "1 validation error detected: Invalid vendor code in '<arn>'" (or "Invalid AWS region in '<arn>'") | `ResourceNotFoundException` "Requested resource not found" | | | the same on `PutItem`, `UpdateItem`, `DeleteItem`, `CreateTable`, `DescribeTable`, `DeleteTable`, `DescribeTimeToLive` and `UpdateTimeToLive` | as above | the engine's name check, as for **table names**: for an ARN of up to 255 bytes, `ValidationException` "1 validation error detected: Value '<arn>' at 'tableName' failed to satisfy constraint: Member must satisfy regular expression pattern: [a-zA-Z0-9_.-]+", and for a longer one the length clause "… less than or equal to 255" | diff --git a/tests/python/test_nul_table_names.py b/tests/python/test_nul_table_names.py index 4837c6a3f..3a3c0f081 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_.-]+" @@ -172,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 @@ -270,3 +276,306 @@ 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" +) +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]" +) + + +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)}} + + +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, 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"}}), + _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", + ), + 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", + ), + 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", + ), +] + + +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)