How I found it

I was reviewing my own site from the outside, the way an attacker or a curious engineer would. The bucket behind the site was private and only reachable through CloudFront, which is what I wanted. Reading the distribution configuration, though, I noticed a second behaviour: /images/* pointed at a different bucket, ogulcanaydogan.com-images. A head-bucket call returned 404. The bucket no longer existed.

I had also misread the main origin at first, because its ID still said s3-website while its domain name was the plain S3 endpoint with Origin Access Control. The domain name is what counts, and that one was fine.

Why a missing bucket is a problem

S3 bucket names are global. Once a bucket is deleted, the name is free for anyone to register. CloudFront would keep sending /images/* requests to that name, so whoever created a bucket called ogulcanaydogan.com-images in the right region could make its objects public and have them served from my domain. Because that is the same origin as the site, an HTML or JavaScript file placed there would run with the site's trust. This class of bug is usually called a dangling origin or a bucket takeover.

How exposed I was

Not very. Nothing on the site referenced /images/, and the path returned 404 at the time. But the exposure existed from the day the bucket was deleted, and nothing would have warned me if someone had registered the name.

The fix and the audit

I saved the distribution configuration, then removed the /images/* behaviour and its origin, along with a second origin that no behaviour used. I compared the configuration before and after to confirm that nothing else changed, then checked that the site, its headers and the www redirect still worked.

Then I checked the rest of the account: for every origin of every distribution that points at S3, I called head-bucket on the bucket name. All eight distributions had origins that still existed. I also confirmed that each subdomain I link to resolves to a live distribution.

Habits worth keeping

  • Remove the origin and the behaviour before you delete the bucket, not after.
  • Audit with a script rather than by eye: list the origins, strip the bucket name, call head-bucket and flag every 404.
  • Treat every DNS name and every CloudFront origin as something that can go stale.