Repository navigation
fix(auth): name every missing Authorization parameter as DynamoDB does - #1295
LeeroyHannigan wants to merge 6 commits into
Conversation
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
left a comment
There was a problem hiding this comment.
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).
| }; | ||
| let aws4 = starts_with("AWS4-"); | ||
| if !aws4 && !starts_with("Bearer ") { | ||
| return Err(DynamoDbError::MissingAuthenticationToken( |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
| // 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), |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
|
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.
Changes since the last review
mainat 01556cf with fix(core): answer a request with no Authorization header as DynamoDB does #1290. On the item operations, the parse reads the parts by position, split at commas, spaces and tabs. The parse refuses a part with no key wherever it sits. A request with no Authorization header getsDynamoDbError::missing_authentication_token(), the text that main sends since fix(core): answer a request with no Authorization header as DynamoDB does #1290.Credential=orSignature=as missing. It rewrites steps 1 and 2 of "SigV4 Verification" in the security model manual, and adds rows for a space inside the credential.mainat c8e66fb. That head lists a difference: on the item operations, DynamoDB reads the parts by position only for a valid request body (The item operations read the Authorization parts by position whatever the body holds, where DynamoDB does so only for a valid request #1552). The merge narrows the doc comment ofparse_authorizationand the comment oftest_item_operation_authorization_headerto such a body.What
The server now answers more malformed
Authorizationheaders as DynamoDB does:Credential=orSignature=is named as missing. An emptySignedHeaders=counts as present, as on DynamoDB.=x, getsInvalid key=value pair (missing key)with the hash.AWS4-norBearer(ASCII case ignored) gets the answer to a request with no Authorization header,Request is missing Authentication Token.AWS4-in another case getsAlgorithm must start with 'AWS4-'; got '<value>'before any other check.Bearervalue getsMissing Authentication Token, and another algorithm getsUnsupported 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 anX-Amz-Dateor aDateheader, and the flag of the item operations from #1277.crates/auth/src/lib.rsreads 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 withDynamoDbError::missing_authentication_token(), as main does since #1290. TheBeareranswer keeps the textMissing Authentication Token, which DynamoDB gives to it.docs/manuals/10-security-model.mddescribes 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
Credentialpair of the documentation's example key, SH isSignedHeaders=host;x-amz-targetand SIG isSignature=and 64 zeros.Authorization header requires 'x' 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>.<hash>is the Base64 of the SHA-256 of the value without the spaces and tabs at its ends.Invalid key=value pair (missing equal-sign) in Authorization header (hashed with SHA-256 and encoded with Base64): '<hash>'.KEY is the same text withmissing key.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.
AuthorizationAWS4-HMAC-SHA256AWS4-HMAC-SHA256 CRED, SHAuthorization header requires 'Signature' parameterAWS4-HMAC-SHA256 CRED, SHAWS4-HMAC-SHA256 CRED,SH,SIGAuthorization header requires existence of 'X-Amz-Date' headerAWS4-HMAC-SHA256 CRED SH SIGAuthorization header requires 'SignedHeaders' parameterAWS4-HMAC-SHA256 =xAuthorization header requires 'Credential' parameterAWS4-HMAC-SHA256, a tab,garbageAWS4-HMAC-SHA256 garbagand the byte E9Missing Authentication TokenCredential should be scoped to a valid region.AWS4-HMAC-SHA512 CRED, SH, SIGUnsupported AWS 'algorithm': 'AWS4-HMAC-SHA512'.aws4-hmac-sha256Algorithm must start with 'AWS4-'; got 'aws4-hmac-sha256'Bearer abcBearer CRED, SH, SIGMissing Authentication Tokengarbage, an empty value or three spacesRequest is missing Authentication TokenThe rows of
aws4-hmac-sha256andBearerwere 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
Bearerrow with all three pairs had ExtendDB's type name. Since the merge of #1277's head with #1290, the unit rows andtest_authorization_answered_as_anotherhold 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:
Credential=gets MISS(Credential) HASH, on DescribeTable and on PutItem.Signature=gets MISS(Signature) HASH on DescribeTable.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 abcgets MissingAuthenticationTokenException,Request is missing Authentication Token.Refs #1270
Testing done
cargo test -p extenddb-auth: 544 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_authorizationandsigv4_verify.malformed_authorization_headerhas 17 rows, one per check of the parse, with DynamoDB's measured hashes.item_operation_authorization_headerhas 21 rows of the item operations. With the old text for a request with no header,malformed_authorization_headerfails. With empty parameters counted as present, it fails withitem_operation_authorization_header.tests/test_auth_error_fidelity.pypassed 87 tests,tests/test_sigv4_scope_date.py11, andtest_missing_auth_headeroftests/test_auth_integration.py4.cargo test -p extenddb-server --libpassed 513 tests, and on this host 5backup_store::testsfail 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.pyandtests/test_auth_permissions.pypassed 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:
Dateheader in the HTTP date form and noX-Amz-Date(A request with a Date header in the HTTP date form and no X-Amz-Date gets another IncompleteSignatureException text than DynamoDB's ISO-8601 text #1289).SignedHeaders=and its place before the key lookup (An empty SignedHeaders gets ExtendDB's host text after the key lookup, where DynamoDB refuses it before the lookup #1551).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 with a malformed
Authorizationheader gets DynamoDB's type and text, where ExtendDB sent other texts. A request with a header outside ASCII, or with anAuthorizationvalue 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.