Skip to content

Commit 81e9d51

Browse files
committed
ensure that incoming request to set_bucket_policy() is of type str
1 parent a01697f commit 81e9d51

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

minio/api.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
get_sha256_hexdigest, get_md5_base64digest, Hasher,
7373
optimal_part_info,
7474
is_valid_bucket_name, PartMetadata, read_full,
75-
is_valid_bucket_notification_config,
75+
is_valid_bucket_notification_config, is_valid_bucket_policy_name,
7676
get_s3_region_from_endpoint,
7777
mkdir_p, dump_http, amzprefix_user_metadata,
7878
is_supported_header,is_amz_header)
@@ -382,14 +382,15 @@ def delete_bucket_policy(self, bucket_name):
382382
bucket_name=bucket_name,
383383
query={"policy": ""})
384384

385-
def set_bucket_policy(self, bucket_name, policy):
385+
def set_bucket_policy(self, bucket_name, policy):
386386
"""
387387
Set bucket policy of given bucket name.
388388
389389
:param bucket_name: Bucket name.
390-
:param policy: Access policy/ies in JSON format.
390+
:param policy: Access policy in string.
391391
"""
392392
is_valid_bucket_name(bucket_name)
393+
is_valid_bucket_policy_name(policy)
393394

394395
headers = {
395396
'Content-Length': str(len(policy)),

minio/helpers.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,19 @@ def is_non_empty_string(input_string):
375375

376376
return True
377377

378+
def is_valid_bucket_policy_name(policy):
379+
"""
380+
Validates bucket policy
381+
:param policy: S3 style Bucket policy.
382+
:return: True if input is a valid policy structure.
383+
Raise :exc: `TypeError` otherwise.
384+
"""
385+
if not isinstance(policy, str):
386+
raise TypeError('policy can only be of type str')
387+
388+
is_non_empty_string(policy)
389+
390+
return True
378391

379392
def is_valid_bucket_notification_config(notifications):
380393
"""

0 commit comments

Comments
 (0)