Repository navigation
fix(auth): answer an Authorization part with no '=' with DynamoDB's text - #1277
LeeroyHannigan wants to merge 6 commits into
Conversation
ExtendDB skipped a part of the Authorization header that holds no '='.
It then answered with the next check's text, such as "Authorization
header requires 'Credential' parameter".
DynamoDB answers IncompleteSignatureException with this text:
Invalid key=value pair (missing equal-sign) in Authorization header
(hashed with SHA-256 and encoded with Base64): '<hash>'.
<hash> is the Base64 of the SHA-256 of the whole header value.
Measured in us-east-1 on 20 Nov 2026, DynamoDB gives this answer
wherever the part sits, and before it names a missing parameter. An
empty part, such as the one after a trailing comma, does not get it.
The auth crate now uses the workspace's base64 crate to encode the hash.
Other crates already depend on it, so the lock file gains no new package.
Fixes #1264.
#1009 replaced the `axum` dependency of `extenddb-auth` with `http`. The merge takes main's `Cargo.lock` and keeps this branch's `base64` dependency of `extenddb-auth`.
demohan
left a comment
There was a problem hiding this comment.
The missing-equal-sign rule matches the service for the table operations at 2e51215, but not for the item operations. With 207 header shapes signed by hand, sent twice to us-east-1 and to this head and main on SQLite and PostgreSQL: on DescribeTable, ListTables, CreateTable, DeleteTable, UpdateTable, BatchWriteItem and ExecuteStatement, this head answers the missing-equal-sign text in every position the service does, ahead of the credential format, a missing or stale date, the region, an unknown key and a wrong signature, with the service's hash, spaces and tabs included, while the checks before authentication still run first and empty parts and repeated commas still authenticate. No shape authenticates here that main refused, and of the 58 headers main accepted that the service refuses, this head refuses 57. The new wire test fails 5 rows on main, every unit and wire mutation fails as it should, fmt, clippy (both configurations and wasm) and the 1.91.1 check are clean, CI is green on 65 of 65, and the branch merges with main at 222d80a, where it builds, passes the 1.94.0 check and the auth tests, and answers all 207 shapes as this head does.
On PutItem, GetItem, DeleteItem, UpdateItem, Query, Scan, BatchGetItem, TransactGetItems and TransactWriteItems, the service gives this text only in some positions (below), and the tests send DescribeTable alone. Separately, and on main too, CRED, SH, SIG, = with a valid signature authenticates, where the service refuses it with Invalid key=value pair (missing key); #1270 could take it.
I will approve once the item operations answer as the service does, with rows for them in the tests.
| signed_headers = Some(val); | ||
| } else if let Some(val) = part.strip_prefix("Signature=") { | ||
| signature = Some(val); | ||
| } else if !part.is_empty() && !part.contains('=') { |
There was a problem hiding this comment.
On the nine item operations, CRED, SH, <wrong Signature>, garbage gets InvalidSignatureException from the service and from main, and IncompleteSignatureException with this text here, on all nine, twice, on both backends. The service also answers otherwise than this text for garbage, CRED, SH, SIG, CRED, garbage, SH, SIG, CRED, garbage, SIG, CRED, SH, garbage, SIG, CRED, Credential, SH, SIG (the requires-parameter texts or the missing-date text) and CRED, SH, SIG, garbage with a valid signature (InvalidSignatureException), and the same without X-Amz-Date. Main authenticated six of those, so refusing them is right; only the class and text differ. The handler knows the operation before authenticate, so the answer could follow it, and the comment's "wherever it sits" would then name the table operations. PutItem rows in the unit and wire tests would hold it.
There was a problem hiding this comment.
798d9ee reads the parts by position on PutItem, GetItem, DeleteItem, UpdateItem, Query, Scan, BatchGetItem, TransactGetItems and TransactWriteItems. authenticate takes the operation from X-Amz-Target (crates/auth/src/lib.rs), and the other operations read the parts by key as before.
On the nine operations the first part is Credential, the second is SignedHeaders, and the rest of the value is Signature. So CRED, SH, <wrong Signature>, garbage now gets InvalidSignatureException. The missing-equal-sign text answers only when a parameter is missing and the last of the three parts has no =. Otherwise the parse names the missing parameter.
I measured this in us-east-1 on 2 and 3 Dec, each request twice. garbage, CRED, SH, SIG went to all nine operations. CRED, garbage, SH, other, CRED, SH, garbage, garbage, CRED, other and CRED, SH, SIG, garbage with a valid signature went to PutItem. The comment at parse.rs:95 names the other operations for "wherever it sits".
PutItem rows are in part_without_equal_sign, the_item_operations_read_the_parts_by_position and the wire test test_authorization_part_without_equal_sign. Without the read by position, 3 unit tests and 3 wire tests fail. The missing date sentence for the same shapes without X-Amz-Date comes with #1295.
DynamoDB reads the Authorization header of PutItem, GetItem, DeleteItem, UpdateItem, Query, Scan, BatchGetItem, TransactGetItems and TransactWriteItems by position. The first part is Credential, the second part is SignedHeaders, and the rest of the value is Signature. On these operations, DynamoDB checks only the last of the three parts for a missing '='. It does so only when a parameter is missing. Before this change, such a part got that text on every operation. A valid request with a part after the signature authenticated on these operations. Measured in us-east-1 on 2 and 3 Dec 2026, each request twice. On the nine operations, `garbage, CRED, SH, SIG` names the missing parameters. On PutItem, `CRED, garbage, SH, other` names them too. With a valid signature, `CRED, SH, SIG, garbage` gets InvalidSignatureException. BatchWriteItem and DescribeTable read the parts by key, as before.
|
LJMart11
left a comment
There was a problem hiding this comment.
Reviewed at 798d9ee. 1 finding: 1 Important.
The change makes the parse of the Authorization header answer DynamoDB's missing-equal-sign text, reading the parts by position on nine item operations and by key elsewhere. Confirmed: against the live service, the nine item operations plus DescribeTable, ListTables, BatchWriteItem and ExecuteStatement answer as the head's table does for a valid body (positional on the nine, by key on BatchWriteItem and the rest); the 15 test_authorization_part_without_equal_sign wire cases pass on SQLite; reverting by_position to false, replacing splitn(3) with split, and removing the by-key branch each fail the parse tests; the head merged with the current main tip builds and passes the auth crate tests (542 lib, 14 differential, 3 doc).
- Important
crates/auth/src/lib.rs:147—by_positionis chosen fromX-Amz-Targetalone, but the service reads the parts by position only when the body is a valid request for that operation; with an invalid body it answers the missing-equal-sign text, as ExtendDB no longer does.
|
|
||
| // Parse Authorization header | ||
| let parsed = sigv4::parse::parse_authorization(auth_header)?; | ||
| // Parse Authorization header. Measured 2026-12-02: DynamoDB reads the |
There was a problem hiding this comment.
Important
authenticate sets by_position from the operation name alone (lib.rs:147-166). On the service the positional read also depends on the body: with a body that lacks a required member the item operations answer by key, so the missing-equal-sign text wins, as it does for DescribeTable.
What the caller sees: for Authorization: AWS4-HMAC-SHA256 garbage, CRED, SH, SIG the service answers Invalid key=value pair (missing equal-sign)... when the PutItem body is {} or {"TableName":"x"}, and Authorization header requires 'Credential' parameter when it is {"TableName":"x","Item":{...}}. The head answers the second text in all three cases (the committed the_item_operations_read_the_parts_by_position sends b"{}" and asserts it, tests.rs:327-349). Before this PR the head's answer for the empty body was also not the service's, so this is a remaining delta, not a regression.
Fix: either decide by_position only after the body has the operation's required members (the body is already passed to authenticate), or list the delta in docs/differences-from-dynamodb.md and narrow the wording in the PR body and the comment at lib.rs:147 ("by position on these operations"). The rows at tests.rs:327-349 and the PutItem rows at test_auth_error_fidelity.py:477-500 use bodies that decide this and would need both a valid and an empty-body row. Sibling #1295 edits the same authenticate and parse.rs hunks, so the change needs a rebase onto whichever lands second.
Evidence: live DynamoDB us-east-1, same header garbage, CRED, SH, SIG, same request otherwise: PutItem {} → Invalid key=value pair (missing equal-sign); PutItem {"TableName":"x"} → same; PutItem with TableName and Item → Authorization header requires 'Credential' parameter; GetItem, Scan, BatchGetItem {} → missing-equal-sign, with a valid body → requires 'Credential'; DescribeTable with either body → missing-equal-sign.
There was a problem hiding this comment.
This reproduces. I sent your shapes and others to us-east-1 on 3 Dec, each request twice. On the nine operations, DynamoDB reads the parts by position only when the body passes a check against the input shape of the operation. Each member must have its type, and the required members must be present and not null, nested ones too. {} gets the missing-equal-sign text on all nine. So do a PutItem with "ReturnValues": 5, an Item value of {"pk": "x"}, and a BatchGetItem table entry with no Keys. A one-character TableName, an empty Item or a member PutItem does not have still read by position, and Query needs only TableName.
That check needs the input shapes of the nine operations in the auth crate, so by_position stays a choice by operation. ExtendDB checks the members only after authentication, and those checks also refuse values that pass the type check. 07ea221 lists the difference in docs/differences-from-dynamodb.md and narrows the comment at lib.rs:147. It also makes the_item_operations_read_the_parts_by_position send a PutItem body that DynamoDB reads by position. The PutItem rows of test_auth_error_fidelity.py already send TableName and Item. #1552 has the measurements and tracks the body check.
The stack merges instead of a rebase: 17b7835 merges 07ea221 into the branch of #1295.
DynamoDB reads the Authorization parts of the nine item operations by
position only when the body is a valid request (measured on 2026-12-03).
With another body, such as `{}` on each of the nine, it reads the parts by
key and answers the missing-equal-sign text. Its check covers each member
and its type, nested members too. This commit keeps the choice by
operation, lists the difference in docs/differences-from-dynamodb.md and
narrows the comments.
The unit test the_item_operations_read_the_parts_by_position now sends a
PutItem body that DynamoDB reads by position, in place of `{}`.
|
LJMart11
left a comment
There was a problem hiding this comment.
Checked at 07ea221 against the list from 798d9ee.
The follow-up lists the body-dependent positional read of the nine item operations in docs/differences-from-dynamodb.md and changes the_item_operations_read_the_parts_by_position to send a valid PutItem body. Confirmed: the live service answers the missing-equal-sign text for PutItem bodies {} and {"TableName":"x"} and the requires 'Credential' text for a valid body, which is what the new doc row says; the updated test passes, and forcing by_position to false or to true each fails it at tests.rs:351; the auth crate tests pass (542 lib); the head already contains the current base tip (c8e66fb), so there is no base movement to merge.
Previous items: 1 fixed.
Changes since the last review
mainat c8e66fb, with no conflict.docs/differences-from-dynamodb.md. On the item operations, DynamoDB reads the parts by position only when the body is a valid request for the operation. This PR reads them by position whatever the body holds (The item operations read the Authorization parts by position whatever the body holds, where DynamoDB does so only for a valid request #1552). The commit narrows the comments, andthe_item_operations_read_the_parts_by_positionnow sends a PutItem body that DynamoDB reads by position.What
A part of the
Authorizationheader with no=after the algorithm now gets DynamoDB's IncompleteSignatureException text:Invalid key=value pair (missing equal-sign) in Authorization header (hashed with SHA-256 and encoded with Base64): '<hash>'.<hash>is the standard Base64 of the SHA-256 of the header value. Before this change, ExtendDB skipped such a part and answered with the text of a later check, such asAuthorization header requires 'Credential' parameter.On PutItem, GetItem, DeleteItem, UpdateItem, Query, Scan, BatchGetItem, TransactGetItems and TransactWriteItems, DynamoDB reads the parts by position for a valid request body. The first part is Credential, the second is SignedHeaders and the rest of the value is Signature. On these operations the text above answers only when a parameter is missing and the last of the three parts has no
=. Otherwise ExtendDB names the missing parameter, and a part after the signature is part of the signature. The other operations read the parts by key, and the text answers wherever the part sits. ExtendDB makes the choice from the operation alone. With a body that is not a valid request, such as{}, DynamoDB reads the parts by key, and ExtendDB still reads them by position.docs/differences-from-dynamodb.mdlists this difference (#1552).The change is in
parse_authorization(crates/auth/src/sigv4/parse.rs), which now takes aby_positionflag, and in its callerauthenticate(crates/auth/src/lib.rs), which sets the flag fromX-Amz-Target. The 8 KB cap and the algorithm check still run first. The parse by key still skips an empty part, such as the one after a trailing comma. The auth crate now uses the workspace'sbase64crate for the hash. That crate is already in the auth crate's dependency graph throughextenddb-core, soCargo.lockgains one line and no package.Why
DynamoDB's answers, measured in us-east-1 on 20 November 2026 with DescribeTable requests. Each request went out twice and got the same answer both times. CRED, SH and SIG are well-formed
Credential,SignedHeadersandSignaturepairs for the documentation's example key. EQ is the text above.AuthorizationAWS4-HMAC-SHA256 garbageAuthorization header requires 'Credential' parameterAWS4-HMAC-SHA256 garbage, CRED, SH, SIGAuthorization header requires existence of 'X-Amz-Date' headerAWS4-HMAC-SHA256 CRED, SH, SIG, garbageAuthorization header requires existence of 'X-Amz-Date' headerAWS4-HMAC-SHA256 CRED, garbage, SIGAuthorization header requires 'SignedHeaders' parameterAWS4-HMAC-SHA256 garbage, otherAuthorization header requires 'Credential' parameterAWS4-HMAC-SHA256 CredentialAuthorization header requires 'Credential' parameterDynamoDB gave EQ for the first row with an
X-Amz-Dateheader too, and for PutItem. The quoted hash is the hash of the header value, with spaces and tabs at either end removed. With this change, ExtendDB gives each of these requests DynamoDB's type and full text. It also hashes what DynamoDB hashes for values with spaces or tabs at either end or inside.DynamoDB's answers on the item operations, measured in us-east-1 on 2 and 3 December 2026 with an
X-Amz-Dateheader and a valid body, each request twice. MISS names the missing parameters, which #1295 gives in DynamoDB's form.Authorizationafter the algorithmgarbage, CRED, SH, SIGgarbage, CRED, SH, SIGCRED, garbage, SH, SIGCRED, garbage, SH, otherCRED, SH, garbage, SIGCRED, SH, garbagegarbage, CRED, otherCRED, SH, SIG, garbage, valid signatureCRED, SH, SIG, garbage, valid signatureDynamoDB's answers to
garbage, CRED, SH, SIGwith other bodies, measured in us-east-1 on 3 December 2026, each request twice. With a body that is not a valid request, the nine operations read the parts by key.{}TableNameonly,Itemonly, aTableNamethat is a number, anItemthat is a string,nullor{"pk": "x"}, or"ReturnValues": 5addedTableNameonly orKeyonlyKeysTableNameof one character, an emptyItem, or a member that PutItem does not haveTableNameonlyFixes #1264
Testing done
cargo test -p extenddb-auth: 542 unit tests, 14 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 -- --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.part_without_equal_signchecks the six rows of the first table with DynamoDB's hashes, two control rows, and nine item operation rows.the_item_operations_read_the_parts_by_positionsends PutItem and ListTables requests throughauthenticate, with bodies that DynamoDB reads as valid.tests/test_auth_error_fidelity.pypassed 39 tests. Its parametrized testtest_authorization_part_without_equal_signsends five DescribeTable rows of the first table, eight PutItem rows and two control rows.part_without_equal_signfails.parse_authorizationhad one caller, which servesPOST /. Requests to the data plane, management, console, metrics and health routes went to that head and to main. Of 15 requests, only the two rows with no=got other answers.Line counts: production +75 -12 (
Cargo.lock,crates/auth/Cargo.toml,lib.rs,parse.rs), tests +244 -7, fuzz targets +4 -2, docs +1.#1009 merged first.
Cargo.lockis main's file with this branch'sbase64dependency ofextenddb-auth, because #1009 replaced theaxumdependency of that crate withhttp. dc6d767 merges main at c8e66fb with no conflict.Not in this PR: other malformed headers, which DynamoDB answers with other texts or another exception (#1270). #1295 also refuses
CRED, SH, SIG, =with a valid signature on the operations that read the parts by key. The check of the body that DynamoDB makes before it reads the parts by position is not in this PR either (#1552).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 part of the
Authorizationheader that has no=gets DynamoDB's IncompleteSignatureException text, where ExtendDB sent the text of a later check. On the item operations, a request with a valid signature and a part after it gets InvalidSignatureException, where ExtendDB authenticated it. The status stays 400 for the refused requests.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.