• Apr 28, 2026
  • 6 min read

I Replaced Decap CMS With My Own Editor, and Forgot to Lock the Actions

A look back at a retired client project: what I built, what a later review found, and how the fix works.

When I built websites for people close to me, one question kept coming back: how do I change this? For a real estate agency it mattered most: listings come and go, prices change, photos get swapped. Sending me an email each time wasn’t going to last.

Why not Decap CMS

The obvious answer was Decap CMS, a Git-based editor for static sites. In practice it fought me: routing conflicts and 404s inside the Astro site, and an authentication setup (Netlify Identity or GitHub OAuth) far heavier than “one agent edits their own listings”. I wrote a change request to replace it, with one rule: no new dependencies the owner has to understand.

What I built instead

The public site stays static: fast, cheap, nothing to break. Only the editor is server-rendered:

PartHow
Public pagesAstro, generated as static HTML
/edit pagesAstro server-rendered pages: list, create, edit, delete listings, plus site settings (hero text, bio, contact)
StorageMarkdown files on disk, one per property, front matter read and written with gray-matter
Write actionssmall API routes: /api/properties/create, update, delete, /api/settings/update
ProtectionCloudflare Access in front of /edit/*, plus HTTP Basic auth with a bcrypt-hashed password in the app

Two decisions I’d make again:

  • One container, not two. Static site and editor together: one process, one filesystem, one tunnel, one Access policy. A separate admin container would have meant syncing files between them for no gain at this size.
  • Files, not a database. Every listing is a Markdown file in Git. Backups, history and “undo” come for free.

The gap

Months later I reviewed the project with fresh eyes, and found the kind of bug I’d written a whole post warning about: hiding something is not the same as protecting it.

The middleware protected pages under /edit. It also explicitly let every path under /api/ through, and the Access policy covered /edit/*. So:

RequestProtected?
GET /edit/properties (the editor page)yes: Access + password
POST /api/properties/delete (the action that page calls)no

The buttons were behind a login. The endpoints the buttons call weren’t. Unless the Access rule also happened to cover those API paths, anyone who read the page’s JavaScript, or guessed the routes, could create, change or delete listings directly. Nothing in the UI hinted at it, because the UI was exactly the part that was protected.

Where Cloudflare Access fits

Cloudflare Access was already in front of the editor, and it could have closed this gap on its own. Used fully, it does four things:

  1. Cover the actions, not just the pages. One Access application can list several paths on the same hostname: /edit/*, /api/properties/*, /api/settings/*, /api/scrape-proxy. A browser that passed Access for the editor sends the same Access cookie with the API calls, so the editor keeps working without any code change.
  2. Leave public routes out, on purpose. The site’s chatbot endpoint must stay reachable without a login, so it can’t sit behind Access, and needs its own protection (part 2). Every route should be a written decision: public or private.
  3. Let the app verify Access instead of just trusting it. For every request that passed, Cloudflare adds a signed token in the Cf-Access-Jwt-Assertion header. The app can check its signature against the team’s public keys and its audience (the application’s ID), and reject anything without a valid one. Then Access is the login, and a wrong path rule fails closed instead of open.
  4. Make the tunnel the only way in. All of this holds only if the app can’t be reached around Cloudflare. With a Cloudflare Tunnel and no published ports, there’s no direct path to the container.

If a script ever needs to call those APIs, Access service tokens (a client ID and secret sent as headers) let it through without a browser login, scoped to that one application.

The fix: protect actions, not pages

The rule is simple: every request that changes state is checked on the server, whatever URL it uses.

import { createRemoteJWKSet, jwtVerify } from "jose";

const PROTECTED = ["/edit", "/api/properties", "/api/settings", "/api/scrape-proxy"];
const TEAM = "https://<team>.cloudflareaccess.com";
const KEYS = createRemoteJWKSet(new URL(`${TEAM}/cdn-cgi/access/certs`));

async function hasValidAccessToken(request: Request): Promise<boolean> {
  const token = request.headers.get("cf-access-jwt-assertion");
  if (!token) return false;
  try {
    await jwtVerify(token, KEYS, { issuer: TEAM, audience: process.env.CF_ACCESS_AUD });
    return true;
  } catch {
    return false;
  }
}

export const onRequest: MiddlewareHandler = async ({ request, url }, next) => {
  const needsAuth = PROTECTED.some((p) => url.pathname.startsWith(p));
  if (!needsAuth) return next();          // public pages and the public chat API
  if (!(await hasValidAccessToken(request))) {
    return new Response("Forbidden", { status: 403 });
  }
  return next();
};

The app no longer needs a password of its own: the Access token proves who the person is, and the middleware proves the token is real and meant for this app.

Plus three smaller lessons from the same review:

  • No default credentials. The code fell back to a built-in password hash and a placeholder session secret if the environment variables were missing. Now it refuses to start without them.
  • No credentials in logs. Debug lines printed part of the password hash and the length of every attempted password. Gone.
  • Two layers that each stand alone. A path rule at the edge is one configuration mistake away from open. Verifying the Access token in the app means a wrong rule makes a route unusable, not unprotected.

And a test that would have caught it, run against the dev server:

curl -s -o /dev/null -w "%{http_code}\n" -X POST localhost:4321/api/properties/delete \
  -H "Content-Type: application/json" -d '{"slug":"test"}'    # expect 403

What I’d tell myself

  • List the actions, not the pages. Every endpoint that writes is part of the admin, whatever folder it lives in.
  • Test the API without the UI. The UI only shows you the path you designed.
  • Never let the edge be the only lock; make the app verify what the edge decided.

Takeaways

  • A small custom editor beat a CMS for one owner and one content type.
  • Static public pages, server-rendered admin is a good split.
  • Protect every state-changing endpoint on the server.
  • Cover the API paths in Cloudflare Access, and verify its token in the app.
  • No default secrets, no secrets in logs.