Repository navigation
fix(auth): read the Date header and check the date as DynamoDB does - #1306
LeeroyHannigan wants to merge 7 commits into
Conversation
ExtendDB read the request date from X-Amz-Date only. With only a Date header, it answered that the request needs X-Amz-Date. It checked the date after the whole Authorization parse. Its text for a date in another form named no value. DynamoDB reads Date when the request has no X-Amz-Date, and an empty value is no date. It checks the date after the missing parameters and before the Bearer answer, the algorithm and the credential. For a value in another form it answers "Date must be in ISO-8601 'basic format'. Got '<value>'. See http://en.wikipedia.org/wiki/ISO_8601". Measured in us-east-1 on 21 Nov 2026. request_date picks the header, and the parse takes the timestamp check as a closure that it runs at that point. parse_authorization keeps its signature for its other callers. Fixes #1289.
demohan
left a comment
There was a problem hiding this comment.
The Date header is read as the service reads it at 6306c32, and the replay window is no wider than before. Signed and unsigned date headers, Date alone, both, neither, both disagreeing either way and empty values answer as in us-east-1 on SQLite and PostgreSQL, with X-Amz-Date winning when both are present and a scope date of the day before getting the service's text; 14 minutes either side authenticates and 16 is refused; and 20 unsigned rows give the service's check order. Since the request date is in the string to sign, a captured request resent with a fresh Date or X-Amz-Date gets a signature mismatch, and a fresh Date beside a stale X-Amz-Date is refused as expired. The 9 new tests fail on the base and pass here and live, eight controls fail as they should, fmt, clippy and the 1.91.1 check are clean, and CI is green on 59 of 59. It merges with #1304; onto main at 222d80a it conflicts in Cargo.lock and lib.rs as #1295 does, and once those are resolved the auth tests pass, #949's included, and the server builds.
I will approve once a test holds the window for a request dated only by Date, and a date header with a byte above 0x7F is read rather than dropped.
| headers | ||
| .get("x-amz-date") | ||
| .or_else(|| headers.get("date")) | ||
| .and_then(|v| v.to_str().ok()) |
There was a problem hiding this comment.
A date value with a byte above 0x7F fails to_str() and is dropped, so the request is treated as having no date: with X-Amz-Date: 20261129T012702 and a 0x80 byte, the service answers Date must be in ISO-8601 'basic format'. Got '20261129T012702\u0080'. ... (twice) and this head Authorization header requires existence of either a 'X-Amz-Date' or a 'Date' header. ..., on both backends, also with a valid Date beside it and with the value in Date alone. The base differs too and the request is refused either way. Decoding the value as Latin-1, as the base's parse does for Authorization, would match.
There was a problem hiding this comment.
d82e5a2 reads each byte of X-Amz-Date and Date as a Latin-1 character (request_date, verify.rs:210), with the latin1 helper that the Authorization parse uses too. A value with a byte above 0x7F is then a date, and the format check refuses it with the value echoed.
I measured it on 2 Dec, twice each, with a 0x80 byte after the time: X-Amz-Date alone, Date alone, and such an X-Amz-Date beside a valid Date. Each got Date must be in ISO-8601 'basic format'. Got '20261202T210318Z' with the 0x80 byte before the closing quote. The unit test a_date_with_a_byte_above_0x7f_is_refused_with_its_value and three rows of test_malformed_authorization_header hold the three requests. Without the Latin-1 read, the unit test and the three rows fail.
| @@ -140,8 +140,7 @@ impl AuthProvider for BuiltinAuthProvider { | |||
| .map_or(&b""[..], |value| value.as_bytes()); | |||
|
|
|||
| // Parse Authorization header | |||
There was a problem hiding this comment.
No test holds the window for a request dated only by Date: with the window check skipped for such a request, all Rust tests and the 72 cases of the new class pass, and Date-only requests 16 minutes in the past or future authenticate. A unit test and a fidelity row at 16 minutes either side would hold it. The wiring here is held only by the Python rows. The comments here and at verify.rs:164, :170 and :193 still name X-Amz-Date alone, and after the merge docs/manuals/10-security-model.md:58-59 (from #949) describes the old order.
There was a problem hiding this comment.
d82e5a2 adds the unit test a_date_header_has_the_window_of_x_amz_date (verify.rs), which sends Date alone at 16 and 14 minutes either side of now. The fidelity test test_date_header_outside_the_window_is_refused sends Date alone at 16 minutes either side. With the window check skipped for a request with no X-Amz-Date, the unit test and both fidelity rows fail.
DynamoDB answered the two 16-minute requests with Signature expired: ... and Signature not yet current: ... on 3 Dec, twice each. At 14 minutes before now it went on to the key lookup. ExtendDB's type and text for the refusal are its own (#805), so the fidelity test checks the start of the text.
The comments at verify.rs lines 164, 171 and 195 now name the request date, and no comment in lib.rs names one date header alone. Steps 2 to 4 of the security model manual now name both date headers. They put the date check after the missing parameters, and compare the scope date with the request date.
parse_authorization_with_date_check takes the flag of the operations that read the parts by position, and runs the date check after those parts are read.
DynamoDB reads each byte of X-Amz-Date and Date as a Latin-1 character. A value with a byte above 0x7F is therefore a date, and the format check refuses it with the value echoed. Before this change, ExtendDB dropped such a value. The request then got the missing date text. Tests hold the 15 minute window of a request dated only by Date, at 16 minutes before and after now. The comments on the request date and the security model manual name both date headers. The manual also gives the place of the date check among the checks of the parse. Measured in us-east-1 on 2 and 3 Dec 2026, each request twice.
|
…parse d82e5a2 reads a date header as Latin-1, so a byte above 0x7F becomes a character of two bytes in the date string. The basic-format parse slices each field of that string at a fixed byte offset. It panicked when an offset fell inside such a character. The sigv4_timestamp fuzz target found the 15-byte X-Amz-Date value 20150930T136, the byte 0xCE, then 0Z. The parse now refuses a value that is not ASCII before it slices the fields. The request gets the format refusal with the value echoed, which is DynamoDB's answer to that value (measured 2026-12-03).
The manual keeps this branch's step 2 and adds the sentence on the valid request body.
05afa34 gave the rows of a_date_with_a_byte_above_0x7f_is_refused_with_its_value a type that the type_complexity lint of clippy refuses under -D warnings. The test now allows that lint on that one statement.
Changes since the last review
mainat 01556cf.parse_authorization_with_date_checknow also takes the flag of the item operations, which read the parts by position.Date. The comments on the request date and steps 2 to 4 of the security model manual now name both date headers.sigv4_timestampfuzz job found at d82e5a2. The Latin-1 read of d82e5a2 makes a byte above 0x7F a character of two bytes, and the basic-format parse sliced the fields at byte offsets. The 15-byteX-Amz-Datevalue20150930T136, the byte 0xCE, then0Zmade it panic. The parse now refuses a value that is not ASCII before it slices the fields. The request gets the format text with its value, which DynamoDB answered on 3 December.a_date_with_a_byte_above_0x7f_is_refused_with_its_valuehas a row with that value.mainat c8e66fb. That head limits the read by position of the item operations to a valid request body in its texts (fix(auth): answer an Authorization part with no '=' with DynamoDB's text #1277). Step 2 of the security model manual keeps this branch's text and adds that sentence.type_complexitylint of clippy on the rows of that test.What
The server now reads the request date and checks it as DynamoDB does:
X-Amz-Datevalue when the request has that header, else theDatevalue. An empty value is no date.request_dateincrates/auth/src/sigv4/verify.rspicks it, andextract_timestampreads it, sovalidate_timestampandverify_signatureread the same value. Before, the server readX-Amz-Dateonly.Authorizationparse. A date with a byte above 0x7F gets the format text below. Before d82e5a2, such a date was dropped, and the request got the missing date text.Beareranswer, the algorithm and the credential. Before, it ran after the wholeAuthorizationparse.Date must be in ISO-8601 'basic format'. Got '<value>'. See http://en.wikipedia.org/wiki/ISO_8601.parse_authorization_with_date_checkincrates/auth/src/sigv4/parse.rstakes the date check as a closure and runs it at that point.authenticateincrates/auth/src/lib.rspassesvalidate_timestamp, which checks the form and the 15 minute window at that point.parse_authorizationkeeps its signature for its other callers: the fuzz targets, the differential tests and the unit tests. It runs the parse with a check that does nothing.docs/manuals/10-security-model.mdgives the request date and the place of the date check in steps 2 to 4 of "SigV4 Verification".The base of this PR is #1295, which changes the same parse.
Why
These are DynamoDB's answers, measured in us-east-1 on 21 November 2026 with DescribeTable requests of a table that does not exist. Each request went out twice and got the same answer both times. The
Authorizationvalue used the documentation's example key and a signature of 64 zeros. Its scope date is the send day unless the row says otherwise. Each date is the time of the send unless the row gives it.Date must be in ISO-8601 'basic format'. Got 'v'. See http://en.wikipedia.org/wiki/ISO_8601.Authorization header requires existence of either a 'X-Amz-Date' or a 'Date' header.and the hash of the value.Authorization header requires existence of 'X-Amz-Date' header.The security token included in the request is invalid.The column "ExtendDB on #1295" gives the answers of #1295's head 86a0378.
AuthorizationDatein the HTTP date formCredential=xCredential must have exactly 5 slash-delimited elements, ...AWS4-XUnsupported AWS 'algorithm': 'AWS4-X'.Bearerand the three pairsSignatureAuthorization header requires 'Signature' parameter.and the hashX-Amz-Datein the HTTP date formDate must be in ISO 8601 basic format (YYYYMMDDTHHMMSSZ)X-Amz-Datein the HTTP date form,Datein the basic formX-Amz-DatevalueX-Amz-DatevalueDatein the basic formDatein the basic formDate in Credential scope does not match YYYYMMDD from ISO-8601 version of date from HTTP.Datewith an empty valueX-Amz-Date,Datein the HTTP date formDate must be in ISO 8601 basic format (YYYYMMDDTHHMMSSZ)Datein the ISO-8601 extended formDate: 20260101T000000ZCredential=xSignature expired: 20260101T000000Z is now earlier than <edge> (<now> - 15 min.)Credential must have exactly 5 slash-delimited elements, ...Signature expired: the signature is too old or the request date is too far in the future.At 6306c32, 25 of the 30 measured requests got DynamoDB's type name and message, where 7 did on #1295. Every request that got DynamoDB's answer on #1295 still got it. The other five:
X-Amz-Dateand inDate(A request date in the ISO-8601 extended form gets IncompleteSignatureException, where DynamoDB reads the date #1302).ExtendDB sends UNREC in another
__typenamespace than DynamoDB (#1303).These answers were measured on 2 and 3 December 2026 in the same way, each request twice:
X-Amz-Datewith a 0x80 byte after the timeDatewith a 0x80 byte after the timeX-Amz-Datewith a 0x80 byte, and a validDateX-Amz-Datevalue, with the byteX-Amz-Dateof 15 bytes with a 0xCE byte in the time (3 December)Datealone, 16 minutes before nowSignature expired: ...Signature expired: ...(#805)Datealone, 16 minutes after nowSignature not yet current: ...Signature expired: ...(#805)Datealone, 14 minutes before nowFixes #1289
Testing done
cargo test -p extenddb-auth: 548 unit tests, 14sigv4_differentialtests and 3 doc tests passed.cargo +1.97.0 clippy -p extenddb-auth --all-targets -- -D warnings,cargo +1.97.0 fmt --all -- --checkandcargo +1.94.0 check -p extenddb-auth --all-targetsare clean. The cargo commands ran with--locked.cargo test -p extenddb-wasm-adapterpassed its 3 unit tests and the parity corpus. The clippy step of the WebAssembly job is clean, andcargo fuzz buildbuildssigv4_authorization,sigv4_verifyandsigv4_timestamp.cargo fuzz run sigv4_timestampran as the Fuzz job runs it. At d82e5a2 it stopped on the input above after 6 runs. At fix(auth): name every missing Authorization parameter as DynamoDB does #1295's head fd7201c, it found no failure in 600 seconds (81,566,555 runs). At 782ec83, it found no failure in 600 seconds (65,683,423 runs). With the old first check of the basic-format parse,a_date_with_a_byte_above_0x7f_is_refused_with_its_valuepanics at the byte offset.the_date_check_runs_after_the_missing_parametersfails with the date check moved below the credential check.the_request_date_is_x_amz_date_else_datefails without the rule that an empty value is no date. With the date read byto_str,a_date_with_a_byte_above_0x7f_is_refused_with_its_valueand the three wire rows of the byte fail. With the window check skipped for a request with noX-Amz-Date,a_date_header_has_the_window_of_x_amz_dateand both rows oftest_date_header_outside_the_window_is_refusedfail.tests/test_auth_error_fidelity.pypassed 101 tests,tests/test_sigv4_scope_date.py11, andtest_missing_auth_headeroftests/test_auth_integration.py4.tests/test_auth_error_fidelity.py,tests/test_auth_integration.py,tests/test_auth_permissions.pyandtests/test_sigv4_scope_date.pypassed 238 tests on SQLite, and the 30 requests got the answers in the first table. Against fix(auth): name every missing Authorization parameter as DynamoDB does #1295, that head's version oftests/test_auth_error_fidelity.pyfailed 9 tests: the 8 new rows andtest_basic_date_header_is_the_request_date.Dateheader in the basic form got HTTP 200, and OLD on fix(auth): name every missing Authorization parameter as DynamoDB does #1295. No measurement of DynamoDB used a signed request of that form.parse_authorization_with_date_checkends withOk(...).map(...). The tuple formOk((ParsedAuthorization { ... }, checked))is two lines longer after rustfmt.Line counts: production +71 -24, tests +210 -8, docs +3 -3.
782ec83 carries main at c8e66fb, through #1295's head. Two open PRs change
validate_timestamptoo: #889 by Dodothereal (#805) conflicts with this head inverify.rs, and #1125 by jgaul3 inlib.rs,verify.rsandtests.rs. The PR that merges second resolves the conflict. #889 changes the text thata_date_header_has_the_window_of_x_amz_dateasserts. #1356, which sits on this branch, needs a merge of this head.Not in this PR:
__typenamespace of UnrecognizedClientException (UnrecognizedClientException carries the com.amazonaws.dynamodb.v20120810 namespace, where DynamoDB sends com.amazon.coral.service #1303).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
A request dated only by
Dateis now checked against that date, and a signed request of that form can authenticate. A date in another form, or with a byte above 0x7F, gets DynamoDB's format text with its value, where ExtendDB sent other texts. The status of the refused requests stays 400.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.