Repository navigation
fix(backup): strip only one trailing line terminator from a backup ARN - #1328
LeeroyHannigan wants to merge 3 commits into
Conversation
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
left a comment
There was a problem hiding this comment.
Reviewed at dc858f5.
2 findings are left inline.
| /// `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)) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
| /// `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)) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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, butv1.1.0is already tagged and does not contain this change, so it will ship in a later release. It also leaves out the--forget-backupchange. - For an ARN with trailing whitespace, the engine now reports the ARN error before other members (
check_backup_arnruns first in the handler). DynamoDB reports an invalidTargetTableNameorBackupTypefirst 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
wasmfails on a compile error incrates/corethat 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) { |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
Changes since the last review
check_backup_arn,BACKUP_ARN_NOT_VALIDand the ListBackups handlers fromcrates/engine/src/backup.rstocrates/engine/src/backup_requests.rs. This branch's changes to that code are now inbackup_requests.rs. The upgrade manual keeps both v1.1.0 entries, main's first.trim_backup_arn(thread onarn_gate.rs:241). With the strip, the gate passed on.../table/<bad>/backup/\n, and RestoreTableFromBackup got the engine'sInvalid Request: BackupArn is not valid. A new row of the gate's unit test pins the gate's answer.BackupArnwith whitespace before it and a table name outside the pattern is now measured (second thread onarn_gate.rs:241). The branch gives the same answer, so no code changed for it.What
DescribeBackup, DeleteBackup, RestoreTableFromBackup and the
ExclusiveStartBackupArnof ListBackups now read whitespace around a backup ARN as DynamoDB does:\n,\r\n,\r, U+0085, U+2028 or U+2029.trim_backup_arnincrates/core/src/backup_format/layout.rsdoes this. Authorization and the engine both call it, so they read the same string.ValidationExceptionInvalid Backup ARN. The engine'scheck_backup_arnincrates/engine/src/backup_requests.rsrefuses it before it parses the ARN.ValidationExceptionInvalid Request: BackupArn is not valid.BackupNotFoundExceptionnames the ARN as the request wrote it, its line terminator included. The three operations build that text from the request'sBackupArn.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 validon RestoreTableFromBackup and in a cursor. The not-found text dropped the line terminator.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:Invalid Backup ARNbefore authorization. Now authorization evaluates the ARN as sent. A caller without an Allow on it getsAccessDeniedException, and the engine refuses it withInvalid Backup ARNfor any other caller. DynamoDB gives the Admin role the sameInvalid Backup ARN(measured on 2026-11-25). Whether DynamoDB checks the ARN before authorization for a caller without permission was not measured..../table/<bad>/backup/\n. The gate now refuses it withInvalid Backup ARNon all three operations. DynamoDB gives that answer to.../table/<bad>/backup/\non DescribeBackup and RestoreTableFromBackup (measured on 2026-11-25). Main's gate trimmed the whitespace and passed the ARN on, and RestoreTableFromBackup gotInvalid Request: BackupArn is not validfrom the engine.backup sync --forget-backuptrims its arguments when it parses them, asbackup migrate-legacydoes. 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.mdand a v1.1.0 entry indocs/manuals/07-upgrade-manual.mddescribe the rule.In an
ExclusiveStartBackupArn, DynamoDB answers trailing whitespace other than one line terminator withInvalid Request: The supplied ExclusiveStartBackupArn is not a valid backup arn. ExtendDB answers theBackupArntext, 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 withInvalid Backup ARNon DescribeBackup and RestoreTableFromBackup (measured on 2026-11-25). On main and on this branch, RestoreTableFromBackup getsInvalid Request: BackupArn is not validfrom the engine. #1272 tracks it.#1327 changes the engine's
check_backup_arnand the texts for a malformedBackupArn. It conflicts with this branch incrates/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.mdandtests/test_backup_restore_fidelity.py(checked on 2026-11-25).crates/server/src/arn_gate.rsmerges without a conflict, but the merged gate test does not compile. #1327 makesbackupa loop variable, and this branch's rows use it after the loop. With its mapping, an ARN that starts with whitespace getsInvalid Backup ARNwithout this branch's leading check. #1327 also returnsBackupNotFoundExceptionfrombackup_arn_fieldfor a backup id with upper-case hex. On DescribeBackup and DeleteBackup that error returns beforenamed_as_requestedruns. The second of the two to merge drops the leading check and sends that error throughnamed_as_requested. #1327 leaves the not-found text to this PR.The v1.1.0 entry in
docs/manuals/07-upgrade-manual.mdconflicts 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:
ExclusiveStartBackupArn\n,\r\n,\r, U+0085, U+2028 or U+2029\n\n,\r\n\r\n,\n\r,\r\r, space, tab, FF, VT, NBSP, and mixes)Invalid Request: BackupArn is not validInvalid Request: The supplied ExclusiveStartBackupArn is not a valid backup arn\n,\r\n, FF, VT, NBSP, and with one\nafter the ARN)Invalid Backup ARNInvalid Backup ARNBackupNotFoundException,Backup not found:and the ARN as writtenDeleteBackup 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:
BackupArnInvalid Backup ARNInvalid Backup ARNInvalid Backup ARNInvalid Backup ARN.../table/<bad>/backup/+\n(caller's account)Invalid Backup ARNInvalid Backup ARN.../table/<bad>/backup/(caller's account)Invalid Backup ARNInvalid Backup ARNEach 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_itintests/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..../table/<bad>/backup/above. With the gate's strip put back, the two RestoreTableFromBackup requests of.../table/<bad>/backup/\ngotInvalid Request: BackupArn is not validtoo.trim_backup_arnandcheck_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.--forget-backupparsertrim_backup_arnput back: the new gate row fails.cargo +1.97.0 fmt --all -- --check, both commands ofclippy.ymlfor the touched crates,cargo +1.91.1 check --all-targetson them andcargo +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, inbackup_store::tests, fail on the build host, which has no directory whose ancestors belong to root or the test user. This change does not touchbackup_store.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
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.