↓ Skip to main content
Security

Cloudflare Part 2: how it secured my two sites

Cloudflare, plainly - This article is part of a series.
Part 2: This Article
After the blog was hacked, I had two jobs: get off the server that let it happen, and make sure whatever stayed there was hard to reach. Cloudflare did most of the second job, though not all of it. This post goes through each risk, the setting that answers it, and what’s still open.
Two cards. samarthya.me: 63 old DNS records cut to 11; the blog DNS-only to GitHub Pages; www and the old blog name proxied and redirected with a 301 at the edge (blog via the placeholder 192.0.2.1); about proxied with Full (strict) TLS; mail DNS-only on its own name. bhanuni.in: no server, both names proxied to 192.0.2.1 and sent to the gallery with a 302, SPF -all and DMARC p=reject because it sends no mail, and Always Use HTTPS.
Two domains, every record with a job

Part 1 covered the front desk in general. This post is about my own front desks. Earlier posts have the click-by-click detail; here I’m looking at what each step protects against.

Words used in this post
#

TermMeaning here
ZoneAll the DNS records of one domain, as Cloudflare manages them
Attack surfaceEverything an attacker could try: names, open ports, forgotten pages
Full (strict)Cloudflare connects to the origin over HTTPS and checks its certificate
301 / 302Redirects: moved permanently and found elsewhere for now
SPF, DMARCDNS records telling mail servers who may send mail for a domain, and what to do with fakes
Placeholder address192.0.2.1, from a block reserved for documentation; nothing answers on it

The starting point
#

In October the whole domain lived at one shared host: website, mail and DNS. The website was a six-year-old WordPress install, and someone had planted files in it. The decision in Rebuilding was:

  • the blog becomes static on GitHub Pages: nothing to log in to, no plugins, no database;
  • the old host keeps only mail and one static subdomain;
  • Cloudflare takes over DNS and, where it helps, stands in front.

Risk by risk
#

RiskWhat I did in CloudflareWhere
Forgotten names pointing at the old serverRebuilt the zone from scratch: 63 records became 11Rebuilding 4
Moving the site breaks mailMail got its own name (MX → mail.), DNS onlyRebuilding 4
Six years of old links hitting the old serverThe old blog name is proxied to the placeholder and answered with a 301 at the edgeAbout 3
www sent through to GitHub only to bounce backA redirect rule answers it at the edgeAbout 3
A site on a host I don’t trustabout is proxied with Full (strict) TLS and cachedAbout 3
Anyone can claim my domain on GitHub PagesThe domain is verified with GitHub (one TXT record)Rebuilding 4
A spare domain used to fake emailbhanuni.in says “no mail, ever”: v=spf1 -all, DMARC p=rejectbhanuni.in
A new domain needing a new serverbhanuni.in has no server: two proxied placeholders and one 302 rulebhanuni.in

A few of these are worth a closer look.

The cheapest security work: deleting records
#

The old DNS panel had 63 records. Most were things the hosting panel had made for itself, one-time certificate tokens, and subdomains nobody had used in years. Each one is a name that still answers. A forgotten subdomain that points at an old server is exactly the kind of door you don’t know you left open.

I copied over only the 11 records I could explain. Everything else stopped existing when the nameservers changed. No other step removed as much attack surface for as little work.

Redirects that never touch a server
#

The old blog.samarthya.me name gets the most traffic from bots and old bookmarks. It points at 192.0.2.1, an address nothing listens on, with the orange cloud on. Every request lands at Cloudflare, a redirect rule answers it with a 301 to the same path on the new site, and no server anywhere sees it:

curl -sI "https://blog.samarthya.me/wps/x/?a=1" | grep -i "^HTTP\|^location\|^server"
# HTTP/1.1 301 Moved Permanently
# Location: https://samarthya.me/wps/x/?a=1
# Server: cloudflare

bhanuni.in uses the same trick for the whole domain: a 302 to the gallery, and no machine to patch.

Strict TLS to a host I don’t trust
#

about.samarthya.me is the only thing still served from the old host. It’s proxied, so visitors get Cloudflare’s certificate, and Cloudflare connects onwards with Full (strict): HTTPS to the origin, and the certificate must be valid for the name. The looser modes (Flexible, plain HTTP to the origin, or Full, any certificate) would have hidden a real mistake I made: for a day, the origin served the host’s default certificate. Strict mode turns that kind of slip into an error you can see.

The origin’s certificate comes from Let’s Encrypt over HTTP-01, not DNS-01, so no Cloudflare API token ever sits on that server.

The blog itself stays grey
#

The blog at samarthya.me is DNS only. GitHub Pages serves it, has its own CDN, and renews its own certificate. Putting Cloudflare’s proxy in front would add rules I don’t need, and it can get in the way of GitHub’s certificate renewal. A static site with nothing to log in to is already a small target. Not everything needs the orange cloud.

What it looks like from outside today
#

for h in samarthya.me www.samarthya.me about.samarthya.me blog.samarthya.me bhanuni.in; do
  printf "%-20s " "$h"; curl -sI "https://$h/" | grep -i "^HTTP\|^server" | tr -d '\r' | paste -sd' '
done
NameStatusAnswered by
samarthya.me200GitHub.com
www.samarthya.me301cloudflare
about.samarthya.me200cloudflare
blog.samarthya.me301cloudflare
bhanuni.in302cloudflare

What’s still open
#

Being honest about the trophy shelf means listing the empty spots too. I looked these up while writing:

  1. DNSSEC is off on both domains. No DS record at either registry. DNSSEC signs the zone’s answers so nobody can forge them on the way. Turning it on is one click in Cloudflare plus one record at the registrar (part 3).
  2. samarthya.me’s DMARC is still p=none and its SPF ends in ~all (softfail). That’s the “watching” stage: reports come in, but fake mail isn’t rejected. Once the reports show only the real mail server sending, it should become p=quarantine, then p=reject.
  3. No HSTS yet. Browsers aren’t told to insist on HTTPS. It’s easy to switch on and hard to undo (part 3), so I’m leaving it until everything that’s proxied has a working certificate for good.
  4. No WAF rules of my own. Cloudflare already sees and blocks a lot without being asked (About 4). I want a few weeks of data before I write rules.

Takeaways
#

  • The biggest security gain was the least exciting: rebuilding the zone with only the records I could explain.
  • A proxied placeholder plus a redirect rule gives a name that works for visitors and has no server to attack.
  • Use Full (strict) wherever Cloudflare talks to an origin. The other modes hide the mistakes you most need to see.
  • Leave names DNS only when the host already does TLS and caching well. The orange cloud is a tool, not a badge.
  • Write down what’s still open. DNSSEC, DMARC enforcement and HSTS are my next three.

References
#

Next: part 3, the free tier, and a checklist for your own domain.

Author
Samarthya
Engineer, learner, tinkerer. This is my trophy shelf of everyday work and leisure.
Cloudflare, plainly - This article is part of a series.
Part 2: This Article

Related

Cloudflare Part 1: an introduction

Think of a hotel. Guests never walk straight to a room: they talk to the front desk, which checks who they are, answers what it can, and only calls up to the room when it has to. Cloudflare is a front desk for a website. This series is about what that desk does, how it protected my two domains, and what you get from it for free. Two ways to reach a site: through the front desk, or around it I’ve used Cloudflare for a month now, for samarthya.me since the blog moved after the hack and for bhanuni.in. Earlier posts showed single steps. This series puts them together, starting with the basics.

Building about.samarthya.me, part 3: Cloudflare in front

The hub lives on an old server I no longer fully trust. So it gets a receptionist: every visitor talks to Cloudflare, and only Cloudflare talks to the server. This post is about setting up that front desk, record by record. One domain, four kinds of record, one front desk Part 1 and part 2 produced the data. Before the site can be published (part 6), it needs an address, a certificate and a sensible cache.

bhanuni.in: a domain, a redirect and a gallery that keeps her safe

In 2019 I booked a domain in my daughter’s name, bhanuni.in, and then did nothing with it for almost six years. It sat in a drawer like a gift card. She now draws every day (digitally & otherwise) (ponies - MLP, Sprunki, Rat-A-Tat, Sab Jholmaal hai and weekend sessions as part of a group), so the domain finally has a job: it opens her gallery. This post is all about how I wired it up, why I picked the boring option, and the precautions I take before any of her pictures go online. The redirect, and the importer every drawing goes through New to RDAP, SPF, DMARC or a proxied record? Every term in this post is explained in plain words in Keywords at the end. What I wanted # Three things, in this order: