Skip to content

fix(auth): name every missing Authorization parameter as DynamoDB does - #1295

Open
LeeroyHannigan wants to merge 6 commits into
fix/1264-auth-missing-equal-signfrom
fix/1270-authorization-texts
Open

LeeroyHannigan wants to merge 6 commits into
fix/1264-auth-missing-equal-signfrom
fix/1270-authorization-texts

Conversation

@LeeroyHannigan

@LeeroyHannigan LeeroyHannigan commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator

Changes since the last review

What

The server now answers more malformed Authorization headers as DynamoDB does:

  • It names each missing parameter and a missing date header in one message, then a hash of the header value. Before, it named the first missing parameter alone.
  • An empty Credential= or Signature= is named as missing. An empty SignedHeaders= counts as present, as on DynamoDB.
  • A part with no key, such as =x, gets Invalid key=value pair (missing key) with the hash.
  • Pairs split by spaces read as pairs split by commas. A tab after the algorithm ends it, as a space does.
  • Each byte outside ASCII reads as a Latin-1 character. Before, such a header got the answer to a request with no Authorization header.
  • A value that starts with neither AWS4- nor Bearer (ASCII case ignored) gets the answer to a request with no Authorization header, Request is missing Authentication Token. AWS4- in another case gets Algorithm must start with 'AWS4-'; got '<value>' before any other check.
  • After the missing parameters and the date, a Bearer value gets Missing Authentication Token, and another algorithm gets Unsupported AWS 'algorithm': '<word>'. .

The change is in parse_authorization (crates/auth/src/sigv4/parse.rs). It now takes the header bytes, whether the request has an X-Amz-Date or a Date header, and the flag of the item operations from #1277. crates/auth/src/lib.rs reads an absent header as an empty value, so the parse builds the answer to a request with no header in one place. The parse builds that answer with DynamoDbError::missing_authentication_token(), as main does since #1290. The Bearer answer keeps the text Missing Authentication Token, which DynamoDB gives to it.

docs/manuals/10-security-model.md describes the parse in steps 1 and 2 of "SigV4 Verification".

The base of this PR is #1277.

Why

These are DynamoDB's answers, measured in us-east-1 on 20 and 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. CRED is a Credential pair of the documentation's example key, SH is SignedHeaders=host;x-amz-target and SIG is Signature= and 64 zeros.

  • MISS(x) is Authorization header requires 'x' parameter.
  • DATE is Authorization header requires existence of either a 'X-Amz-Date' or a 'Date' header.
  • HASH is (Hashed with SHA-256 and encoded with Base64) Authorization=<hash>. <hash> is the Base64 of the SHA-256 of the value without the spaces and tabs at its ends.
  • EQ is Invalid key=value pair (missing equal-sign) in Authorization header (hashed with SHA-256 and encoded with Base64): '<hash>'. KEY is the same text with missing key.
  • ALG is Authorization header requires 'AWS4-HMAC-SHA256' algorithm.

Each answer is IncompleteSignatureException unless the row names another type. The column "ExtendDB on #1277" gives the answers of #1277's head before this round, 2e51215.

Authorization X-Amz-Date DynamoDB ExtendDB on #1277 ExtendDB with this PR
AWS4-HMAC-SHA256 no MISS(Credential) MISS(Signature) MISS(SignedHeaders) DATE HASH ALG DynamoDB's
AWS4-HMAC-SHA256 CRED, SH no MISS(Signature) DATE HASH Authorization header requires 'Signature' parameter DynamoDB's
AWS4-HMAC-SHA256 CRED, SH yes MISS(Signature) HASH the same DynamoDB's
AWS4-HMAC-SHA256 CRED,SH,SIG no DATE HASH Authorization header requires existence of 'X-Amz-Date' header DynamoDB's
AWS4-HMAC-SHA256 CRED SH SIG no DATE HASH Authorization header requires 'SignedHeaders' parameter DynamoDB's
AWS4-HMAC-SHA256 =x no KEY Authorization header requires 'Credential' parameter KEY
AWS4-HMAC-SHA256, a tab, garbage no EQ ALG EQ
AWS4-HMAC-SHA256 garbag and the byte E9 no EQ MissingAuthenticationToken, Missing Authentication Token EQ
CRED with a space after the region, SH, SIG yes EQ InvalidSignatureException, Credential should be scoped to a valid region. EQ
AWS4-HMAC-SHA512 CRED, SH, SIG yes Unsupported AWS 'algorithm': 'AWS4-HMAC-SHA512'. ALG DynamoDB's
aws4-hmac-sha256 yes Algorithm must start with 'AWS4-'; got 'aws4-hmac-sha256' ALG DynamoDB's
Bearer abc yes EQ ALG EQ
Bearer CRED, SH, SIG yes MissingAuthenticationTokenException, Missing Authentication Token ALG DynamoDB's
garbage, an empty value or three spaces yes or no MissingAuthenticationTokenException, Request is missing Authentication Token ALG DynamoDB's

The rows of aws4-hmac-sha256 and Bearer were not sent to #1277. Its column gives the answer that its code returns for them.

At 86a0378, 48 of the 64 measured requests got DynamoDB's type and text. On #1277, 2 of the 36 requests sent to it did. Of the other 16, twelve got ExtendDB's answer to a request with no header, and the Bearer row with all three pairs had ExtendDB's type name. Since the merge of #1277's head with #1290, the unit rows and test_authorization_answered_as_another hold DynamoDB's answer for those rows. Three keep their answers on #1277 (#1289, #1292). Of the requests sent to both, none that got DynamoDB's type on #1277 gets another type now.

Measured in us-east-1 on 2 and 3 December 2026, each request twice:

  • An empty Credential= gets MISS(Credential) HASH, on DescribeTable and on PutItem.
  • An empty Signature= gets MISS(Signature) HASH on DescribeTable.
  • An empty SignedHeaders= gets InvalidSignatureException, 'Host' or ':authority' must be a 'SignedHeader' in the AWS Authorization., before the key lookup (An empty SignedHeaders gets ExtendDB's host text after the key lookup, where DynamoDB refuses it before the lookup #1551).
  • Basic abc gets MissingAuthenticationTokenException, Request is missing Authentication Token.
  • CRED with a space after the region gets EQ on DescribeTable, and MISS(Signature) MISS(SignedHeaders) HASH on PutItem.

Refs #1270

Testing done

  • At 8f84bc7, cargo test -p extenddb-auth: 544 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 and sigv4_verify.
  • The unit table malformed_authorization_header has 17 rows, one per check of the parse, with DynamoDB's measured hashes. item_operation_authorization_header has 21 rows of the item operations. With the old text for a request with no header, malformed_authorization_header fails. With empty parameters counted as present, it fails with item_operation_authorization_header.
  • Against ExtendDB on SQLite at 8f84bc7, tests/test_auth_error_fidelity.py passed 87 tests, tests/test_sigv4_scope_date.py 11, and test_missing_auth_header of tests/test_auth_integration.py 4.
  • At 86a0378, cargo test -p extenddb-server --lib passed 513 tests, and on this host 5 backup_store::tests fail on every branch, because uid 65534 owns /local/home. The fuzz targets each ran 60 seconds with no crash there. tests/test_auth_error_fidelity.py, tests/test_auth_integration.py and tests/test_auth_permissions.py passed 222 tests, and the 64 requests got the answers in the table.

Line counts: production +132 -47, tests +473 -106, fuzz targets +14 -11, docs +2 -2.

8f84bc7 carries main at c8e66fb, through #1277's 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 with a malformed Authorization header gets DynamoDB's type and text, where ExtendDB sent other texts. A request with a header outside ASCII, or with an Authorization value of another scheme, gets the answers above. The status 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 named only the first missing parameter of a malformed
Authorization header. DynamoDB names each missing parameter and a missing
date header in one message, then a hash of the header value:

    Authorization header requires 'Signature' parameter. Authorization
    header requires existence of either a 'X-Amz-Date' or a 'Date' header.
    (Hashed with SHA-256 and encoded with Base64) Authorization=<hash>

Measured in us-east-1 on 21 Nov 2026, DynamoDB also answers these headers
in other ways than ExtendDB did:

- A part with no key, such as "=x", gets "Invalid key=value pair (missing
  key)" with the hash.
- Pairs split by spaces are read as pairs split by commas.
- A tab after the algorithm ends it, as a space does.
- Each byte outside ASCII is read as a Latin-1 character. ExtendDB
  answered such a header as a request with no Authorization header.
- A value that starts with neither "AWS4-" nor "Bearer ", ignoring
  ASCII case, gets the answer to a request with no Authorization
  header. "AWS4-" in another case gets "Algorithm must start with
  'AWS4-'" before any other check.
- A missing date is named before the form of the credential is checked.
- After the missing parameters and the date, another algorithm gets
  "Unsupported AWS 'algorithm'", and a "Bearer" value gets "Missing
  Authentication Token".

<hash> is the Base64 of the SHA-256 of the value without the spaces and
tabs at its ends. A space now ends a pair, so a space inside a credential
scope splits the credential.

parse_authorization takes the header bytes and whether the request has an
X-Amz-Date or a Date header.

Refs #1270. Values such as "garbage" get the answer to a request with no
Authorization header, whose type and text differ from DynamoDB's. #1075
covers that answer.

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

Missing Authorization parameters are named as the service names them at 86a0378. Of 120 header shapes sent twice to us-east-1 and to this head and its base on SQLite and PostgreSQL, this head matches the service on 93 and the base on 23, with nothing the base matched now differing, and none of 22 malformed headers with valid signatures authenticates here when the service refuses it. 40 of the 46 new wire tests fail on the base and all pass here on both backends, 13 Rust and 2 wire controls fail as they should, fmt, clippy, the 1.91.1 check and the fuzz build are clean, and CI is green on 59 of 59 against the base branch.

The stack conflicts with main at 222d80a in lib.rs over #1290 and in Cargo.lock over #1277's base64 dependency. Resolved by keeping this line, as the body says, a request with no Authorization header answers Missing Authentication Token where the service and main answer Request is missing Authentication Token, and main's test_missing_auth_header fails 4 of 4; with the change the body names at parse.rs:74 and its row at :300, the auth tests, 155 Python tests and 103 of the 120 shapes pass. The Bearer and algorithm answers ahead of the date check (parse.rs:142-157) and an empty X-Amz-Date counted as a date (lib.rs:143) differ from the service too, and #1306 fixes both.

I will approve once main is merged with missing_authentication_token() at line 74, and an empty Credential= or Signature= is named as missing.

docs/manuals/10-security-model.md:56

Optional. Steps 1 and 2 still describe the old parse. No test holds the space-inside-credential answer now that the row at tests.rs:247 is gone, and dropping the Date header from the date check in lib.rs, or reading it with to_str, passes the Rust tests (the new wire tests catch both).

Comment thread crates/auth/src/sigv4/parse.rs Outdated
};
let aws4 = starts_with("AWS4-");
if !aws4 && !starts_with("Bearer ") {
return Err(DynamoDbError::MissingAuthenticationToken(

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.

After the merge with main, this sends Missing Authentication Token for a request with no Authorization header, where #1290 and the service send Request is missing Authentication Token; DynamoDbError::missing_authentication_token() here, with the row at line 300, would keep main's answer, and the comment at lines 142-147 would then be stale. The Bearer answer at line 150 is right as it is: Bearer CRED, SH, SIG with a date gets Missing Authentication Token from the service, twice.

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.

c90926f merges #1277's head, which carries main with #1290. The parse now answers a request with no Authorization header with DynamoDbError::missing_authentication_token() (parse.rs:77). A value that starts with neither AWS4- nor Bearer and a space gets the same answer. The empty-value row of malformed_authorization_header expects it, and a new Basic abc row does too: DynamoDB answered Basic abc with Request is missing Authentication Token on 3 Dec, twice.

The comment above the Bearer answer (parse.rs:169) no longer names #1075, and the Bearer answer stays Missing Authentication Token. At fd7201c, test_missing_auth_header passes 4 of 4 on SQLite.

Comment thread crates/auth/src/sigv4/parse.rs Outdated
// Measured 2026-11-21: DynamoDB splits the pairs at commas and at spaces.
for part in rest.split([',', ' ', '\t']).filter(|part| !part.is_empty()) {
match part.split_once('=') {
Some(("Credential", val)) => credential = Some(val),

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.

An empty Credential= or Signature= counts as present here. The service answers Authorization header requires 'Credential' parameter (or 'Signature') with the hash, while this head answers Credential must have exactly 5 ... got '' or goes on to the key lookup; the base does the same, but it is within this PR's claim to name every missing parameter. The service does not count an empty SignedHeaders= as missing. The comment at line 89 also leaves out tabs, which the code and the service split at.

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.

5b04dd9 names an empty Credential= or Signature= as missing, with the hash (parse.rs:139). I measured Credential=, SH, SIG and CRED, SH, Signature= on DescribeTable, and Credential=, SH, SIG on PutItem, on 2 Dec, twice each. Unit and wire rows hold all three.

An empty SignedHeaders= still counts as present, and a unit row holds that the parse accepts it. DynamoDB then answers 'Host' or ':authority' must be a 'SignedHeader' in the AWS Authorization. before the key lookup. ExtendDB looks the key up first and sends its own host text from verify_signature, which this PR does not change. #1551 tracks it.

The comment on the split (parse.rs:120) now names tabs.

parse_authorization takes the bytes of the value, whether the request
has a date header, and whether the operation reads the parts by
position. On the item operations the parts are split at commas, spaces
and tabs, as on the other operations. The parse refuses a part with no
key wherever it sits. A request with no Authorization header gets
DynamoDbError::missing_authentication_token(), the text that main sends
since #1290. A value that starts with neither AWS4- nor Bearer and a
space gets the same answer.

Measured in us-east-1 on 2 and 3 Dec 2026, each request twice.
DynamoDB names an empty `Credential=` or `Signature=` as a missing
parameter, with the hash of the value. Before this change, an empty
Credential got the credential format text, and an empty Signature went
on to the key lookup. An empty `SignedHeaders=` still counts as present,
as it does on the service.

The security model manual now describes the parse of the Authorization
header. It gives the answers for no header, the separators and the order
of the checks. It names the item operations that read the parameters by
position. The comment on the split names tabs. A row holds the space
inside the credential on DescribeTable, where the part after the space
has no '='.

Measured in us-east-1 on 2 and 3 Dec 2026, each request twice.
After the missing parameters, the parse answers a Bearer value, then an
algorithm other than AWS4-HMAC-SHA256, then a credential that is not five
parts. The manual said that the algorithm came last.
@LeeroyHannigan

Copy link
Copy Markdown
Collaborator Author

@demohan

  1. The merge with main: c90926f merges fix(auth): answer an Authorization part with no '=' with DynamoDB's text #1277's head, which carries main at 01556cf with fix(core): answer a request with no Authorization header as DynamoDB does #1290. The thread on line 74 covers the answer to a request with no Authorization header. The head fd7201c merges with main at b3510a9 with no conflict.
  2. An empty Credential= or Signature=: see the thread on line 94.
  3. The manual: 5b04dd9 and fd7201c rewrite steps 1 and 2 of "SigV4 Verification" in docs/manuals/10-security-model.md for the parse as it is now.
  4. The space inside the credential: part_without_equal_sign has a row for it on DescribeTable, which gets the missing-equal-sign text (measured 3 Dec). item_operation_authorization_header has one for PutItem, which names Signature and SignedHeaders as missing (measured 2 Dec). The wire tests have both.
  5. The Date header in the Rust tests: they stay as they are in this PR. The wire row no-signature-with-http-date sends a request dated only by Date. fix(auth): read the Date header and check the date as DynamoDB does #1306 adds unit tests that read Date, a value with a byte above 0x7F among them.

The resolution narrows two comments to a valid request body: the doc
comment of parse_authorization and the comment of
test_item_operation_authorization_header. On the item operations, DynamoDB
reads the parts by position only for such a body.
… body

Step 2 of the Authorization parse names the nine item operations that read
the parameters by position. DynamoDB does so only when the body is a valid
request. The step now says so and links to the differences from DynamoDB.

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