Skip to content

fix(backup): strip only one trailing line terminator from a backup ARN - #1328

Open
LeeroyHannigan wants to merge 3 commits into
mainfrom
fix/617-backup-arn-whitespace
Open

LeeroyHannigan wants to merge 3 commits into
mainfrom
fix/617-backup-arn-whitespace

Conversation

@LeeroyHannigan

@LeeroyHannigan LeeroyHannigan commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator

Changes since the last review

  • ee68458 merges main at 5252eda. feat(wasm): [Add WebAssembly browser support for ExtendDB #1009 moved the engine's check_backup_arn, BACKUP_ARN_NOT_VALID and the ListBackups handlers from crates/engine/src/backup.rs to crates/engine/src/backup_requests.rs. This branch's changes to that code are now in backup_requests.rs. The upgrade manual keeps both v1.1.0 entries, main's first.
  • 49bd69e: the server's ARN gate parses a backup ARN as sent, without trim_backup_arn (thread on arn_gate.rs:241). With the strip, the gate passed on .../table/<bad>/backup/\n, and RestoreTableFromBackup got the engine's Invalid Request: BackupArn is not valid. A new row of the gate's unit test pins the gate's answer.
  • DynamoDB's answer to a BackupArn with whitespace before it and a table name outside the pattern is now measured (second thread on arn_gate.rs:241). The branch gives the same answer, so no code changed for it.

What

DescribeBackup, DeleteBackup, RestoreTableFromBackup and the ExclusiveStartBackupArn of ListBackups now read whitespace around a backup ARN as DynamoDB does:

  • One trailing line terminator is stripped: \n, \r\n, \r, U+0085, U+2028 or U+2029. trim_backup_arn in crates/core/src/backup_format/layout.rs does this. Authorization and the engine both call it, so they read the same string.
  • An ARN that starts with whitespace is ValidationException Invalid Backup ARN. The engine's check_backup_arn in crates/engine/src/backup_requests.rs refuses it before it parses the ARN.
  • Any other whitespace after the ARN, two line terminators included, is ValidationException Invalid Request: BackupArn is not valid.
  • For a backup that does not exist, BackupNotFoundException names the ARN as the request wrote it, its line terminator included. The three operations build that text from the request's BackupArn.

Before, each of these layers trimmed all ASCII whitespace from both ends. An ARN with a space or a tab around it resolved, and the layers refused one with U+0085, U+2028 or U+2029 after it. VT, NBSP or other non-ASCII whitespace before the ARN got Invalid Request: BackupArn is not valid on RestoreTableFromBackup and in a cursor. The not-found text dropped the line terminator.

  • The server's ARN gate refuses a backup ARN whose table name is outside the pattern with Invalid Backup ARN. It now parses the ARN as sent, where main's gate trimmed ASCII whitespace from both ends first. Two cases change with it:
    • A RestoreTableFromBackup ARN with ASCII whitespace other than VT before it and a table name outside the pattern. Main's gate refused it with Invalid Backup ARN before authorization. Now authorization evaluates the ARN as sent. A caller without an Allow on it gets AccessDeniedException, and the engine refuses it with Invalid Backup ARN for any other caller. DynamoDB gives the Admin role the same Invalid Backup ARN (measured on 2026-11-25). Whether DynamoDB checks the ARN before authorization for a caller without permission was not measured.
    • An ARN with a table name outside the pattern and a backup id made only of ASCII whitespace other than VT, as in .../table/<bad>/backup/\n. The gate now refuses it with Invalid Backup ARN on all three operations. DynamoDB gives that answer to .../table/<bad>/backup/\n on DescribeBackup and RestoreTableFromBackup (measured on 2026-11-25). Main's gate trimmed the whitespace and passed the ARN on, and RestoreTableFromBackup got Invalid Request: BackupArn is not valid from the engine.
  • With a configured backup store, some not-found texts named the ARN in the server's region when the request used another region's ARN. These are the texts for a backup that is DELETED, FAILED or DELETING, or whose manifest is missing. Each now names the ARN as the request wrote it (from the code). DynamoDB names the ARN as written for a deleted backup of another region, on DescribeBackup and DeleteBackup, in two runs.
  • backup sync --forget-backup trims its arguments when it parses them, as backup migrate-legacy does. An argument that 1.0.0 accepted is read as before. VT and non-ASCII whitespace around an argument, which 1.0.0 refused, is now trimmed too.
  • docs/differences-from-dynamodb.md, docs/dynamodb-limits.md and a v1.1.0 entry in docs/manuals/07-upgrade-manual.md describe the rule.

In an ExclusiveStartBackupArn, DynamoDB answers trailing whitespace other than one line terminator with Invalid Request: The supplied ExclusiveStartBackupArn is not a valid backup arn. ExtendDB answers the BackupArn text, as it does for the other malformed cursors that #1315 and #907 list. The new test rows for that case are strict xfail on ExtendDB.

An ARN with a table name outside the pattern and an empty backup id, .../table/<bad>/backup/, is not changed here. DynamoDB answers it with Invalid Backup ARN on DescribeBackup and RestoreTableFromBackup (measured on 2026-11-25). On main and on this branch, RestoreTableFromBackup gets Invalid Request: BackupArn is not valid from the engine. #1272 tracks it.

#1327 changes the engine's check_backup_arn and the texts for a malformed BackupArn. It conflicts with this branch in crates/core/src/backup_format/layout.rs, crates/engine/src/backup_requests.rs, crates/engine/src/backup/tests.rs, docs/differences-from-dynamodb.md, docs/dynamodb-limits.md and tests/test_backup_restore_fidelity.py (checked on 2026-11-25). crates/server/src/arn_gate.rs merges without a conflict, but the merged gate test does not compile. #1327 makes backup a loop variable, and this branch's rows use it after the loop. With its mapping, an ARN that starts with whitespace gets Invalid Backup ARN without this branch's leading check. #1327 also returns BackupNotFoundException from backup_arn_field for a backup id with upper-case hex. On DescribeBackup and DeleteBackup that error returns before named_as_requested runs. The second of the two to merge drops the leading check and sends that error through named_as_requested. #1327 leaves the not-found text to this PR.

The v1.1.0 entry in docs/manuals/07-upgrade-manual.md conflicts with the entries that 22 other open PRs add at the same place, #1329 among them (checked on 2026-11-25).

Why

#617: ExtendDB trimmed more than DynamoDB does, so it resolved ARNs that DynamoDB refuses. Measured in us-east-1 on 2026-11-21, every row twice or more:

Spelling DescribeBackup ExclusiveStartBackupArn
ARN + one \n, \r\n, \r, U+0085, U+2028 or U+2029 200 200
ARN + other whitespace (\n\n, \r\n\r\n, \n\r, \r\r, space, tab, FF, VT, NBSP, and mixes) Invalid Request: BackupArn is not valid Invalid Request: The supplied ExclusiveStartBackupArn is not a valid backup arn
whitespace + ARN (space, tab, \n, \r\n, FF, VT, NBSP, and with one \n after the ARN) Invalid Backup ARN Invalid Backup ARN
ARN of no backup, with no suffix or one line terminator BackupNotFoundException, Backup not found: and the ARN as written not sent

DeleteBackup and RestoreTableFromBackup answer the refused rows and the not-found rows as DescribeBackup does. The resolving rows were not sent to those two, because they would act on the backup.

Measured in us-east-1 on 2026-11-25, every row twice. Each ARN names a table and a backup id that do not exist, in the caller's account or in another account:

BackupArn DescribeBackup RestoreTableFromBackup
space or tab + ARN with a table name outside the pattern Invalid Backup ARN Invalid Backup ARN
space or tab + ARN with a table name in the pattern (other account) Invalid Backup ARN Invalid Backup ARN
.../table/<bad>/backup/ + \n (caller's account) Invalid Backup ARN Invalid Backup ARN
.../table/<bad>/backup/ (caller's account) Invalid Backup ARN Invalid Backup ARN

Each answer was HTTP 400 ValidationException. These runs used a role whose policy allows every action.

Closes #617

Testing done

At 49bd69e, which has main 5252eda merged in, unless a line names another commit.

  • test_backup_arn_whitespace_as_the_service_reads_it in tests/test_backup_restore_fidelity.py, 109 cases, one data table over the four operations. It asserts the status, the type and the full message by equality.
    • Against DynamoDB, at dc858f5: 109 passed, in each of two runs.
    • On a SQLite server built from the branch: 98 passed and the 11 cursor rows xfailed. On a server built from f0170bd, which has the backup ARN code of 8c64333, 79 failed.
    • The module fixture shares one backup, and its cleanup drops the restore target that the RestoreTableFromBackup rows name.
  • I sent the 32 requests of the 2026-11-25 measurement to a SQLite server built from the branch. Each got DynamoDB's answer, except the two RestoreTableFromBackup requests of .../table/<bad>/backup/ above. With the gate's strip put back, the two RestoreTableFromBackup requests of .../table/<bad>/backup/\n got Invalid Request: BackupArn is not valid too.
  • Rust unit tests: the core table of trim_backup_arn and check_backup_arn, three rows in the engine's malformed-ARN table, the ARN gate, authorization, and the parse test of --forget-backup. The gate test has a row for .../table/<bad>/backup/\n.
  • Eight mutants at dc858f5, each run against the Rust unit tests, and a test fails for each:
    • main's trim, a second CRLF strip, no U+2028, and no CR
    • an ASCII-only leading check, and no leading check
    • the gate with main's trim
    • no trim in the --forget-backup parser
  • At the branch, the gate with trim_backup_arn put back: the new gate row fails.
  • cargo +1.97.0 fmt --all -- --check, both commands of clippy.yml for the touched crates, cargo +1.91.1 check --all-targets on them and cargo +1.97.0 test -p extenddb-storage-postgres --test doc_version_literals: pass. Lib tests: core 1178 passed, storage 291, engine 933, server 514, app 105. The other 5 server tests, in backup_store::tests, fail on the build host, which has no directory whose ancestors belong to root or the test user. This change does not touch backup_store.

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

Breaking changes

Some ARNs that 1.0.0 resolved now get ValidationException: an ARN with whitespace before it, and one with whitespace after it other than one line terminator. An ARN sent as CreateBackup or ListBackups returned it is not affected. The upgrade manual has a v1.1.0 entry.


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). See CONTRIBUTING.md for details.

DescribeBackup, DeleteBackup, RestoreTableFromBackup and the
ExclusiveStartBackupArn of ListBackups trimmed all ASCII whitespace from
both ends of the ARN. An ARN with a space or a tab around it resolved.
DynamoDB ignores one trailing line terminator and refuses all other
whitespace (measured in us-east-1 on 2026-11-21):

- One trailing \n, \r\n, \r, U+0085, U+2028 or U+2029 resolves on
  DescribeBackup and in an ExclusiveStartBackupArn.
- An ARN that starts with whitespace is ValidationException "Invalid
  Backup ARN", also when one line terminator follows it.
- Other whitespace after the ARN, two line terminators included, is
  ValidationException "Invalid Request: BackupArn is not valid".
- For a backup that does not exist, BackupNotFoundException names the
  ARN as the request wrote it, its line terminator included.

trim_backup_arn now strips only the one line terminator. The engine
refuses leading whitespace with "Invalid Backup ARN" before it parses
the ARN. Before, VT, NBSP and other non-ASCII whitespace before the ARN
got "not valid" on RestoreTableFromBackup and in a cursor. The three
operations build their not-found text from the request's BackupArn. The
server's ARN gate now calls trim_backup_arn in place of its own trim,
so the gate, authorization and the engine read the same string.

One case changes with the gate: a RestoreTableFromBackup ARN with ASCII
whitespace other than VT before it and a table name outside the
pattern. Main's gate refused it with "Invalid Backup ARN" before
authorization. Now authorization evaluates the ARN as sent. A caller
without an Allow on it gets AccessDeniedException, and the engine
refuses it for any other caller. DynamoDB's answer to that input was
not measured.

backup sync --forget-backup trims its arguments when it parses them, as
backup migrate-legacy does. An argument that 1.0.0 accepted is read as
before. VT and non-ASCII whitespace around an argument, which 1.0.0
refused, is now trimmed too.

In an ExclusiveStartBackupArn, DynamoDB answers trailing whitespace
other than one line terminator with "Invalid Request: The supplied
ExclusiveStartBackupArn is not a valid backup arn". ExtendDB answers
the BackupArn text, as it does for the other malformed cursors that
#1315 and #907 list. The new test rows for that case are strict xfail
on ExtendDB.

The differences document, the limits document and the upgrade manual
describe the new rule.

Closes #617
Refs #1315

@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 dc858f5.

2 findings are left inline.

Comment thread crates/server/src/arn_gate.rs Outdated
/// `Invalid Request: BackupArn is not valid`, as measured.
pub(crate) fn check_backup_arn(arn: &str) -> Result<(), DynamoDbError> {
match parse(arn.trim_matches(|c: char| c.is_ascii_whitespace())) {
match parse(extenddb_core::backup_format::trim_backup_arn(arn)) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

With trim_backup_arn replaced by the raw arn here, cargo test -p extenddb-server --lib arn_gate passes (8 tests), so the gate's strip is unpinned.

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.

Thanks LJMart11. I reproduced it: with parse(arn) in place of parse(trim_backup_arn(arn)) in the gate's check_backup_arn, the 8 arn_gate tests pass.

The strip touches only the end of the ARN, and the gate reads only the table name and the resource kind. So the strip changed the gate's answer for one kind of input. That input has a table name outside the pattern and a backup id that is one line terminator, as in .../table/<bad>/backup/\n. The strip left an empty backup id, so the ARN didn't parse and the gate passed it on. On a SQLite server built with the strip, RestoreTableFromBackup then got Invalid Request: BackupArn is not valid from the engine. DescribeBackup got Invalid Backup ARN from the shape check that runs before authorization. DynamoDB answers Invalid Backup ARN to that ARN on both operations (measured on 2026-11-25, twice each).

49bd69e removes the strip, so the gate parses the ARN as sent and refuses that ARN with Invalid Backup ARN. It adds the ARN as a row of table_arn_fields_stream_backup_and_tag_arns, and the row fails with the strip put back.

Comment thread crates/server/src/arn_gate.rs Outdated
/// `Invalid Request: BackupArn is not valid`, as measured.
pub(crate) fn check_backup_arn(arn: &str) -> Result<(), DynamoDbError> {
match parse(arn.trim_matches(|c: char| c.is_ascii_whitespace())) {
match parse(extenddb_core::backup_format::trim_backup_arn(arn)) {

@LJMart11 LJMart11 Nov 25, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Update: Lee measured the malformed ARN cases on DynamoDB and SQLite, and this branch still returns Invalid Backup ARN. Those Admin-role runs do not establish whether validation happens before authorization, so I withdraw the ordering claim.

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.

Thanks LJMart11. I measured it on DynamoDB on 2026-11-25, twice each, on names that don't exist. The ARNs name a table and a backup id in the caller's account and in account 999999999999. DescribeBackup and RestoreTableFromBackup answer ValidationException Invalid Backup ARN to an ARN with a leading space or tab and a table name outside the pattern, in both accounts. The control, the same ARN in account 999999999999 with a table name in the pattern, gets the same answer.

A SQLite server built from 49bd69e gives the same answer to each of these requests, so the branch keeps this behaviour. The runs used the Admin role, whose policy allows every action. They don't show whether DynamoDB checks the ARN before or after authorization for a caller without permission, so I don't claim either order. The PR body now gives the measurement and says the order is not measured.

Main is at 5252eda. The base of this branch is main 8c64333, and
main has 25 commits since then. Of the files that this branch changes,
main changes six, and git reported a conflict in two of them.

#1009 moved check_backup_arn, BACKUP_ARN_NOT_VALID and the ListBackups
handlers from crates/engine/src/backup.rs to
crates/engine/src/backup_requests.rs. The merge keeps the move. It
applies the changes of this branch to the moved code. They are the check
of an ARN that starts with whitespace, the INVALID_BACKUP_ARN constant,
and the doc comments of check_backup_arn and list_backups_cursor.

In docs/manuals/07-upgrade-manual.md, main and this branch each add a
v1.1.0 entry at the same place. The merge keeps both entries, main's
first.
The server's ARN gate refuses a backup ARN whose table name is outside
the pattern with "Invalid Backup ARN". It stripped one trailing line
terminator with trim_backup_arn before it parsed the ARN. The strip
changed the gate's answer for one kind of input: a backup id that is
one line terminator, as in ".../table/<bad>/backup/\n". The strip left
an empty backup id, the ARN did not parse, and the gate passed it on.
RestoreTableFromBackup then got "Invalid Request: BackupArn is not
valid" from the engine. Without the strip, the gate answers "Invalid
Backup ARN" on DescribeBackup, DeleteBackup and RestoreTableFromBackup.

DynamoDB answers "Invalid Backup ARN" to that ARN on DescribeBackup and
RestoreTableFromBackup (measured in us-east-1 on 2026-11-25, twice
each). The strip touches only the end of the ARN, and the gate reads
only the table name and the resource kind. So for every other ARN the
gate gives the same answer with and without the strip.

The gate now parses the ARN as sent. A new row of the gate's unit test
sends ".../table/<bad>/backup/\n" and fails with the strip in place.
The doc comment of trim_backup_arn now names authorization and the
engine as the layers that strip.

@hitesh96db hitesh96db left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This fixes what #617 describes. Against DynamoDB, 1235 of the spellings I sent now match where main did not, and one trailing line terminator is accepted as the service does. I also checked authorization on a server with built-in IAM and explicit Denies on 57 backup ARNs, sending 55 spellings through DescribeBackup, DeleteBackup and RestoreTableFromBackup: no spelling reached a denied backup, and the ARN that authorization matches is the one the engine acts on.

Three request shapes that main answered like DynamoDB now differ (inline). Two things to fix before merge, then small items.

Also:

  • The upgrade-manual entry is headed v1.1.0, but v1.1.0 is already tagged and does not contain this change, so it will ship in a later release. It also leaves out the --forget-backup change.
  • For an ARN with trailing whitespace, the engine now reports the ARN error before other members (check_backup_arn runs first in the handler). DynamoDB reports an invalid TargetTableName or BackupType first on RestoreTableFromBackup and ListBackups. Not new in kind (main trimmed, so it answered the other member), but worth knowing.
  • 26 CI jobs at this head were cancelled before they started a step, and wasm fails on a compile error in crates/core that the PR does not touch. The cancelled jobs include the Python tests for RestoreTableFromBackup, so please re-run CI so those tests run.

/// `Invalid Request: BackupArn is not valid`, as measured.
pub(crate) fn check_backup_arn(arn: &str) -> Result<(), DynamoDbError> {
match parse(arn.trim_matches(|c: char| c.is_ascii_whitespace())) {
match parse(arn) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Without the trim here, a leading space, tab, LF, CR, CRLF or FF makes parse return None, because it needs the arn: prefix. The gate passes the ARN and the later member checks answer first. main trimmed here, so the gate refused the ARN first. Measured in us-east-1 on 2026-11-30, twice, identical, and on SQLite builds of main and this head:

RestoreTableFromBackup {"BackupArn": " arn:aws:dynamodb:us-east-1:123456789012:table/bad table!/backup/01796075814728-deadbeef", "TargetTableName": "bad name!"}

  • DynamoDB and main: Invalid Backup ARN
  • This PR: 1 validation error detected: Value 'bad name!' at 'targetTableName' failed to satisfy constraint: Member must satisfy regular expression pattern: [a-zA-Z0-9_.-]+

The same holds with BillingModeOverride: "BAD" as the second fault, and for the leading space, tab, LF, CR, CRLF and FF, in the caller's account and in another account (24 cells). Have the gate refuse an ARN with leading whitespace as Invalid Backup ARN, or run the engine's leading check before the member checks.

arn.trim_matches(|c: char| c.is_ascii_whitespace())
arn.strip_suffix("\r\n")
.or_else(|| arn.strip_suffix(['\n', '\r', '\u{85}', '\u{2028}', '\u{2029}']))
.unwrap_or(arn)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

A backup id that is only whitespace now answers differently. main turned .../backup/ into .../backup/ with an empty id, which the pre-authorization check refused as Invalid Backup ARN. trim_backup_arn strips only a line terminator, so the id stays " " or "\t" and reaches the printable-ASCII test in check_backup_arn. Measured on DynamoDB twice, identical, and on SQLite builds:

DescribeBackup {"BackupArn": "arn:aws:dynamodb:us-east-1:123456789012:table/<table>/backup/ "}

  • DynamoDB and main: Invalid Backup ARN
  • This PR: Invalid Request: BackupArn is not valid

Same for DeleteBackup, and for the ids \t, FF, \n\n and \t\n (22 cells per operation). A one-line check that treats a whitespace-only id as Invalid Backup ARN would restore this.

One smaller case in the same place: a bad backup id followed by U+0085, U+2028 or U+2029 now reaches is_backup_id after the strip and answers Invalid Backup ARN. DynamoDB and main answer Invalid Request: BackupArn is not valid. The older mapping of a non-hex id to Invalid Backup ARN is the real difference: DynamoDB answers not valid for every bad id (for example the ARN followed by a), and the PR makes three more terminators reach that mapping. Fixing the mapping fixes both.

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

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BackupArn with leading or trailing whitespace resolves; DynamoDB accepts only one trailing line terminator

3 participants