Skip to content

fix(auth): answer InvalidSignatureException for timestamps outside skew window (#805) - #889

Draft
Dodothereal wants to merge 1 commit into
ExtendDB:mainfrom
Dodothereal:fix/805-sigv4-skew-window-invalid-signature
Draft

Dodothereal wants to merge 1 commit into
ExtendDB:mainfrom
Dodothereal:fix/805-sigv4-skew-window-invalid-signature

Conversation

@Dodothereal

@Dodothereal Dodothereal commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

What changes

When a request has an X-Amz-Date timestamp outside the ±15 minute clock skew window, ExtendDB returned UnrecognizedClientException with the generic message "Signature expired: the signature is too old or the request date is too far in the future.".

Amazon DynamoDB returns InvalidSignatureException (HTTP 400) with specific messages indicating the direction and boundary times compared against the server clock:

  • Past skew (>15 min earlier):
    Signature expired: <date> is now earlier than <edge> (<server_time> - 15 min.)
  • Future skew (>15 min later):
    Signature not yet current: <date> is still later than <edge> (<server_time> + 15 min.)

This PR updates validate_timestamp in crates/auth/src/sigv4/verify.rs to return InvalidSignatureException with the directional messages and adds format_iso8601_basic.

Measurements

As reported and measured by the issue reporter in #805 against Amazon DynamoDB in us-east-1 on 2026-11-03 (and referenced in PR #792):

  • 16 min before server clock: 400 InvalidSignatureException Signature expired: 20261103T201550Z is now earlier than 20261103T201650Z (20261103T203150Z - 15 min.)
  • 16 min after server clock: 400 InvalidSignatureException Signature not yet current: 20261103T204750Z is still later than 20261103T204650Z (20261103T203150Z + 15 min.)

(Note: Live AWS measurements were not performed in this workspace; they are cited directly from the reporter's findings in #805).

Tests & Validation

  • Added unit tests in crates/auth/src/sigv4/verify.rs:
    • validate_timestamp_expired_returns_invalid_signature_exception: verifies exact Signature expired error code and text format against known epoch.
    • validate_timestamp_future_returns_invalid_signature_exception: verifies exact Signature not yet current error code and text format against known epoch.
    • validate_timestamp_at_exact_boundaries_succeeds: verifies exact ±15 minute boundary timestamps are accepted.
    • validate_timestamp_live_clock_succeeds_for_now: verifies current timestamps validate cleanly against system clock.
  • Local test execution: cargo test -p extenddb-auth (441 unit tests, 3 doctests passed).
  • Code formatting & linting: cargo fmt --check and cargo clippy -p extenddb-auth --all-targets -- -D warnings passed cleanly.

CONTRIBUTING & RFC / Auth Policy Note

Under CONTRIBUTING.md, an RFC is requested for changes to wire protocol or authentication/authorization. Meanwhile, docs/rfcs/README.md notes that an RFC is not required for bug fixes, dependency bumps, internal refactors that preserve public behavior, documentation, or tests.

This PR does not alter ExtendDB's authentication model, the 15-minute window threshold, or the constant-time pipeline invariants. However, because it alters the returned error type and message for out-of-skew requests on the wire, this PR is submitted as a draft to seek maintainer review on whether this bug fix falls under standard bug fix treatment or requires an RFC or ADR.

Provenance & Disclosure

  • Developed with AI assistance (Gemini 3.8 Flash via T3 Code harness).
  • Verification was conducted purely locally on test fixtures; no live cloud resources or AWS accounts were utilized.

Checklist

  • I have read CONTRIBUTING.md
  • All tests pass (cargo test -p extenddb-auth)
  • Code is formatted (cargo fmt --check)
  • Clippy is clean (cargo clippy -p extenddb-auth --all-targets -- -D warnings)
  • Added unit tests for new functionality
  • No new dependencies or cost/credential requirements
  • Draft PR for maintainer review

@navareamol navareamol added release-blocker Must ship for its milestone's release v1 Needed for the 1.0 release labels Nov 7, 2026
@navareamol navareamol added this to the 1.0 milestone Nov 7, 2026
@navareamol navareamol self-assigned this Nov 7, 2026

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

One thing to fix, one to run:

  1. The boundary test pins behaviour that isn't measured (inline on verify.rs).
  2. No CI has run on this head and the branch is behind main. Could you merge main so CI runs? The 441 unit test count in the description can then be checked against the run.

The messages match the ones measured in #805, and the description matches the code.


/// Exact ±15 minute boundary timestamps are accepted.
#[test]
fn validate_timestamp_at_exact_boundaries_succeeds() {

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.

This pins that a date exactly 15 minutes off is accepted. #805 measured 16 minutes either side, not exactly 15, so the boundary has no live measurement. Could you measure 15:00 and 15:01 on the live service? If that isn't possible, I'd drop this test and keep the 16 minute cases, so it doesn't lock in a guess.

@LeeroyHannigan

Copy link
Copy Markdown
Collaborator

In its skew texts, DynamoDB gives the instant that it read from the request date, in the UTC basic form. It does not echo the header value. These are its answers in us-east-1 on 21 November 2026. Each request went out twice and got the same answer both times.

X-Amz-Date sent DynamoDB's message
20261121T240000Z Signature not yet current: 20261122T000000Z is still later than 20261121T231120Z (20261121T225620Z + 15 min.)
20261100T225657Z Signature expired: 20261031T225657Z is now earlier than 20261121T224157Z (20261121T225657Z - 15 min.)
2026-11-21 Signature expired: 20261121T000000Z is now earlier than 20261121T215137Z (20261121T220637Z - 15 min.)

The parse on main reads the first two values. With this PR, {timestamp} puts them in the two messages as sent. format_iso8601_basic(request_epoch) gives DynamoDB's text for both. The server reads the third value after #1356, which reads the request date in the ISO-8601 forms that DynamoDB reads.

#1356 adds basic_form to crates/auth/src/sigv4/verify.rs. It writes the same form as format_iso8601_basic. The PR that merges second can call the function of the other PR and remove its own.

@navareamol

Copy link
Copy Markdown
Collaborator

I read Lee's table against validate_timestamp_at at a3dc40b. Two of the three rows show a defect in this PR, and my boundary question is still open.

  1. Both messages write {timestamp}, the X-Amz-Date text as sent. parse_iso8601_basic checks only the length, the T and the Z, and it does not range check the digits. So 20261121T240000Z and 20261100T225657Z pass the parse, and the messages would carry those two strings. DynamoDB answers 20261122T000000Z and 20261031T225657Z. I think both messages should print format_iso8601_basic(request_epoch) in place of {timestamp}. Could you do that and add the first two rows of Lee's table as test rows with the exact texts?

  2. 2026-11-21 is 10 characters, so parse_iso8601_basic returns None and this head answers IncompleteSignature ("Date must be in ISO 8601 basic format"). DynamoDB answers Signature expired: 20261121T000000Z .... Lee says fix(auth): read the request date in the basic and extended ISO-8601 forms #1356 covers that form. Could the description say that this row is left to fix(auth): read the request date in the basic and extended ISO-8601 forms #1356, and which of the two PRs merges first? Both add the same formatter.

  3. My question on validate_timestamp_at_exact_boundaries_succeeds has no answer yet. The three rows in Lee's table are hours or days outside the window, so none of them tests the edge. Could you measure 15:00 and 15:01 off on the live service? If not, I think the test should go, so it does not lock in a guess.

  4. The branch is still at a3dc40b, behind main, with no CI run on it. Could you merge main so CI runs and the 441 test count can be checked?

I will approve once the two messages use format_iso8601_basic(request_epoch) with the two rows as tests, the boundary has a measurement or the test is dropped, and CI is green on a branch with main merged.

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

v1 Needed for the 1.0 release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants