Security and governance: the part nobody tells you about after you build
Period: November and December 2026 · Role: audit, fixes, deployment and routine design, with Claude Code and subagents · Status: fixes in production since 2026-11-29; weekly, monthly and quarterly routine running; the routine closed 21 more items by 2026-12-05 (section 8) · Updated: 2026-12-05
In one sentence: after shipping more than a dozen systems in a few weeks with AI agents, I stopped to audit all of them at once against the most common attacks on AI-generated code, found and fixed a critical flaw the same day, shipped the fixes to every system, shut down a server nobody remembered existed, and turned what I learned into a routine that runs on its own.
1. Context and problem
In two months, the group put into production an ERP, two SaaS products (accounting and clinics), an AI legal product in pilot, a WhatsApp support hub with AI, a sales bot, a prospecting engine with two spin-offs, a management accounting system, websites and a tax legislation monitor. All built with AI agents, fast, with tests and careful deployment.
Build speed creates a specific kind of risk: each system is born well, but nobody looks at all of them at the same time. A post about “the 8 attacks that take down AI-built systems” became a concrete question: where do we stand, across all of them, today?
2. Results
| Metric | Value |
|---|---|
| Applications audited | 13 (12 on Next.js and 1 on Node), plus 7 static sites and the server |
| From audit start to fixes in production | one day (2026-11-29) |
| Exploitable critical flaw found | 1, confirmed in production and fixed the same day |
| Applications upgraded to a Next.js release without the known critical flaws | 12 of 12 |
| Proxy sites with security headers | 25 of 25 |
| Applications that stopped running as root | 12 |
| Forgotten server shut down | 1 old hosting plan, with 24 domains and a compromised site |
| Backup of the old hosting | 27.7 GB, encrypted, immutable for 30 days, restore tested, 0 differences |
| Open items at the end of the day | low severity only |
| Routine created | automated weekly check and monthly audit, quarterly review |
| Items closed by the routine the following week | 21, including mandatory 2FA for administrators, the Cloudflare proxy, error alerts and a disaster drill |
3. Method
flowchart LR
A[Post: 8 attacks<br/>on AI-built systems] --> B[One checklist<br/>8 attacks + governance]
B --> C1[Agent 1<br/>ERP]
B --> C2[Agent 2<br/>accounting SaaS]
B --> C3[Agent 3<br/>clinics SaaS]
B --> C4[Agent 4<br/>legal AI]
B --> C5[Agent 5<br/>WhatsApp]
B --> C6[Agent 6<br/>prospecting and others]
B --> S[Server<br/>ports, ssh, firewall]
C1 & C2 & C3 & C4 & C5 & C6 & S --> R[Report<br/>severity and evidence]
R --> V{Confirm<br/>in production}
V --> P0[Critical:<br/>fix now]
V --> P1[High and medium:<br/>one agent per system]
P0 & P1 --> D[Deployment<br/>backup, md5, attack replayed]
D --> G[Routine<br/>inventory and cadences]
| Step | How it was done |
|---|---|
| One checklist | The same list for everything: XSS, exposed routes and access to another customer’s data, exposed keys, open database, SQL injection, attempt limits, prompt injection and packages; plus sessions, 2FA, audit trail, uploads, webhooks, data retention and containers |
| Parallel audit | Six Claude Code subagents, one per system, read-only: code review, gitleaks over the git history and npm audit. Every finding with file and line, separating confirmed from suspected |
| Confirmation | A critical finding is only critical after being reproduced in production, with data that does not exist, without reading anything real |
| Fixes | One subagent per repository, each confined to its own, with the system’s own test suites passing before the commit |
| Deployment | I deployed one system at a time: production compared to the previous commit by md5, code and database backups verified, deploy, migration, and the attack itself replayed against production to prove it was closed |
4. What the audit found
| Attack | Before | After |
|---|---|---|
| 1. XSS | None confirmed; one suspicious path in media received over WhatsApp | Third-party media served as an attachment, with a policy that prevents execution |
| 2. Exposed routes and other customers’ data | Critical: a server action answered without login, treating the visitor as an administrator. High: in a multi-tenant SaaS, a check trusted the user’s company list without verifying in the database which customer the company belonged to | Without login the action returns nothing; the check now verifies ownership in the database, with a test proving one customer cannot read or write another’s data |
| 3. Exposed keys | No keys on GitHub; old keys stored in plain text in a local configuration file | Revoked, verified as dead and removed from the file |
| 4. Open database | No production database exposed | Kept |
| 5. SQL injection | None | Kept |
| 6. Attempt limits | The weakest point: login and 2FA with only a small delay, no lockout | Per-account and per-IP lockout in every system; 2FA invalidates the challenge after 5 wrong codes; AI spending caps in dollars where missing |
| 7. Prompt injection | Good: no AI with tools that take actions, validated outputs, masked personal data | Third-party text delimiters neutralized where they could still be forged |
| 8. Packages | Critical everywhere: a framework version with known remote code execution and proxy bypass | All upgraded, with npm audit clean in production |
Also shipped the same day: security headers on every domain (HSTS, nosniff, iframe protection on the admin panels), internal identity headers stripped at the edge, containers without root, SSRF protection in the bot that reads web pages (including its headless browser), 24-month retention for WhatsApp conversations, and a server reboot to apply OS updates.
5. What nobody was looking at
The most serious findings were not in the systems I worked on every day:
- A forgotten old hosting plan, still active and paid, with 24 domains, 96 mailboxes from before the email migration, and the old WordPress of one of the group’s sites compromised. The domain already pointed to the new site, so nobody saw it, but the server was still there, compromised and tied to the company’s name. I took a full backup, stored it encrypted as evidence, checked domain by domain what still depended on it, moved what was needed, deleted the sites and databases and shut the plan down.
- Two public sites off the radar, on a framework version with a critical flaw, running as root. They were not on the audit list because they were not on any list.
- The secrets file copied into the Docker images of three systems, for lack of a
.dockerignore.
The conclusion became the routine’s first rule: what is not in the inventory does not get audited.
6. Mistakes along the way
Three mistakes of mine during the day, all caught by the check that follows every action:
- A file uploaded empty to the server. The build failed and the old system stayed up, because the deploy script only swaps the container if the build passes. I resent it another way and checked the md5 before deploying.
- A manual collection that saved a redirect page as if it were the text of a law, creating a false version and alert in the legislation monitor. I deleted the record before the alert went out and redid it following the redirect.
- The wrong API key revoked. While cleaning up exposed keys, the key revoked was the production one, and the exposed one stayed active. Testing every key after revocation showed the swap right away: audio transcription was restored with a new key written by a local shortcut that keeps the secret out of the conversation, and the exposed key was revoked right after.
None of the three reached an end user. The pattern that worked was the same in all three: every action has a check right after it, and the check measures the result, not the intention.
7. The routine that stayed
| Piece | What it is |
|---|---|
| Inventory | Servers, systems, domains (where the registration and the DNS live), paid subscriptions, keys and backups, each item with an owner and a last-reviewed date |
| Minimum standard for every app | Ten rules that apply from the first deploy: login limits and 2FA, record ownership checked on every route, headers at the proxy, non-root container, secrets outside the image, critical dependencies upgraded within 7 days, AI with no action without human review and with a spending cap, backup before deploying, signed webhooks, defined retention |
| Every week | A scheduled task that checks dependencies, versions, headers, certificates, backup age and the server, and only calls someone if it finds something |
| Every month | Automated full audit, read-only, with a report and open items; nothing is fixed without approval |
| Every 3 months | Keys and access, restore test, domains and subscriptions, data protection (LGPD) and a review of the routine itself |
| Severity and deadline | Critical the same day, high in 7 days, medium in 30, low in the next release |
8. The following week: what the routine delivered
The audit ended with a list of medium and low severity items, each with an owner and a deadline. In the week of 2026-11-30 to 2026-12-05 the list moved, and a post about “what every backend needs” became four more items, compared one by one with what already existed.
| Area | What changed |
|---|---|
| Two-step verification | Mandatory on the internal prospecting and management accounting systems (single-user basic login was replaced by a proper login, with backup codes and no way to turn it off), for anyone who opens medical records in the clinic system and for administrators in the accounting SaaS. An administrator cannot turn off their own verification; to switch phones, another administrator resets it, which immediately ends all of that person’s sessions. Nobody resets their own |
| Sessions | Expire after inactivity in the browser (not in the mobile app), with a session log and a way to sign out other devices |
| Redirect after login | The return address accepted backslashes and control characters, which some browsers read as another site. It now accepts only a clean internal path, with tests for the attack cases |
| Cloudflare proxy | Turned on in front of 44 addresses, with strict SSL to the origin. The server accepts the visitor’s real IP only when the request comes from Cloudflare’s published ranges; an IP forged from outside is replaced, tested both ways. Without this, the login attempt limit, which counts per IP, would start counting the proxy’s IP |
| Errors and slowness with alerts | Access log without personal data: no IP, no headers, no query parameters and long path segments masked, kept for 7 days. A watcher reads the last 15 minutes every 5 and sends an email if an app has 3 or more internal errors, 10 or more unavailable responses or 3 or more requests over 30 seconds. The alert was tested with a simulated failure |
| Automatic LGPD retention | A daily job in four systems deletes or anonymizes what is past its deadline (sessions, access logs, conversations), with approved retention periods and its own test |
| AI spending cap | A daily dollar limit in every system with AI, with a phone notification when the limit is hit |
| Public forms | Per-IP and per-day submission limits on the sites’ quote forms |
| Quality | Zero lint and type errors in four older systems |
| Disaster drill | The accounting SaaS came up in full on the standby server from the latest dump, in about 4.5 minutes of machine time, with data matching production and the clients’ digital certificates opening with the copy’s key. Details in the infrastructure case |
Job catalog. Everything that runs without anyone clicking (timers, workers, cron, webhooks, collection, cleanup, backup) went into a single catalog, with the code snippet that proves the job exists and the evidence that it ran: last run time in a table, a log line or a ping to an external monitor. A checker runs before every deploy, to flag a job that disappeared from the code, and after, to flag a job that stopped in production. In its first week it found three data collections that had been stopped for days without anyone noticing: a government server certificate missing its intermediate, a public API that started timing out on full-year queries and transient overnight errors on an official portal. All three were fixed with automatic retries and smaller query windows.
Two mistakes of mine this week, caught by the checks:
- Configuration applied on the server, but not in the container. The proxy’s file, mounted inside the container, stayed pinned to the old version after being copied over, and the reload “succeeded” with the old configuration. For 8 minutes the apps saw Cloudflare’s IP instead of the visitor’s. A check from the outside showed the difference; the rule now is to verify by reading the file inside the container.
- The disaster drill did not come up on the first try. The standby server’s configuration was readable only by the administrator, and the app has run unprivileged since the audit. A security fix had silently broken the recovery path. That is exactly the kind of thing that only shows up in a drill.
9. Lessons
- Building fast is not the problem; not looking is. AI agents speed up building and, with the right checklist, speed up auditing the same way: six systems read in parallel in minutes.
- Inventory first. The biggest risk was in what was not on the list.
- Confirm before classifying. A finding read in the code is a suspicion; reproduced in production with fake data, it is a fact.
- Every fix proves it closed. The same attack, replayed against production after the deploy.
- Secrets do not go through the conversation. New keys and passwords go in through local shortcuts that write straight to the server.
- Security needs drills too. A correct fix (no root in the app) silently broke the recovery path; only the disaster drill showed it.
- A useful log does not need personal data. To know an app is failing or slow you need the path, the status code and the duration; IP, headers and parameters stay out.
- Governance is a routine, not a project. Audit day fixed the past; the weekly check and the monthly audit take care of the next thing someone forgets.
10. Tools
Claude Code with parallel subagents · gitleaks · npm audit · Caddy (headers, internal header stripping, rejecting Server Actions without Origin) · Docker with unprivileged users · Next.js 16 · PostgreSQL · rclone with encryption and Backblaze B2 with Object Lock · Cloudflare (DNS and proxy) · Healthchecks.io · Claude scheduled tasks.
Reports and code stay private; I walk through the method, the audit checklist and the routine in interviews.