60
60
61
61
SIGNATURE_V2_POST_FIELDS = [
62
62
"signature" ,
63
- "AWSAccessKeyId " ,
63
+ "awsaccesskeyid " ,
64
64
]
65
65
66
66
SIGNATURE_V4_POST_FIELDS = [
@@ -768,13 +768,17 @@ def validate_post_policy(
768
768
)
769
769
raise ex
770
770
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 :
772
775
# A POST request needs a policy except if the bucket is publicly writable
773
776
return
774
777
775
778
# 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
+
778
782
if not is_v2 and not is_v4 :
779
783
ex : AccessDenied = AccessDenied ("Access Denied" )
780
784
ex .HostId = FAKE_HOST_ID
@@ -784,7 +788,7 @@ def validate_post_policy(
784
788
policy_decoded = json .loads (base64 .b64decode (policy ).decode ("utf-8" ))
785
789
except ValueError :
786
790
# 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" )
788
792
credentials = get_credentials_from_parameters (request_form , "us-east-1" )
789
793
ex : SignatureDoesNotMatch = create_signature_does_not_match_sig_v2 (
790
794
request_signature = signature ,
@@ -813,7 +817,6 @@ def validate_post_policy(
813
817
return
814
818
815
819
conditions = policy_decoded .get ("conditions" , [])
816
- form_dict = {k .lower (): v for k , v in request_form .items ()}
817
820
for condition in conditions :
818
821
if not _verify_condition (condition , form_dict , additional_policy_metadata ):
819
822
str_condition = str (condition ).replace ("'" , '"' )
@@ -896,7 +899,7 @@ def _parse_policy_expiration_date(expiration_string: str) -> datetime.datetime:
896
899
897
900
898
901
def _is_match_with_signature_fields (
899
- request_form : ImmutableMultiDict , signature_fields : list [str ]
902
+ request_form : dict [ str , str ] , signature_fields : list [str ]
900
903
) -> bool :
901
904
"""
902
905
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(
910
913
for p in signature_fields :
911
914
if p not in request_form :
912
915
LOG .info ("POST pre-sign missing fields" )
913
- # .capitalize() does not work here, because of AWSAccessKeyId casing
914
916
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 ()
918
918
)
919
+ # AWSAccessKeyId is a special case
920
+ if argument_name == "Awsaccesskeyid" :
921
+ argument_name = "AWSAccessKeyId"
922
+
919
923
ex : InvalidArgument = _create_invalid_argument_exc (
920
924
message = f"Bucket POST must contain a field named '{ argument_name } '. If it is specified, please check the order of the fields." ,
921
925
name = argument_name ,
0 commit comments