Repository navigation
fix(lambda-http): build query strings in a deterministic order - #1182
Open
abhiishek340 wants to merge 1 commit into
Open
abhiishek340 wants to merge 1 commit into
abhiishek340 wants to merge 1 commit into
Conversation
ALB, API Gateway REST and VPC Lattice requests rebuild the URI query from a QueryMap, which is backed by a HashMap. Its iteration order is random per instance, so the same event produced a differently ordered query string each time, breaking apps that sign or compare the raw URL. Sort the pairs by key before serializing. The sort is stable, so the values of a repeated key keep their order. Fixes aws#1181
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📬 Issue #, if available: Fixes #1181
✍️ Description of changes:
ALB, API Gateway REST (v1) and VPC Lattice requests rebuild the URI query string in
build_request_urifrom aQueryMap.QueryMapwraps aHashMapwith a per-instance random seed, so the same event produced a differently ordered query string each time. Apps that sign, hash or compare the raw URL (CakePHP FormProtection, Laravel signed URLs, cache keys) fail intermittently. API Gateway HTTP (v2) isn't affected because it usesraw_query_string.This PR implements option 2 from the issue:
build_request_urinow serializes the pairs sorted by key. It uses the sameform_urlencodedserializer thatQueryMap::to_query_stringuses, so escaping is unchanged. The sort is stable, so repeated keys keep their value order (b=2&b=1staysb=2&b=1).Sorting doesn't restore the original request order. The issue's option 1 would need an insertion-ordered map in
query_mapand confirmation that ALB preserves key order in its JSON, so I kept this change local tolambda-http. It makes the URI stable either way, and it matches order-independent schemes such as Laravel's, which sign with keys sorted.Testing:
alb_request_query_string_order_is_deterministictest: it deserializes the issue's ALB event 64 times and asserts one exact URI. It fails onmain(e.g.?b=2&b=1&parent_id=1&a=1&type=leader_employee) and passes with this change.cargo test -p lambda_http --all-features: 98 unit and 6 doc tests pass.cargo check -p lambda_http --no-default-features --features <each of alb, apigw_rest, apigw_http, apigw_websockets, vpc_lattice>: no new warnings compared tomain.🔏 By submitting this pull request
cargo +nightly fmt.cargo clippy --fix.