Skip to content

fix(engine): refuse a U+0000 in a tag key or value - #1448

Open
eliseong wants to merge 2 commits into
mainfrom
eliseong-tag-nul-char-2026-11-24
Open

eliseong wants to merge 2 commits into
mainfrom
eliseong-tag-nul-char-2026-11-24

Conversation

@eliseong

@eliseong eliseong commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

What

TagResource and UntagResource now refuse a tag key or value that contains U+0000, before the write. Such a key or value answered 500 on PostgreSQL, which cannot bind U+0000 in a TEXT parameter, and 200 on SQLite. The service answers:

ValidationException: The Tag Key provided is invalid, Key: <key>
ValidationException: The Tag Value provided is invalid, Value: <value>

with the raw character echoed. The check is in the backend-independent handler, so every backend answers the same.

Why

Closes #903

Testing done

  • Live DynamoDB (us-east-1, two runs each): TagResource key U+0000 and value U+0000, and UntagResource key U+0000, each answer the messages above with the raw character.
  • Unit tests pin the exact key and value messages and a clean key and value passing.
  • tests/python/test_tagging.py::test_nul_tag_on_nonexistent_resource sends a U+0000 key 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 warnings clean on engine; the engine suite passes.

Notes

  • Scope is U+0000, the character that causes the 500. Broader tag key and value charset and length validation is a separate, unmeasured concern.
  • CreateTable Tags take the same path to storage with no check, so a U+0000 tag there likely still answers 500 on PostgreSQL. Out of scope here; worth a follow-up issue.
  • The check 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, so a U+0000 tag aimed at a missing table or at a table ARN in another region answers the tag's ValidationException, as on the service (us-east-1, 1 December 2026, each request twice). A stream ARN in another region still answers Invalid StreamArn first, 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.
  • fix(tagging): validate tag keys and values against the service grammar #485 also reorders validate_resource_arn around its tag checks. Whichever merges second folds the other's check into one place.
  • Still different from the service, here and on main: a principal without dynamodb:TagResource gets AccessDeniedException where the service answers the tag's ValidationException, and a table name outside the name pattern answers Invalid TableArn first (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 empty ResourceArn, an ARN with too few fields and an ARN over 1600 characters answer other texts than the service.
  • A tag key with U+0000 stored before this change (possible on SQLite, which accepted it) can no longer be removed through UntagResource, since the key is now refused; it clears when the table is deleted.
  • Open PR fix: answer TTL and tag calls during a table's DELETING window #599 also edits 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

  • I have read CONTRIBUTING.md
  • All tests pass (cargo test --workspace)
  • Code is formatted (cargo fmt --check)
  • Clippy is clean (cargo clippy -- -W clippy::pedantic)
  • I have added or updated tests for new functionality
  • I have updated documentation if behavior changed
  • Breaking changes are noted below (if any)
  • If this changes the wire protocol, Storage trait, auth model, on-disk
    format, or public CLI surface, an RFC has been accepted or is linked
    below. Otherwise, an ADR captures the decision (link below).

ADR / RFC: n/a


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache License 2.0 and I agree to the Developer Certificate of Origin (DCO).

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 LJMart11 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread crates/engine/src/tagging.rs Outdated

validate_resource_arn(&input.resource_arn, ctx).await?;

for tag in &input.tags {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
@eliseong
eliseong requested a review from LJMart11 December 1, 2026 19:21

@LeeroyHannigan LeeroyHannigan left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 of validate_resource_arn and its three call sites.
  • The Notes suggest a follow-up issue for U+0000 in the Tags of CreateTable. #485 checks those Tags.

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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 navareamol self-assigned this Dec 4, 2026

@navareamol navareamol left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TagResource and UntagResource: U+0000 in a tag key or value answers 500 on PostgreSQL

4 participants