Skip to content

A Free and Secure Blog with GitHub, Zensical and Cloudflare Workers

A blog you own, that costs nothing to run and gives attackers very little to work with. The exact setup behind this site.

Contents

I'm restarting this blog. A lot has happened in AI, and new vulnerabilities come out faster than anyone can read them. So I'm going through everything I own, personal and company, and securing it one system at a time. This series shares how.

The first system is the simplest one: this blog. It costs nothing but the domain, has no server to patch, and loads nothing from other domains.

What I wanted

  • A blog I own. My domain, my posts as plain Markdown in my own repository.
  • Nothing to worry about. No server, database or plugins to patch, and nothing in the page from other domains. I want to write, publish, and not think about the site again.
  • Free. Only the domain costs money.
  • Easy to publish. Write Markdown, preview it, merge it, and it's live a minute later.

The setup

Three pieces, all free:

  1. GitHub holds the posts, drafts and notes in a private repository. GitHub Actions builds the site on every change.
  2. Zensical turns the Markdown into plain HTML files. It's from the authors of Material for MkDocs.
  3. A Cloudflare Worker serves those files on my domain. Workers are small programs that run on Cloudflare's network, close to readers; this one only serves the files. Serving static files is free, with no request limit, and Cloudflare handles the certificate.

Publishing is a pull request: I preview the post on my laptop, open the pull request, the build checks it, I merge, and the deploy job puts the new files live.

What makes it secure

Here's the whole setup, in the order a post travels. The first two parts run code other people wrote; the last two only ever see plain files.

Outside code runs here

Laptop

Write and preview

  • Malicious packagePinned, hashedA release with hidden code, from a hijacked maintainer or a lookalike name. Installing it runs that code with your access. Here: one package for the build, eleven with what it pulls in, each pinned to an exact version and hash. The deploy installs none.
  • Install scriptsTurned offnpm packages can run code the moment they're installed, which is where many malicious ones strike. Here: turned off in the repository's npm settings.
  • Exposed previewThis machine onlyA preview server open to the network can be reached by anyone on the same Wi-Fi. Seeing drafts early is the small part; the server itself is code that may have a hole to exploit. Here: it only answers on this machine.

GitHub

Repository and build

  • Stolen loginPasskey, no teamWhoever gets into the GitHub account controls the code, the build and the deploy. Here: passkey login, and no other collaborators.
  • Hijacked actionPinned to commitsActions are usually named by a tag like v4, and a tag can be moved to new code. Here: every action is pinned to a commit, and others are refused.
  • Bad pull requestOnly I can pushA pull request can change the workflow it runs with, to leak secrets or deploy its own pages. Here: I'm the only one who can push, and pull requests from forks don't run workflows at all.
  • Leaked tokenDeploys onlyA copied token works for whoever holds it, until it's revoked. Here: it can only deploy Workers, nothing else, and it expires after a year.

Only plain files here

Cloudflare

Domain and serving

  • Spoofed emailSPF, DMARC rejectAnyone can send mail claiming to be from your domain, unless the domain says otherwise. Here: SPF and DMARC say it sends no mail, so fakes are rejected.
  • Rogue certificateCAA recordsAny certificate authority can issue a certificate for any domain. Here: CAA records allow only the authorities Cloudflare uses.
  • Forged DNSDNSSECFake DNS answers can send visitors to someone else's server. Here: DNSSEC signs the answers.
  • HTTP downgradeHSTSSomeone on the network can keep a visitor on plain HTTP, where pages can be read and changed. Here: HSTS makes browsers use HTTPS only.

Reader

The browser

  • Injected scriptNo inline scriptsHTML slipped into a page can carry a script that runs as if the site wrote it. Here: the policy only allows script files from this site.
  • Third-party scriptNone loadedA script from another domain can change the page and watch readers, and its owner can change it at any time. Here: none are loaded.
  • TrackingNo cookiesCookies and analytics scripts follow readers across visits and sites. Here: no cookies and no analytics script.
  • ClickjackingNo framingAnother site shows this page in an invisible frame and tricks readers into clicking. Here: the page refuses to be framed.

Analytics without a script: Cloudflare counts visits at its edge, and Search Console shows the searches.

How a post travels from my laptop to your browser. Each card is a threat and what stops it here; hover over or tap a card for a short explanation.

One package for the build, none for the deploy

Readers get plain HTML and CSS, the theme's script and one small script of mine, all copied into the site at build time and served from this domain. The packages themselves run only where the site is built: on my laptop when I preview, and in GitHub Actions when it builds. That's where a malicious package could do damage.

The build needs one package I chose, the site generator, which brings ten more with it. The deploy used to need Cloudflare's deploy tool, Wrangler, which brought about ninety, all running in the one job that holds the Cloudflare token. So the deploy job now installs nothing: a short script, using only Python's standard library, uploads the files through Cloudflare's API. So:

  • every package and action is pinned, so nothing changes without a pull request;
  • I only upgrade for a reason: a feature I want, a bug that affects me, or a security issue that applies to how I use the package. A blog that works doesn't need the newest version;
  • the deploy job is the only job that uses the Cloudflare token, and it installs no packages.

What to avoid, and what to do instead:

Avoid Do instead
uses: actions/checkout@v4: a tag its owner can move to new code uses: actions/checkout@3d3c42e…ba90b1: a commit, which can't change. The repository refuses anything else
pip install zensical: whatever is newest today exact versions with hashes, installed with --require-hashes
npm install: can rewrite the lock file npm ci: exactly what the lock file says, hashes checked
npx wrangler: downloads the newest version if the local one is missing ./node_modules/.bin/wrangler: the locked copy, or nothing
install scripts left on ignore-scripts=true in .npmrc
one job that builds and deploys with the token a build job with no secrets, and a deploy job that runs only on main
pull_request_target, or a downloaded script piped into a shell plain pull_request, and only pinned tools
a deploy tool with ninety packages next to the token a short deploy script with no packages
Show the code

requirements.txt, generated by uv pip compile --generate-hashes:

zensical==0.1.2 \
    --hash=sha256:0d7fae6546c3982de202f92038b69027f16e5f8c33d212739f8d1a3b7a4d3a16 \
    ...

.npmrc (excerpt):

save-exact=true
ignore-scripts=true

The build job (excerpt): actions pinned to commits, and nothing installed that isn't hashed:

- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
  with:
    persist-credentials: false
- run: python -m pip install --require-hashes --no-deps -r requirements.txt

The deploy job (excerpt): only on main, the only job that uses the token, and nothing to install:

deploy:
  if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
  steps:
    - run: python3 -I scripts/deploy_worker.py
      env:
        CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}

What the deploy script does, in four API calls:

  1. Send Cloudflare the list of files and their hashes; it answers with the files it doesn't have yet and a short-lived upload key.
  2. Upload those files with that key, not the API token.
  3. Create a new Worker version with the settings, _headers and _redirects.
  4. Send all traffic to that version. If any step fails, the current version keeps serving the site.

Keeping the laptop itself clean is its own topic, for a later post.

A domain nobody else can use

Nobody should be able to send mail or get a certificate in the domain's name:

  • v=spf1 -all and DMARC p=reject, since the domain sends no mail;
  • CAA records, so only the certificate authorities Cloudflare uses can issue certificates for it;
  • DNSSEC, so resolvers that check signatures can spot forged answers.

Nothing in the page from anyone else

Fonts and images come from this site. There's no analytics script, no comment widget, no cookies, so no cookie banner either. Replies go to X. For numbers, Cloudflare counts visits at its edge, and Google Search Console shows what people searched for to find a post.

Headers that tell browsers to protect readers

The Worker sends these headers with every page. They live in a _headers file in the repository, so they're reviewed and versioned with everything else. The /* on the first line means "every page":

/*
  Content-Security-Policy: default-src 'self'; script-src 'self'; connect-src 'self'; img-src 'self' data:; style-src 'self' 'unsafe-inline'; font-src 'self'; object-src 'none'; base-uri 'self'; form-action 'self'; frame-ancestors 'none'; upgrade-insecure-requests
  X-Content-Type-Options: nosniff
  Referrer-Policy: strict-origin-when-cross-origin
  Permissions-Policy: camera=(), microphone=(), geolocation=(), payment=(), usb=()
  X-Frame-Options: DENY

The policy allows no inline scripts, so even if something slipped HTML into a page, it couldn't run code of its own. The theme wrote two small scripts straight into every page; I moved one into a file and dropped the other, which the site doesn't use. The build now fails if an inline script comes back. HSTS is set in Cloudflare, so it also covers www, which only redirects to thoughtson.ai.

To check your own site, run it through securityheaders.com: this one gets an A+.

Keeping the repository private

The repository is private: drafts and notes sit next to the site, and only the built pages are public. GitHub's free plan allows that, but drops two protections for private repositories: branch protection and environment secrets. When you're the only person with access, you can cover the gaps yourself:

  • Be the only one with access. No collaborators, and two-factor login on the GitHub account; a passkey is the easiest.
  • Give the deploy token as little as possible. It can deploy Workers in my Cloudflare account and do nothing else: no DNS, no other settings. It expires after a year and lives only in GitHub's secret store. It's the only secret; none is in the code.
  • Let the repository settings and the workflow enforce the rules. Only main deploys, and only GitHub's own actions can run.

Those workflow rules only hold while you're the only one who can push: anyone who can push a branch can change the workflow and read the token.

Run it on your own blog

I turned this setup into a skill for coding agents: a free and secure blog on tldrskills. Give your agent the prompt on that page, and it takes you through the same steps for a new blog, a move from another host, or a check of the one you have. It asks before every change that matters, and you sign in to each service yourself. tldrskills.com was set up that way, and the skills are on GitHub.

Next steps

Find me on X and let me know if this is useful to you, if you have a system you want me to secure next, or if you just want to connect and say hi.