AWS S3 Bucket With Public Access Enabled
What Is This Vulnerability?
An AWS S3 bucket configured with public access allows anyone on the internet to list, read, or even write objects in the bucket. This frequently leads to massive data breaches when sensitive files such as database backups, user records, or internal documents are stored in a bucket that was never intended to be public.
Why It Happens
Developers often set buckets to public during initial development or testing and forget to restrict access before deploying to production. Legacy bucket policies, overly broad ACLs, and confusing AWS console defaults also contribute. Some teams disable the S3 Block Public Access settings at the account level without understanding the consequences.
Example Code
resource "aws_s3_bucket" "data_backup" {
bucket = "company-data-backup"
}
resource "aws_s3_bucket_acl" "data_backup_acl" {
bucket = aws_s3_bucket.data_backup.id
acl = "public-read"
}resource "aws_s3_bucket" "data_backup" {
bucket = "company-data-backup"
}
resource "aws_s3_bucket_public_access_block" "data_backup_block" {
bucket = aws_s3_bucket.data_backup.id
block_public_acls = true
block_public_policy = true
ignore_public_acls = true
restrict_public_buckets = true
}
resource "aws_s3_bucket_acl" "data_backup_acl" {
bucket = aws_s3_bucket.data_backup.id
acl = "private"
}How Hackers Exploit It
Attackers use automated scanners like BucketFinder or GrayhatWarfare to discover publicly accessible S3 buckets. Once found, they enumerate all objects, download sensitive data such as credentials and PII, or upload malicious files. In some cases, they can modify existing objects to inject malware into software supply chains.
How to Fix It
Enable S3 Block Public Access at both the account and bucket level. Audit all bucket policies and ACLs to ensure no public grants exist. Use AWS Config rules like s3-bucket-public-read-prohibited to continuously monitor for misconfigurations. Apply the principle of least privilege and use IAM policies or pre-signed URLs for controlled access.