Repository navigation
Conversation
TagResource and UntagResource passed tag keys and values to storage with no character check. A key or value carrying a U+0000 answered 500 on PostgreSQL, which cannot bind the character in a TEXT parameter, and 200 on SQLite. The service answers ValidationException "The Tag Key provided is invalid, Key: <key>" or "The Tag Value provided is invalid, Value: <value>", with the raw character echoed. Both handlers now refuse a U+0000 in a key, and TagResource also in a value, with that message, before the write. The check is in the backend-independent handler, so every backend answers the same. Closes #903
LJMart11
left a comment
There was a problem hiding this comment.
Reviewed at 5315115. 1 finding: 1 Important.
The change refuses a U+0000 in a tag key or value in TagResource and UntagResource before the storage write. Confirmed: on SQLite and PostgreSQL, a NUL key, a NUL value, a NUL key in UntagResource and a NUL in the middle of a key each answer 400 ValidationException with the same text as live DynamoDB (us-east-1), raw character echoed; with several bad tags the first bad value is reported, as on the service. The engine tests ran under 1.91.1 (893 lib tests passed, 0 failed), including the 3 new ones; a trial merge with the current main tip has no conflicts.
- Important
crates/engine/src/tagging.rs:236— The NUL check runs after the resource-existence check, so a NUL tag aimed at a missing table answers ResourceNotFoundException where DynamoDB answers ValidationException.
|
|
||
| validate_resource_arn(&input.resource_arn, ctx).await?; | ||
|
|
||
| for tag in &input.tags { |
There was a problem hiding this comment.
Important
The check runs after validate_resource_arn (tagging.rs:234 TagResource, :276 UntagResource), so a request with a U+0000 key or value aimed at a table that does not exist answers ResourceNotFoundException. DynamoDB answers ValidationException first. The PR body lists this precedence as not measured; I measured it.
Fix: move the key/value loops above validate_resource_arn in both handlers, and add a handler-level or pytest case that sends a U+0000 key to a missing table ARN and expects ValidationException; the three unit tests at tagging.rs:338-361 call only the helpers and do not change. No migration.
Evidence: same request, TagResource with ResourceArn of a nonexistent table (the existing table's ARN plus zz) and Tags [{Key:'k\u0000',Value:'v'}]. Live DynamoDB (us-east-1): 400 ValidationException The Tag Key provided is invalid, Key: k\u0000. This head on SQLite and PostgreSQL: 400 ResourceNotFoundException Requested resource not found: ResourceArn: arn:aws:dynamodb:us-east-1:123456789012:table/... not found. Same request on an existing table matched live on both backends for key, value, UntagResource key and a NUL in the middle of a key.
There was a problem hiding this comment.
Fixed in 6dbb2bd. The tag check now runs after the ARN's prefix, resource and account checks and before the existence check, and for a table ARN also before the region check. Measured in us-east-1 on 1 December 2026, each request twice: a U+0000 key or value aimed at a missing table, or at a table ARN in another region, answers the tag's ValidationException. An ARN that does not start with arn:, an index or backup ARN, another account's ARN and another service's ARN still answer their ARN refusal first, as on the service. A stream ARN in another region still answers Invalid StreamArn first, as #485 measured. test_nul_tag_on_nonexistent_resource sends these cases and fails on 5315115.
TagResource and UntagResource checked a U+0000 in a tag key or value after every check of the resource ARN. For a table that does not exist, such a request answered ResourceNotFoundException, and for a table ARN in another region it answered the region's ValidationException. DynamoDB answers the tag's ValidationException in both cases. The tag check now runs after the ARN's prefix, resource and account checks and before the existence check. For a table ARN it also runs before the region check; measured in us-east-1 on 2026-12-01, each request sent twice. A stream ARN in another region still answers Invalid StreamArn first, as measured on 2026-11-20. Signed-off-by: Elise Ong <eliseong@amazon.com>
LeeroyHannigan
left a comment
There was a problem hiding this comment.
Thanks. I read the change against main 92155f3. The three texts are the ones in #903. The check comes where the service puts it: after the account check, before the existence check, and for a table ARN before the region check. On servers built from this branch and from main, tests/python/test_tagging.py passed 8 of 8 here, and on main only test_nul_tag_on_nonexistent_resource failed, as it should. cargo test -p extenddb-engine --lib tagging passed 5 of 5. CI passed, and the branch merges with main.
This overlaps #485 (opened 24 October). Its validate_tag_key and validate_tag_value in crates/core/src/validation/tag.rs already refuse U+0000, with the same two texts, in the same two handlers and in the same order. #485 also checks the Tags of CreateTable. The two PRs conflict in 8 hunks of crates/engine/src/tagging.rs. Under code-size.md, the second of the two to merge drops its copy. If #485 merges first, this PR's Python test is the part that #485 lacks, because #485 has no U+0000 row.
This needs one change before it merges. In 1.1.0 a TagResource or UntagResource with U+0000 answered 200 on SQLite and 500 on PostgreSQL, and here it answers 400. docs/versioning.md puts such a change under Behavior Changes by Release in the upgrade manual, so it needs a v1.2.0: entry. The entry can carry your note that UntagResource can no longer remove a U+0000 key that an earlier SQLite release stored.
On the description:
- The Notes say that #599 overlaps only in the test imports. At this head the two PRs conflict in 7 hunks of
tagging.rs, because both change the signature ofvalidate_resource_arnand its three call sites. - The Notes suggest a follow-up issue for U+0000 in the
Tagsof CreateTable. #485 checks thoseTags.
One nit inline.
| /// (measured 2026-11-24 on DynamoDB; the raw character is echoed). PostgreSQL | ||
| /// cannot bind U+0000 in a TEXT parameter, so without this check TagResource | ||
| /// and UntagResource answer 500 there; SQLite accepted it. The service answers | ||
| /// ValidationException on both, ahead of the region and existence checks of |
There was a problem hiding this comment.
Nit: for a stream ARN the region check comes first, as the code at line 176 and the Python test show. "ahead of the existence check, and for a table ARN ahead of the region check" says what the code does.
navareamol
left a comment
There was a problem hiding this comment.
I ran this head and a build of main on SQLite and on PostgreSQL 16. On PostgreSQL main answers InternalServerError for a U+0000 in a tag key or value on TagResource and for a U+0000 key on UntagResource. This head answers the ValidationException with the raw character on both backends, and test_nul_tag_on_nonexistent_resource passes on both and fails on main on both. With several tags the first bad one is reported, a request that is refused stores none of its tags, and a missing table gets the tag error where main gave ResourceNotFoundException. An index ARN, a backup ARN, a bad prefix and another account's ARN still get their own refusals first.
One thing I measured that the description only guesses at. CreateTable with a U+0000 in a tag key answers InternalServerError on PostgreSQL, on this head and on main. The Notes say "likely"; you can state it as measured, or point to the PR that checks those Tags.
I will approve once the v1.2.0 upgrade manual entry that LeeroyHannigan asked for is in and the conflict count with #599 in the Notes is corrected.
What
TagResourceandUntagResourcenow refuse a tag key or value that containsU+0000, before the write. Such a key or value answered 500 on PostgreSQL, which cannot bindU+0000in aTEXTparameter, and 200 on SQLite. The service answers:with the raw character echoed. The check is in the backend-independent handler, so every backend answers the same.
Why
Closes #903
Testing done
TagResourcekeyU+0000and valueU+0000, andUntagResourcekeyU+0000, each answer the messages above with the raw character.tests/python/test_tagging.py::test_nul_tag_on_nonexistent_resourcesends aU+0000key and value to a missing table, to a table ARN in another region and to a stream ARN in another region. It passes on this head and fails on 5315115, on SQLite. A PostgreSQL build answers the missing-table and existing-table cases as the service does, with no 500.cargo clippy --all-targets -- -D warningsclean on engine; the engine suite passes.Notes
U+0000, the character that causes the 500. Broader tag key and value charset and length validation is a separate, unmeasured concern.CreateTableTagstake the same path to storage with no check, so aU+0000tag there likely still answers 500 on PostgreSQL. Out of scope here; worth a follow-up issue.U+0000tag aimed at a missing table or at a table ARN in another region answers the tag'sValidationException, as on the service (us-east-1, 1 December 2026, each request twice). A stream ARN in another region still answersInvalid StreamArnfirst, as fix(tagging): validate tag keys and values against the service grammar #485 measured on 20 November 2026. Across several tags, the first bad key or value is reported, as on the service.validate_resource_arnaround its tag checks. Whichever merges second folds the other's check into one place.dynamodb:TagResourcegetsAccessDeniedExceptionwhere the service answers the tag'sValidationException, and a table name outside the name pattern answersInvalid TableArnfirst (related to Three TagResource ARN shapes get a shape error or AccessDeniedException before or without the account check, where DynamoDB checks the account first #1243). An emptyResourceArn, an ARN with too few fields and an ARN over 1600 characters answer other texts than the service.U+0000stored before this change (possible on SQLite, which accepted it) can no longer be removed throughUntagResource, since the key is now refused; it clears when the table is deleted.crates/engine/src/tagging.rs; the two overlap only in the tests import block, a trivial union to resolve, so merge order is either way.Checklist
cargo test --workspace)cargo fmt --check)cargo clippy -- -W clippy::pedantic)Storagetrait, auth model, on-diskformat, or public CLI surface, an RFC has been accepted or is linked
below. Otherwise, an ADR captures the decision (link below).
ADR / RFC: n/a
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache License 2.0 and I agree to the Developer Certificate of Origin (DCO).