AWS S3: How to restrict document uploads by Content-Type?

Viewed 460

Anyone know of a way to write an S3 bucket policy that restricts file uploads by Content Type? Also, is there a way to view failed upload attempts in AWS?

Why are we looking to do this?

We are generating a Pre-Signed url from one of our services. Our UI is then responsible for uploading a document via the provided URL. We have UI file type validation in place but also want to protect the bucket in the scenario someone gets a hold of the Pre-Signed url (allowing them to side-step the UI file type validation). One important thing to note is our bucket is just a temporary holding bucket. Much more in-depth file validation is handled outside of our system.

Here's the statement we have so far. This results in a upload error any time we are uploading a PDF document.

Is this written incorrectly? Is there another way of doing this besides checking the file extension?

JSON

{
            ...
            "Effect": "Deny",
            "Action": "s3:PutObject",
            "Resource": [ "..." ],
            "Condition": {
                "StringNotEqualsIfExists": {
                    "aws:ContentType": "application/pdf"
                }
            }
}
1 Answers
Related