---
title: "The blog you shut down still serves an attacker: subdomain takeover"
description: "If you remove a hosted service but leave its CNAME record in DNS, anyone can claim the same name at that provider and publish their content on your subdomain. Remove DNS records first when you shut down, and create them last when you set up."
url: https://ihsanalapsi.dev/articles/subdomain-takeover-dangling-dns
lang: en
date: 2026-11-26
updated: 2026-11-26
tags: ["App security", "Web development"]
author: Ihsan Alapsi (إحسان العبسي)
---
# The blog you shut down still serves an attacker: subdomain takeover

You built a side blog two years ago on a hosting service, then shut it down because nobody read it. Today that same name, under your own domain, could be showing a fake login page to your customers. By the end of this article you will know how that happens without anyone hacking you, how to find such names on your domain, and in what order to set up and shut down services so it doesn't happen again.

## What is a CNAME record?

A CNAME record is a line in your domain's DNS settings that says: "this subdomain is the same as that name at another provider." Like a sign on your shop door that says "we moved next door."

For example, `blog.yoursite.com` points at a name at your hosting provider, and the provider serves the content. Your DNS doesn't know what is in the shop next door; it just sends people there.

## How does subdomain takeover happen?

Subdomain takeover happens when a CNAME record still points at a service where nobody serves content, so an attacker claims the same name at the same provider and publishes their own content.

[MDN's page on subdomain takeovers](https://developer.mozilla.org/en-US/docs/Web/Security/Subdomain_takeovers) describes the scenario directly: you decide you no longer want the blog, so you remove the virtual host from the hosting provider, but you don't remove the DNS entry that points to it. Now an attacker creates their own virtual host with that provider, claims your subdomain, and hosts whatever they want.

The same thing happens in the other direction: when you create the DNS record before you claim the service itself, there is a window where the name points at an empty spot.

## Why is this so dangerous?

Because the page shows up under your own domain, and the browser treats it as part of your site. The visitor sees `blog.yoursite.com` in the address bar and has no reason to doubt it.

According to the same MDN page, an attacker who takes the subdomain can potentially read cookies set from the main domain, perform cross-site scripting, or get around content security policies, so they can capture protected information such as logins or send malicious content to visitors. If your session cookies are set for the whole domain, review [your session cookie settings](/articles/session-cookie-flags-check), because this is where it matters.

And here is the moment it clicks: the attacker didn't crack a password or touch your DNS account. Your own record still sends people there, and they simply claimed the spot you left empty.

## How do you find dangling records on your domain?

A dangling record is a DNS record that points at a service that is no longer yours. You find it with a list, not by guessing.

1. Export every DNS record from your domain provider's dashboard, and focus on CNAME records.
2. For each record, ask: who owns the service it points at, and do we still use it?
3. Check the name from your machine and see where it points:

```bash
dig blog.yoursite.com CNAME +short
```

4. Open the name in a browser. An error page from the provider itself saying there is no site under that name is a sign the record is dangling. Delete it now.

The same MDN page recommends keeping an inventory of all your organization's domains and their hosting providers, and updating it as things change, so nothing is left dangling.

## How do you prevent it in the first place?

The rule is about order: when you set up a service, claim the virtual host first and create the DNS record last. When you shut it down, remove the DNS record first.

If you use GitHub Pages with a custom domain, [GitHub's documentation on verifying your domain](https://docs.github.com/en/pages/configuring-a-custom-domain-for-your-github-pages-site/verifying-your-custom-domain-for-github-pages) says verification stops other GitHub users from taking over your custom domain and publishing their own site. It warns that takeover can happen when you delete your repository, when your billing plan is downgraded, or after any other change that unlinks the domain or disables GitHub Pages while the domain is still configured and not verified. The same documentation strongly recommends against wildcard DNS records such as `*.example.com`, because they put you at immediate risk even if you verify.

## Where do you start now?

The lesson for us as site owners: the DNS record is the last thing you create and the first thing you remove, because it is what sends your visitors, and it can't tell whether the spot is still yours.

Open your domain dashboard today, count your CNAME records, and test each one. If your site has a CSP, make sure it doesn't allow every `*.yoursite.com` without a reason; [rolling out CSP in report-only mode first](/articles/csp-report-only-rollout) helps you tighten it. And if you want someone to go over your domain and whole platform, [Muhassan](/muhassan) does that. How many CNAME records did you find?

## FAQ

**Does subdomain takeover need the attacker to break into my DNS account?**

No. Your record already points at the provider, and the attacker opens a normal account there and claims the name you left behind.

**A wildcard DNS record like *.example.com saves me work. Is it a problem?**

Yes. The GitHub Pages documentation strongly recommends against it, because it puts you at immediate risk of takeover even if you verify the domain.

**What can an attacker do with the subdomain once they have it?**

According to MDN they may read cookies set for the main domain, run cross-site scripting, or get around a content security policy, and send malicious content to your visitors.
