Repository navigation
fix(auth): read the request date in the basic and extended ISO-8601 forms - #1356
LeeroyHannigan wants to merge 6 commits into
Conversation
Move the test module of crates/auth/src/sigv4/verify.rs to crates/auth/src/sigv4/verify/tests.rs. Each line is four spaces less indented, and `#[cfg(test)] mod tests;` takes the place of the module. Nothing else changes.
ExtendDB read the request date only in the basic form YYYYMMDDTHHMMSSZ. A date in the extended form got the 'basic format' text. So did a value with a fraction, an offset, no zone or no time. DynamoDB reads X-Amz-Date and Date as an ISO-8601 date and time, in the basic or the extended form. A fraction and a zone are optional. The zone is Z or an offset such as +01:00, +0100 or +01, and a time with no zone is UTC. A date with no time, or with a T and nothing after it, is midnight UTC. Each part has a limit: month 12, day 31, hour 24, minute 60, second 60, and two digits of offset hours and minutes. The service then adds up the parts with no calendar check. Month 00 is January, day 00 is the day before the first, and 2026-02-30 is 2 March. T24:00:00 is the next midnight. A second of 60 is the next minute, and a minute of 60 the next hour. The service converts the instant to UTC and drops the fraction. The skew check, the scope date and the date line of the string to sign use this form. That is also true for a second or a minute of 60. The x-amz-date and date canonical headers keep the value as sent. A part over its limit gets the 'basic format' text. So do a lower-case t or z, a space for T, a time without seconds and a time of five digits. Measured in us-east-1 on 21 and 22 Nov 2026. parse_request_date reads the measured forms into an instant with the time crate, and basic_form writes the UTC basic form. validate_timestamp returns that form, so the scope check and the string to sign use it. Fixes #1302.
demohan
left a comment
There was a problem hiding this comment.
More request date forms are read as the service reads them at 58f1097, but two readings differ from the service in ways that let a request authenticate here that the service refuses (below). With DescribeTable and ListTables requests signed by hand, each sent twice to us-east-1 and to this head and its base 6306c32 on SQLite and PostgreSQL, the two backends answered alike on all 262 probes; this head differs from the service on 89 and the base on 154, and on 28 the base matched the service and this head does not. Where they agree: the string to sign carries the UTC basic form with the fraction cut off, second 60 and hour 24 roll over, hour 25, second 61, month 13 and day 32 are refused, +5:30 and +05:30:00 are refused, the scope date must be the UTC day, and under this head's own reading an offset cannot move a request outside the 15-minute check, which uses the same instant as the string to sign. The parser is linear and does not panic up to 200,000 bytes. fmt, clippy and the 1.91.1 check are clean, 47 of the 67 new Python rows fail on the base, nine controls fail as they should, and CI is green on 61 of 61.
The stack does not merge with main at 222d80a: verify.rs conflicts with #1009 (web_time) and tests.rs with #949 (now scope_tests.rs), besides #1295's conflict in lib.rs. Resolved by hand, with #1304 merged, fmt, clippy, the auth tests, the wasm build and the 1.94.0 check pass. The body's "no conflict with origin/main" no longer holds.
I will approve once a fraction of ten or more digits is refused, a negative offset with minutes is read as the service reads it, main is merged, and tests hold the field limits below.
| return None; | ||
| } | ||
| let rest = rest | ||
| .strip_prefix('.') |
There was a problem hiding this comment.
The service reads up to nine fraction digits and refuses ten or more with the basic format text, including .0000000000Z, with an offset and on a past date; this takes any number, so a correctly signed request with a ten-digit fraction answers 200 here where the service answers 400 IncompleteSignatureException, measured with ListTables and DescribeTable, twice each. The base refused every fraction, so these are new. Refusing more than nine digits, with rows for nine and ten, would match.
There was a problem hiding this comment.
Fixed in ff0b97d. parse_request_date now refuses a fraction of ten or more digits with the basic format text.
I measured both lengths on 3 Dec at 13:05Z with DescribeTable requests of a table that does not exist, each sent twice. 2026-12-03T13:05:06.123456789Z got UnrecognizedClientException, so the service read the date. 2026-12-03T13:05:07.1234567890Z got IncompleteSignatureException with the basic format text.
Both values are rows of the unit table in crates/auth/src/sigv4/verify/tests.rs. nine-digit-fraction and ten-digit-fraction are rows of the same two forms in _DATE_FORMS in tests/test_auth_error_fidelity.py. With no limit, or with a limit of 10, the ten-digit row fails.
| if !rest.is_empty() { | ||
| return None; | ||
| } | ||
| sign * (hours * 3600 + minutes * 60) |
There was a problem hiding this comment.
For a negative offset with minutes, the service applies the minus to the hours only: it reads 2026-01-01T00:00:00-03:30 as 20260101T023000Z, and -00:30 as +00:30. This applies it to both, so a request dated 2026-11-28T21:57:28-03:30 sent at 01:27:28Z is accepted here and refused by the service as expired at 20261129T002728Z, while the value the service accepts (...T22:57:28-03:30) is refused here; the same holds in basic form (-0330), at -05:45 and through the Date header. No test has a negative offset with minutes.
There was a problem hiding this comment.
Fixed in ff0b97d. The sign of an offset now applies to its hours only: parse_request_date computes sign * hours * 3600 + minutes * 60.
Measured on 3 Dec at 13:05Z, each request twice:
2026-01-01T00:00:00-03:30inX-Amz-Dategot "Signature expired: 20260101T023000Z is now earlier than ...". The same value inDate, with noX-Amz-Date, got the same text.2026-12-03T10:35:04-03:30,20261203T103505-0330and2026-12-03T13:35:05-00:30, sent at 13:05Z, got UnrecognizedClientException. So the service read each one as the time of the send.
These four values are rows of the unit table in crates/auth/src/sigv4/verify/tests.rs. minus-three-thirty, basic-minus-three-thirty and minus-zero-thirty are rows of _DATE_FORMS. X-Amz-Date and Date go through the same parse_request_date, and the_request_date_is_x_amz_date_else_date holds the choice of header. With the old sign rule, the first row fails with 20260101T033000Z.
| None if !rest.is_empty() => return None, | ||
| None | Some("") => (0, ""), | ||
| Some(rest) => { | ||
| let (hour, minute, second, rest) = three::<u8>(rest, 2, ':')?; |
There was a problem hiding this comment.
The service also reads forms this refuses: a time of hours, or hours and minutes, when no zone or fraction follows (20261129T0127 and 2026-11-29T01:29, signed as ...012700Z), a lower-case z (...T01:27:28z; the body's measurement put t and z in one value, and only t is refused), and an extended ordinal date (2026-333T01:27:28Z, 2026-333T012728Z; 2026-366 rolls into the next year and 2026-999 is refused). The doc comment above says the other way for each.
There was a problem hiding this comment.
The doc comment of parse_request_date now says what the code does (ff0b97d, with shorter sentences in 01d80a0).
parse_request_date reads a lower-case z now. On 3 Dec at 13:05Z, 2026-12-03T13:05:14z got UnrecognizedClientException twice. The value is a row of the unit table, and lower-case-z is a row of _DATE_FORMS. 2026-11-21t22:06:36z stays refused because of the t.
This PR still refuses a time of hours, or of hours and minutes, with nothing after it, and the extended ordinal date. Reading them needs a second form of the time parse and a day-of-year date, each with limits to measure. #1566 tracks them, with your rows. The doc comment names both forms as ones that the service reads and this parse refuses.
| /// `t` or `z`, a space for `T`, a `,` before the fraction, a time without | ||
| /// seconds and a `T` followed by a zone alone are refused. | ||
| fn parse_request_date(s: &str) -> Option<time::OffsetDateTime> { | ||
| let (year, month, day, rest) = three(s, 4, '-')?; |
There was a problem hiding this comment.
Year 0000 gets the basic format text on the service and Signature expired here; an instant past 9999 (99991231T240000Z) gets "not yet current" with 100000101T000000Z there and the format text here, and on the MongoDB build the time crate has large-dates enabled, so the body's "stops at 9999" depends on the build. Neither authenticates. No test holds the field limits: raising the minute, second or day limit by one, dropping the check for text after the offset, accepting a one-digit offset hour or a , in the fraction each pass the unit tests, though the service and this head refuse every value they would let through.
There was a problem hiding this comment.
The unit table and _DATE_FORMS now have rows one past each limit (ff0b97d). These are minute 61, second 61, day 32, +5:30, +05:30:00 and .12,3. On 3 Dec at 13:05Z the service refused each one with the basic format text, each request sent twice. Rows for month 12 (20261231T000000Z) and for 20261121T240100Z hold values that the service and this parse read. The service named 20261231T000000Z and 20261122T000100Z in its texts.
I changed the code one limit at a time and ran the unit table. Each of these changes fails a row:
- a minute or second limit of 61
- a day limit of 32, a month limit of 11 or an hour limit of 25
- no check for text after the offset
- a one-digit offset hour
- a
,in the fraction
A month limit of 13 still passes, because time::Month::try_from refuses month 13. The month 13 rows hold that limit.
This parse refuses year 0000 now. 00001203T130512Z got the basic format text from the service, and 00010101T000000Z got "Signature expired: 00010101T000000Z is now earlier than ...". Both values are rows.
99991231T240000Z stays as it is. The service answered "Signature not yet current: 100000101T000000Z is still later than ...". A build without the MongoDB crate answers the basic format text here. A build with it reads 10000-01-01 and answers the skew text, because bson turns on the large-dates feature of time. Neither build authenticates the request. The skew type and text differ from the service's for every date outside the window (#805). The PR body now gives the answer of each build and the service's measured answer.
The base now reads each byte of the request date as a Latin-1 character and refuses a date that is not ASCII before the parse. It reads the clock through web_time. It adds tests for a byte above 0x7F and for the window of a Date header. Conflicts: - crates/auth/src/sigv4/verify.rs: parse_request_date keeps the ISO-8601 forms of this branch and starts with the ASCII check of the base. The clock lines are those of the base, without the format comment. The doc comment of validate_timestamp names both refusals. The two new tests of the base go to verify/tests.rs, and the window test writes its dates with basic_form. - crates/auth/src/tests.rs: the tests that the base moved to scope_tests.rs stay there. make_date_stale in scope_tests.rs calls basic_form, as this branch changed it in tests.rs. - tests/test_auth_error_fidelity.py: both sets of date constants and both sets of tests stay. _BYTE_DATE_TEXT uses _BAD_DATE.
…DB does DynamoDB applies the minus of a negative offset to the hours only. It reads 2026-01-01T00:00:00-03:30 as 20260101T023000Z, in the extended form, in the basic form and through the Date header. It reads -00:30 as +00:30. The parse applied the minus to the minutes too. So a request that the service refuses as expired was inside the window here. The parse refused a date that the service reads as now. DynamoDB reads up to nine fraction digits. Ten or more get the basic format text, and so does year 0000. It reads year 0001. It reads a lower-case z as the zone. The parse read any number of fraction digits and year 0000, and it refused z. parse_request_date now applies the sign to the hours only, refuses a fraction of ten or more digits and year 0000, and reads z. Its doc comment also names two forms that the service reads and the parse refuses. They are a time of hours, or of hours and minutes, with nothing after it, and an ordinal date. The unit table and the Python table get a row for each case. Other rows are one past a limit: minute 61, second 61, day 32 and a one-digit offset hour. Text after the offset and a comma in the fraction get rows too. Rows for month 12 and for hour 24 with minutes hold values that the parse reads. Steps 3 and 4 of the security manual now give the forms that the server reads, and the scope date as the UTC day. Measured in us-east-1 on 3 Dec 2026, each request twice.
…he hours The minute 60 rows of test_the_date_line_is_the_utc_basic_form wrote an offset of minus the current minute as -00MM. DynamoDB applies the minus of an offset to the hours only (measured 3 Dec 2026). So -00MM is MM minutes ahead of UTC, and the rows failed with the parse of the last commit. The rows now write -01 and 60 - MM, which is MM minutes behind UTC. The instant is still the current time at any hour.
The doc comment of parse_request_date and steps 3 and 4 of the security manual had sentences of 27 to 54 words. Each one is now two or three sentences, with the same facts. No code changes.
|
@demohan The replies in the threads answer the fraction, the negative offset, the field limits and the forms not read. Main: this branch now merges the head of #1306 (782ec83) in b0160d1. #1306 holds main at c8e66fb, with #1009 and #949, and #1295 is its base. The merge keeps the ASCII check of #1306 at the start of The body no longer says "no conflict with origin/main". It lists the conflicts with open PRs at the new head. |
Changes since the last review
parse_request_date, and it moves the two new tests of fix(auth): read the Date header and check the date as DynamoDB does #1306 tocrates/auth/src/sigv4/verify/tests.rs.z. The unit table and the Python table get a row one past each limit. Steps 3 and 4 ofdocs/manuals/10-security-model.mdgive the forms that the server reads.tests/test_sigv4_scope_date.pywith the sign on the hours. Their-00MMoffset was MM minutes ahead of UTC under the rule of ff0b97d.parse_request_dateand of the manual's steps 3 and 4. It changes no code.What
The server now reads the request date in the ISO-8601 forms below, which DynamoDB reads, and it uses the date as DynamoDB does. This applies to
X-Amz-Date, and toDatewhen the request has noX-Amz-Dateheader.YYYYMMDDorYYYY-MM-DD, from the year 0001. The time follows an upper-caseTand isHHMMSSorHH:MM:SS. The date and the time each use either form..and zero to nine digits. The zone isZ,zor an offset with either sign:+01:00,+0100or+01. A time with no zone is UTC.-03:30is 2 hours 30 minutes behind UTC, and-00:30is 30 minutes ahead of UTC.Twith nothing after it, is midnight UTC.2026-02-30is 2 March, andT24:00:00is the next midnight.basic formattext:,before or in the fractiont, or a space in place ofTTwith only a zoneYYYYMMDDTHHMMSSZ, with no fraction. It uses this UTC basic form for the 15 minute check, the scope date and the date line of the string to sign. Thex-amz-dateanddatecanonical headers keep the value as sent.Before, the server read only the basic form with a
Z. It also read basic values with a part over its limit, such as month 13, which DynamoDB refuses.In
crates/auth/src/sigv4/verify.rs,parse_request_datereplacesparse_iso8601_basic.request_instantreads the request date and returns the instant or thebasic formattext.basic_formwrites the UTC basic form.validate_timestampreturns that form forcheck_scope, andverify_signatureuses it for the scope date and the string to sign. Three test helpers callbasic_formin place of their own copies of the format:make_headers_with_authincrates/auth/src/tests.rs,make_date_staleincrates/auth/src/scope_tests.rsand the window test inverify/tests.rs.The first commit moves the test module of
verify.rs(lines 249 to 629) tocrates/auth/src/sigv4/verify/tests.rswith no other change. Each moved line is four spaces less indented. The second commit has the fix. The merge and the three commits after it are the changes since the last review.The base of this PR is #1306, which reads the
Dateheader and checks the date before the rest of theAuthorizationparse.Why
Fixes #1302
These are DynamoDB's answers, measured in us-east-1 on 21 and 22 November and on 3 December 2026. Each request went out twice and got the same answer both times. Each date is the time of the send unless the row gives another time. ExtendDB got the same forms at the time of its run.
Authorizationvalue used the documentation's example key and a signature of 64 zeros.x-amz-datecanonical header is the value as sent.The answers:
The security token included in the request is invalid.The service read the date and did not find the key.Date must be in ISO-8601 'basic format'. Got '<value>'. See http://en.wikipedia.org/wiki/ISO_8601.Signature expired: the signature is too old or the request date is too far in the future.X-Amz-Date2026-11-21T22:06:32Z2026-11-21T22:06:34.123456Z2026-11-21T23:06:35+01:002026-11-21T22:06:362026-11-21T220639Z2026-11-21T23:08:03+012026-11-21T22:08:04.Z2026-11-23T00:56:18+26:002026-11-21t22:06:36z2026-11-21T22:08Z2026-11-21T22:56:17,123Z20261321T225656Z20261121T225799Z20261100T225657Z20261031T225657Z)2026-11-21T24:00:00Z20261122T000000Z)2026-11-22T01:07:13+03:00, scope date the UTC day2026-11-21T22:06:45Z, date line20261121T220645Z2026-11-21T22:06:44Z, date line as sent2026-11-22T01:07:15+03:00, date line20261121T220715Z20261122T010715Z(the local time)20261122T005260Z, date line20261122T005300ZThe local day of U18 and U19 is the day after the UTC day. ExtendDB got U18 and U19 with a
-03:00offset at 01:48Z, so that the local day was again not the UTC day.The rows of 3 December went out from 13:05:03Z to 13:05:15Z. The ExtendDB column is a server built from the head, on SQLite and on PostgreSQL, with the same forms from 13:58Z to 14:00Z. A value that carries the time of the send carried the new time. Both backends gave the same answers. On #1306, each value that is not in the basic form gets FORMAT.
X-Amz-Date: 2026-01-01T00:00:00-03:3020260101T023000Z)Date: 2026-01-01T00:00:00-03:3020260101T023000Z)X-Amz-Date: 2026-12-03T10:35:04-03:30X-Amz-Date: 20261203T103505-0330X-Amz-Date: 2026-12-03T13:35:05-00:30X-Amz-Date: 2026-12-03T13:05:06.123456789ZX-Amz-Date: 2026-12-03T13:05:07.1234567890ZX-Amz-Date: 20261203T136107ZX-Amz-Date: 20261203T130561ZX-Amz-Date: 20261232T130509ZX-Amz-Date: 2026-12-03T13:05:09+5:30X-Amz-Date: 2026-12-03T13:05:10+05:30:00X-Amz-Date: 2026-12-03T13:05:10.12,3ZX-Amz-Date: 20261231T000000Z20261231T000000Z)X-Amz-Date: 20261121T240100Z20261122T000100Z)X-Amz-Date: 00001203T130512ZX-Amz-Date: 00010101T000000Z00010101T000000Z)X-Amz-Date: 99991231T240000Z100000101T000000Z)X-Amz-Date: 2026-12-03T13:05:14zOn #1306, 15 of the 62 rows of 21 November get DynamoDB's answer. At 58f1097, 51 of those 62 rows got DynamoDB's type name and message, and so did the 5 rows of 22 November. Every row that got DynamoDB's answer on #1306 still got it. The other 11 rows are U9, U14, V5, V11, V14, M3, M4, M5, M10, M11 and M12. In these rows, the server reads the instant that DynamoDB's text gives. It then refuses the date with the 15 minute check, with ExtendDB's type and text (#805, PR #889).
The changes since the last review read four kinds of value in a new way. They are a negative offset with minutes, a fraction of ten or more digits, the year 0000 and a lower-case
z. The 62 rows did not go out again at this head. The rows of the first table keep their answers. U7 has a lower-casez, and its lower-casetstill gets FORMAT.botocore, which the AWS CLI and boto3 use, writes
X-Amz-Datein the basic form from adatetime. For a basic value whose parts are a valid date and time,basic_formgives back the same bytes. So these requests get the same scope date and date line as before.An instant after the year 9999, such as
99991231T240000Z, gets FUTURE(100000101T000000Z) from DynamoDB (measured on 3 December). A build of the server without the MongoDB crate refuses it with FORMAT, because thetimecrate stops at the year 9999. A build with the MongoDB crate gets SKEW, becausebsonturns on thelarge-datesfeature oftime. Neither build authenticates the request. The value is outside the 15 minute window.#889 adds
format_iso8601_basic, which writes the same form asbasic_form. The PR that merges second should call the function of the other PR and remove its own. DynamoDB's skew texts give the instant in the UTC basic form (M3, V11), which isbasic_form(request).Testing done
cargo +1.97.0 test -p extenddb-auth --no-fail-faston the head: 548 unit tests, 14sigv4_differentialtests and 3 doc tests passed.cargo +1.97.0 test -p extenddb-core --libpassed 1,260 tests.cargo +1.97.0 test -p extenddb-server --libpassed 521 tests. The 5backup_store::teststhat fail on the test host (storage-sqlite: the two write_lock_tests fail when an ancestor of the Cargo target directory is owned by another user #1414) failed there too.cargo +1.97.0 fmt --all -- --checkis clean. Both clippy commands of.github/workflows/clippy.yml(cargo +1.97.0 clippy --all-targetswith each feature set,-D warnings) are clean, and so arecargo +1.94.0 check -p extenddb-auth --all-targetsand the WebAssembly clippy step.cargo test -p extenddb-wasm-adapterpassed, with the parity corpus.cargo fuzz buildofsigv4_authorization,sigv4_verifyandsigv4_timestamppassed, and so did thedoc_version_literalstest.z.,in the fractiontime::Month::try_fromrefuses month 13.validate_timestamp_returns_the_utc_basic_form. With calendar limits (a calendar check of the date, hour 23, minute 59, second 59), 17 rows failed. They were 13 values that DynamoDB reads, and S12 to S15.tests/test_auth_error_fidelity.pyandtests/test_sigv4_scope_date.pypassed 192 tests against ExtendDB on SQLite and 192 on PostgreSQL. Each server was a debug build of the head on 127.0.0.1.match, which 58f1097 writes asmap_or. The two checks do not cover the changes since the last review.Line counts:
verify.rs+1 -380,verify/tests.rs+381.verify.rs, code +7 -6 and doc comments +24 -15. Tests +54 -12, and the manual +2 -2. The merge puts the ASCII check of fix(auth): read the Date header and check the date as DynamoDB does #1306 (3 lines) at the start ofparse_request_date. It also puts the two new tests of fix(auth): read the Date header and check the date as DynamoDB does #1306 inverify/tests.rs(+68 -1 against 58f1097).With origin/main at c057660, the head merges with no conflict. #949 and #1009 are in main and in #1306 now. Against the open PRs, this PR adds these conflicts to those of #1306:
tests/test_auth_error_fidelity.py, where both PRs add an import line. Keep both lines.verify.rs, and this PR adds hunks there: the move of the test module, andparse_request_datein place ofparse_iso8601_basic. fix(auth): answer InvalidSignatureException for timestamps outside skew window (#805) #889 adds four tests to the inline module, which go incrates/auth/src/sigv4/verify/tests.rs. There,validate_timestamp_at(headers, now)starts withlet request = request_instant(headers)?;, usesrequest.unix_timestamp()as the epoch and returnsOk(basic_form(request)). feat(auth): add EXTENDDB_DEV_IGNORE_CLOCK_SKEW for dev-mode builds #1125 changesparse_iso8601_basicto refuse February 30 and hour 24, which DynamoDB reads (M rows of 21 November).Not in this PR:
2026-333. DynamoDB reads them, and this PR refuses them (A request date with a time of hours or of hours and minutes, or an ordinal date, gets IncompleteSignatureException, where DynamoDB reads it #1566).__typenamespace of UnrecognizedClientException (UnrecognizedClientException carries the com.amazonaws.dynamodb.v20120810 namespace, where DynamoDB sends com.amazon.coral.service #1303, PR fix(core): send UnrecognizedClientException in the coral.service namespace #1330).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
None for a client that writes
X-Amz-Datein the basic form from a valid date and time, as the AWS SDKs do. A request whose date is in another form that DynamoDB reads now authenticates. A basic value with a part over its limit, such as second 99, getsIncompleteSignatureException, as on DynamoDB. Before, the server read such a value.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.