Skip to content

AmazonS3Client doesBucketExist() should throw an exception if bucket access is forbidden #1256

@niranjan-wa

Description

@niranjan-wa

I have an application that uploads data to S3, before uploading I check whether bucket exists in S3 or not, if it doesn't exist I throw an exception to notify the user to create one. To check if bucket exists I use doesBucketExist() of AmazonS3Client class. This check happens in the initialisation phase.

Today when I ran my application with incorrect AWSCredentials, to my surprise my application didn't fail in the initialisation phase rather it failed when my app tried to upload data to S3. Then I was wondering why it didn't fail in the initialisation phase where I check if bucket exists or not, then looking at the code of AmazonS3Client.doesBucketExist() I realised it was returning true when bucket access is forbidden or for a status code of 403 of AmazonServiceException

screen shot 2017-07-27 at 4 18 33 pm

The issue here is that code is making an incorrect assumption that bucket always exists when a client is unable to access a bucket or if the access is forbidden. In my test I tried to check if a bucket named "nirabafasfanjan-str" exists with incorrect AWS credentials.
These are the buckets available in my region

screen shot 2017-07-27 at 4 04 20 pm

As you can clearly see this is a false positive and in this case correct behaviour should be to throw exception rather than returning true when the client cannot ascertain bucket exists or not.

Metadata

Metadata

Assignees

Labels

response-requestedWaiting on additional info or feedback. Will move to "closing-soon" in 5 days.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions