Skip to content

fix(auth): read the Date header and check the date as DynamoDB does - #1306

Open
LeeroyHannigan wants to merge 7 commits into
fix/1270-authorization-textsfrom
fix/1289-date-header
Open

LeeroyHannigan wants to merge 7 commits into
fix/1270-authorization-textsfrom
fix/1289-date-header

Conversation

@LeeroyHannigan

@LeeroyHannigan LeeroyHannigan commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator

Changes since the last review

  • 1367d94 and ed03f00 merge fix(auth): name every missing Authorization parameter as DynamoDB does #1295's new head, fd7201c, which carries main at 01556cf. parse_authorization_with_date_check now also takes the flag of the item operations, which read the parts by position.
  • d82e5a2 reads each byte of a date header as a Latin-1 character. A date with a byte above 0x7F then gets the format text with its value. It adds tests that hold the 15 minute window of a request dated only by Date. The comments on the request date and steps 2 to 4 of the security model manual now name both date headers.
  • 05afa34 fixes a panic that the sigv4_timestamp fuzz 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-byte X-Amz-Date value 20150930T136, the byte 0xCE, then 0Z made 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_value has a row with that value.
  • 1ec7587 merges fix(auth): name every missing Authorization parameter as DynamoDB does #1295's new head, 8f84bc7, which carries main at 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.
  • 782ec83 allows the type_complexity lint of clippy on the rows of that test.

What

The server now reads the request date and checks it as DynamoDB does:

  • The request date is the X-Amz-Date value when the request has that header, else the Date value. An empty value is no date. request_date in crates/auth/src/sigv4/verify.rs picks it, and extract_timestamp reads it, so validate_timestamp and verify_signature read the same value. Before, the server read X-Amz-Date only.
  • Each byte of the date is a Latin-1 character, as in the Authorization parse. 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.
  • The date check runs after the missing-parameter check and before the Bearer answer, the algorithm and the credential. Before, it ran after the whole Authorization parse.
  • A date in another form gets DynamoDB's text, which gives the value: Date must be in ISO-8601 'basic format'. Got '<value>'. See http://en.wikipedia.org/wiki/ISO_8601.

parse_authorization_with_date_check in crates/auth/src/sigv4/parse.rs takes the date check as a closure and runs it at that point. authenticate in crates/auth/src/lib.rs passes validate_timestamp, which checks the form and the 15 minute window at that point. parse_authorization keeps 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.md gives 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 Authorization value 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(v) is IncompleteSignatureException, Date must be in ISO-8601 'basic format'. Got 'v'. See http://en.wikipedia.org/wiki/ISO_8601.
  • NODATE is IncompleteSignatureException, Authorization header requires existence of either a 'X-Amz-Date' or a 'Date' header. and the hash of the value.
  • OLD is IncompleteSignatureException, Authorization header requires existence of 'X-Amz-Date' header.
  • UNREC is UnrecognizedClientException, The security token included in the request is invalid.

The column "ExtendDB on #1295" gives the answers of #1295's head 86a0378.

Date headers Authorization DynamoDB ExtendDB on #1295 ExtendDB with this PR
Date in the HTTP date form complete DATE OLD DATE
the same Credential=x DATE Credential must have exactly 5 slash-delimited elements, ... DATE
the same the algorithm AWS4-X DATE Unsupported AWS 'algorithm': 'AWS4-X'. DATE
the same Bearer and the three pairs DATE MissingAuthenticationToken DATE
the same no Signature Authorization header requires 'Signature' parameter. and the hash the same the same
X-Amz-Date in the HTTP date form complete DATE Date must be in ISO 8601 basic format (YYYYMMDDTHHMMSSZ) DATE
X-Amz-Date in the HTTP date form, Date in the basic form complete DATE of the X-Amz-Date value the same as the row above DATE of the X-Amz-Date value
Date in the basic form complete UNREC OLD UNREC
Date in the basic form a scope date of the day before InvalidSignatureException, Date in Credential scope does not match YYYYMMDD from ISO-8601 version of date from HTTP. OLD DynamoDB's
Date with an empty value complete NODATE OLD NODATE
an empty X-Amz-Date, Date in the HTTP date form complete NODATE Date must be in ISO 8601 basic format (YYYYMMDDTHHMMSSZ) NODATE
Date in the ISO-8601 extended form complete UNREC OLD DATE
Date: 20260101T000000Z Credential=x InvalidSignatureException, Signature expired: 20260101T000000Z is now earlier than <edge> (<now> - 15 min.) Credential must have exactly 5 slash-delimited elements, ... UnrecognizedClientException, 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:

ExtendDB sends UNREC in another __type namespace than DynamoDB (#1303).

These answers were measured on 2 and 3 December 2026 in the same way, each request twice:

Date headers DynamoDB ExtendDB with this PR
X-Amz-Date with a 0x80 byte after the time DATE of that value, with the byte the same
Date with a 0x80 byte after the time DATE of that value, with the byte the same
X-Amz-Date with a 0x80 byte, and a valid Date DATE of the X-Amz-Date value, with the byte the same
X-Amz-Date of 15 bytes with a 0xCE byte in the time (3 December) DATE of that value, with the byte the same
Date alone, 16 minutes before now InvalidSignatureException, Signature expired: ... UnrecognizedClientException, Signature expired: ... (#805)
Date alone, 16 minutes after now InvalidSignatureException, Signature not yet current: ... UnrecognizedClientException, Signature expired: ... (#805)
Date alone, 14 minutes before now UNREC UNREC

Fixes #1289

Testing done

  • At 782ec83, cargo test -p extenddb-auth: 548 unit tests, 14 sigv4_differential tests and 3 doc tests passed.
  • cargo +1.97.0 clippy -p extenddb-auth --all-targets -- -D warnings, cargo +1.97.0 fmt --all -- --check and cargo +1.94.0 check -p extenddb-auth --all-targets are clean. The cargo commands ran with --locked.
  • cargo test -p extenddb-wasm-adapter passed its 3 unit tests and the parity corpus. The clippy step of the WebAssembly job is clean, and cargo fuzz build builds sigv4_authorization, sigv4_verify and sigv4_timestamp.
  • cargo fuzz run sigv4_timestamp ran 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_value panics at the byte offset.
  • the_date_check_runs_after_the_missing_parameters fails with the date check moved below the credential check. the_request_date_is_x_amz_date_else_date fails without the rule that an empty value is no date. With the date read by to_str, a_date_with_a_byte_above_0x7f_is_refused_with_its_value and the three wire rows of the byte fail. With the window check skipped for a request with no X-Amz-Date, a_date_header_has_the_window_of_x_amz_date and both rows of test_date_header_outside_the_window_is_refused fail.
  • Against ExtendDB on SQLite at 782ec83, tests/test_auth_error_fidelity.py passed 101 tests, tests/test_sigv4_scope_date.py 11, and test_missing_auth_header of tests/test_auth_integration.py 4.
  • At 6306c32, tests/test_auth_error_fidelity.py, tests/test_auth_integration.py, tests/test_auth_permissions.py and tests/test_sigv4_scope_date.py passed 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 of tests/test_auth_error_fidelity.py failed 9 tests: the 8 new rows and test_basic_date_header_is_the_request_date.
  • At 6306c32, a signed ListTables with only a Date header 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_check ends with Ok(...).map(...). The tuple form Ok((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_timestamp too: #889 by Dodothereal (#805) conflicts with this head in verify.rs, and #1125 by jgaul3 in lib.rs, verify.rs and tests.rs. The PR that merges second resolves the conflict. #889 changes the text that a_date_header_has_the_window_of_x_amz_date asserts. #1356, which sits on this branch, needs a merge of this head.

Not in this PR:

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

A request dated only by Date is 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.

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 demohan left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

Comment thread crates/auth/src/sigv4/verify.rs Outdated
headers
.get("x-amz-date")
.or_else(|| headers.get("date"))
.and_then(|v| v.to_str().ok())

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

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.

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.

Comment thread crates/auth/src/lib.rs Outdated
@@ -140,8 +140,7 @@ impl AuthProvider for BuiltinAuthProvider {
.map_or(&b""[..], |value| value.as_bytes());

// Parse Authorization header

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

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.

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

Copy link
Copy Markdown
Collaborator Author

@demohan

  1. The window of a request dated only by Date: see the thread on lib.rs:142.
  2. A date byte above 0x7F: see the thread on verify.rs:210.
  3. The merge: 1367d94 and ed03f00 merge fix(auth): name every missing Authorization parameter as DynamoDB does #1295's new head, which carries main at 01556cf. The conflicts were in lib.rs, parse.rs and the fidelity test. parse_authorization_with_date_check now also takes the flag of the operations that read the parts by position. At the head d82e5a2 the auth tests pass, test(auth): pin the order of the scope date and token expiry checks #949's included. The head merges with main at b3510a9 with no conflict.

…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.

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants