Repository navigation
fix(backup): strip only one trailing line terminator from a backup ARN #1328
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -238,7 +238,7 @@ pub(crate) fn check_stream_arn(arn: &str) -> Result<(), DynamoDbError> { | |
| /// `RestoreTableFromBackup`). U+0000 in the backup id keeps the engine's | ||
| /// `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) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
The same holds with |
||
| Some(res) if matches!(res.sub, Some(SubResource::Backup(_))) && !in_pattern(&res.table) => { | ||
| Err(validation("Invalid Backup ARN".to_owned())) | ||
| } | ||
|
|
@@ -539,6 +539,21 @@ mod tests { | |
| ); | ||
| let backup_id = format!("{}/backup/0170\u{0}", table("ok")); | ||
| assert!(check_backup_arn(&backup_id).is_ok(), "left to the engine"); | ||
| // The gate parses the ARN as sent: whitespace before it is left to | ||
| // the later checks, and a trailing line terminator stays in the | ||
| // backup id, also when it is the whole id (measured on 2026-11-25). | ||
| assert_eq!( | ||
| message(check_backup_arn(&format!("{backup}\n"))).unwrap(), | ||
| "Invalid Backup ARN" | ||
| ); | ||
| assert_eq!( | ||
| message(check_backup_arn(&format!("{bad}/backup/\n"))).unwrap(), | ||
| "Invalid Backup ARN" | ||
| ); | ||
| assert!( | ||
| check_backup_arn(&format!(" {backup}")).is_ok(), | ||
| "left to the engine" | ||
| ); | ||
| assert_eq!( | ||
| message(check_tag_resource_arn(&bad)).unwrap(), | ||
| format!("Invalid TableArn: Invalid ResourceArn provided as input {bad}") | ||
|
|
||
There was a problem hiding this comment.
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 asInvalid Backup ARN.trim_backup_arnstrips only a line terminator, so the id stays" "or"\t"and reaches the printable-ASCII test incheck_backup_arn. Measured on DynamoDB twice, identical, and on SQLite builds:DescribeBackup {"BackupArn": "arn:aws:dynamodb:us-east-1:123456789012:table/<table>/backup/ "}Invalid Backup ARNInvalid Request: BackupArn is not validSame for DeleteBackup, and for the ids
\t, FF,\n\nand\t\n(22 cells per operation). A one-line check that treats a whitespace-only id asInvalid Backup ARNwould 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_idafter the strip and answersInvalid Backup ARN. DynamoDB and main answerInvalid Request: BackupArn is not valid. The older mapping of a non-hex id toInvalid Backup ARNis the real difference: DynamoDB answersnot validfor every bad id (for example the ARN followed bya), and the PR makes three more terminators reach that mapping. Fixing the mapping fixes both.