6060
6161SIGNATURE_V2_POST_FIELDS = [
6262 "signature" ,
63- "AWSAccessKeyId " ,
63+ "awsaccesskeyid " ,
6464]
6565
6666SIGNATURE_V4_POST_FIELDS = [
@@ -768,13 +768,17 @@ def validate_post_policy(
768768 )
769769 raise ex
770770
771- if not (policy := request_form .get ("policy" )):
771+ form_dict = {k .lower (): v for k , v in request_form .items ()}
772+
773+ policy = form_dict .get ("policy" )
774+ if not policy :
772775 # A POST request needs a policy except if the bucket is publicly writable
773776 return
774777
775778 # TODO: this does validation of fields only for now
776- is_v4 = _is_match_with_signature_fields (request_form , SIGNATURE_V4_POST_FIELDS )
777- is_v2 = _is_match_with_signature_fields (request_form , SIGNATURE_V2_POST_FIELDS )
779+ is_v4 = _is_match_with_signature_fields (form_dict , SIGNATURE_V4_POST_FIELDS )
780+ is_v2 = _is_match_with_signature_fields (form_dict , SIGNATURE_V2_POST_FIELDS )
781+
778782 if not is_v2 and not is_v4 :
779783 ex : AccessDenied = AccessDenied ("Access Denied" )
780784 ex .HostId = FAKE_HOST_ID
@@ -784,7 +788,7 @@ def validate_post_policy(
784788 policy_decoded = json .loads (base64 .b64decode (policy ).decode ("utf-8" ))
785789 except ValueError :
786790 # this means the policy has been tampered with
787- signature = request_form .get ("signature" ) if is_v2 else request_form .get ("x-amz-signature" )
791+ signature = form_dict .get ("signature" ) if is_v2 else form_dict .get ("x-amz-signature" )
788792 credentials = get_credentials_from_parameters (request_form , "us-east-1" )
789793 ex : SignatureDoesNotMatch = create_signature_does_not_match_sig_v2 (
790794 request_signature = signature ,
@@ -813,7 +817,6 @@ def validate_post_policy(
813817 return
814818
815819 conditions = policy_decoded .get ("conditions" , [])
816- form_dict = {k .lower (): v for k , v in request_form .items ()}
817820 for condition in conditions :
818821 if not _verify_condition (condition , form_dict , additional_policy_metadata ):
819822 str_condition = str (condition ).replace ("'" , '"' )
@@ -896,7 +899,7 @@ def _parse_policy_expiration_date(expiration_string: str) -> datetime.datetime:
896899
897900
898901def _is_match_with_signature_fields (
899- request_form : ImmutableMultiDict , signature_fields : list [str ]
902+ request_form : dict [ str , str ] , signature_fields : list [str ]
900903) -> bool :
901904 """
902905 Checks if the form contains at least one of the required fields passed in `signature_fields`
@@ -910,12 +913,13 @@ def _is_match_with_signature_fields(
910913 for p in signature_fields :
911914 if p not in request_form :
912915 LOG .info ("POST pre-sign missing fields" )
913- # .capitalize() does not work here, because of AWSAccessKeyId casing
914916 argument_name = (
915- capitalize_header_name_from_snake_case (p )
916- if "-" in p
917- else f"{ p [0 ].upper ()} { p [1 :]} "
917+ capitalize_header_name_from_snake_case (p ) if "-" in p else p .capitalize ()
918918 )
919+ # AWSAccessKeyId is a special case
920+ if argument_name == "Awsaccesskeyid" :
921+ argument_name = "AWSAccessKeyId"
922+
919923 ex : InvalidArgument = _create_invalid_argument_exc (
920924 message = f"Bucket POST must contain a field named '{ argument_name } '. If it is specified, please check the order of the fields." ,
921925 name = argument_name ,
0 commit comments