The Approve Button Had My Password In It
Before rebuilding this site, I froze its AI writing pipeline and read the Worker like an attacker. The review step was the weakest part.
Before I tore down the old NerdlyBuilds, I did one last thing with it. I turned off its cron triggers, so the AI pipeline would stop writing posts. Then I read the Worker behind it from top to bottom, the way someone who wanted to break it would.
I’d already written about the content side of that teardown: the 61 auto-generated posts, the thumbnails on a 30-day timer, the five markdown renderers. This post is about the other half. A handful of commits, all landed the same day, closed holes I had built myself. And the worst of them sat in the part I’d added to be safe: the human review step.
The pipeline, briefly
The old setup ran on a single Cloudflare Worker with two schedules. On weekdays at 10:00 UTC it asked Claude, with web search on, for the latest AI news and stored the results. On Fridays at 14:00 UTC it turned the week’s results into an article, generated images, saved everything as a draft and emailed me. The email had two buttons: Approve and Reject.
The model was reading arbitrary web pages and writing text that would go out under my site’s name. The only gate between that text and the public was me clicking a button. So the button deserved more scrutiny than anything else in the system. It got the least.
The secret lived in the link
Here’s how the review email built those two buttons:
const approveUrl = `${base}/api/approve/${env.REVIEW_SECRET}/${article.slug}`;
const rejectUrl = `${base}/api/reject/${env.REVIEW_SECRET}/${article.slug}`;
REVIEW_SECRET wasn’t a one-time token for that draft. It was the only credential the Worker had. The same value guarded every admin route: publishing, deleting articles, editing project pages, reading the client intake forms people submitted through the site.
So every review email carried the master key in plain text, inside a URL. URLs are the leakiest place you can put anything. They end up in browser history, in server logs, and in any tool that scans or rewrites links in your inbox. And the link worked as a plain GET request, so anything that simply followed it would publish the draft.
Email wasn’t the only leak. The admin endpoint that listed drafts returned the same URL for each one:
approveUrl: `/api/approve/${env.REVIEW_SECRET}/${d.slug}`
And if the email provider wasn’t configured, the Worker logged the approve link with the secret in it to the console instead, as a fallback.
The fix was to stop treating approval as a link. Approve and Reject became POST /api/drafts/approve and /reject, authenticated with an Authorization header. The review email now links only to the admin dashboard, with every field HTML-escaped. The old /api/approve/* and /api/reject/* paths still exist, but only to return 410 Gone and do nothing, so any old link left in my inbox is dead.
Drafts weren’t drafts
The public endpoint for reading an article had a quiet fallback:
let a = await env.BLOG_KV.get(`article:${slug}`, 'json');
if (!a) a = await env.BLOG_KV.get(`draft:${slug}`, 'json');
If no published article matched the slug, it served the unpublished draft. No auth check. Anyone who guessed or saw a slug could read a post I hadn’t approved. That included posts I’d go on to reject.
I didn’t add that by accident. It was how the Preview button in my admin page worked. Preview opened the normal public article page with ?preview=draft on the end, and that page fetched the draft through the public endpoint. To let me read a draft before approving it, I’d made every draft readable by everyone.
Now the fallback only happens for authenticated requests, and there’s a separate authed GET /api/drafts/:slug for the dashboard.
Unreviewed model output, rendered on my own domain
This one is the most specific to AI, and it took me longest to see.
The public article page rendered post bodies like this:
document.getElementById('article-body').innerHTML = marked.parse(processed);
marked passes raw HTML in markdown straight through, and nothing sanitized the result. For posts I’d approved, that’s sloppy. For drafts, it’s worse. That body was written by a model that had just read whatever web pages its search turned up. So Preview took text shaped by strangers’ pages and ran it as live HTML on my own domain. That’s the same domain where my admin page kept the review secret in sessionStorage while I was logged in.
OWASP has a name for this: Improper Output Handling, number five on its 2025 list of LLM risks. The idea is simple. Whatever a model writes should be handled like input from a stranger, because in a sense that’s what it is. My pipeline handled it like my own writing.
The new Preview doesn’t use the public page at all. The dashboard fetches the draft with the auth header and renders it inside an iframe with an empty sandbox attribute:
<iframe id="preview-frame" sandbox="" title="Draft preview"></iframe>
An empty sandbox means no scripts and no same-origin access. The draft can look however it wants, but it can’t do anything.
The same commit fixed a smaller version of the problem in the dashboard itself. Its buttons were built by gluing data into onclick strings:
'<button class="btn btn-sm btn-green" onclick="approveDraft(\'' + draft.slug + '\')">Approve</button>'
The slug was made from the model’s title. In practice the slug function stripped quotes, so this one was safe by luck: the dashboard’s safety depended on a helper in a different file that was never written with security in mind. Now buttons carry escaped data-* attributes, and one delegated listener handles them all.
Auth that failed open
Every protected route checked auth with the same copy-pasted line. I counted 23 of them:
if (request.headers.get('Authorization') !== `Bearer ${env.REVIEW_SECRET}`) return json({ error: 'Unauthorized' }, 401, cors);
Read it with the secret missing. If REVIEW_SECRET is ever unset, say after a botched deploy or a renamed variable, the template literal becomes the string Bearer undefined. Send that header and you’re in. A missing secret should lock everyone out. This line would have let everyone in who knew the trick.
All 23 now call one function:
// Fails closed if REVIEW_SECRET is missing/short; constant-time compare of the Bearer token.
function isAuthed(request, env) {
const secret = env.REVIEW_SECRET;
if (typeof secret !== 'string' || secret.length < 16) return false;
const enc = new TextEncoder();
const a = enc.encode(request.headers.get('Authorization') || '');
const b = enc.encode(`Bearer ${secret}`);
let diff = a.length ^ b.length;
const len = Math.max(a.length, b.length);
for (let i = 0; i < len; i++) diff |= (a[i] ?? 0) ^ (b[i] ?? 0);
return diff === 0;
}
It does two things the old line didn’t. It refuses to authenticate anyone if the secret is missing or short. And it compares every byte instead of stopping at the first mismatch, so response timing doesn’t hint at how much of a guess was right. The timing part is belt-and-braces over the network. The fail-closed part is the one that matters.
The leftovers
Three smaller things came out the same day.
Six debug routes. While I was getting the pipeline working, I’d added /api/debug/scrape, /full, /generate, /email, /image and /imgkeys. They were behind auth, but they ran paid model calls on demand. The image and email ones also echoed the first eight characters of my Gemini and Mailgun API keys into their responses, to show whether the keys were set. A partial key is still a piece of a key, and I had no use for any of these anymore. All six were deleted.
CORS on everything. Every route, public or admin, answered with Access-Control-Allow-Origin: *. To be fair to past me, this was more sloppy than dangerous. Auth was a Bearer header, which browsers don’t attach on their own, so a random site couldn’t ride my login. Still, there was no reason for admin routes to invite every origin. Now public reads and the two public forms get *. Everything else only reflects my own site or localhost, with Vary: Origin.
Inputs from strangers. Intake emails dropped some form values into HTML without escaping them. The newsletter signup accepted anything with an @ in it. Now the values are escaped, and an email has to be a string of at most 254 characters that passes a simple pattern check, lowercased before de-duplicating.
Where review lives now
The new site doesn’t need most of these fixes, because the dangerous parts are gone. Posts are Markdown files in Git. An agent can draft a post from my notes, but all it can do is open a pull request. It can’t publish or merge, and it can’t touch anything outside the content folder. I read the draft on a staging preview and merge it myself. The How this site is made page has the full rules.
Look at what that does to the old problems. The approval step is a merge button behind my GitHub login, not a URL. A draft is a branch, not a public record that a missing auth check can expose. And the preview is a separate staging build, not my production domain.
What I’d check in any AI pipeline
None of these bugs were clever. They were normal web mistakes. The AI part is why they mattered: the content flowing through them came from a model reading pages I’d never seen.
- Read the review step like an attacker would. It’s the most trusted path in the system, so it’s the one worth breaking. Mine handed out the master key.
- Treat model output as untrusted input. Render it sandboxed or sanitized, especially before a human has looked at it. “It’s my pipeline” isn’t the same as “I wrote it.”
- Make auth fail closed. Read your auth check as if the secret were missing. If the answer is “anyone gets in,” fix that first.
- Delete debug code once it’s done its job. Every helper route that echoes config is a small leak waiting for a bad day.
It’s the same lesson I ran into from a different direction when my local model called a tool it was never offered. Whatever the model produces, check it at the point where it can do damage, not just where you hoped it would behave.
— Colby, NerdlyBuilds


