Gus Mejía ES: ver esta página en español View CV Lab

Notes · 09

Security before code.

· Security

I worked out the worst case of three AI demos for my site. With every cap working, about US$60 a month. If one cap failed, there was no number.

That's why I didn't open them. To keep practicing, I built a Lab: a little pixel figure that shows what I worked on last week, with no AI, no accounts and no forms.

Below are the numbers and the seven rules I applied before writing code.

What did you decide not to build last time?

My name is Gustavo Mejía. I lead construction and engineering projects, and now I also build software with AI, as everyone will at some point. My site, gusmejia.com, has a lab, the Lab: a little figure drawn in pixels, like in a video game, that shows what I worked on last week. This piece is about how I decided what to build and what not to.

Screenshot of the Lab on gusmejia.com: the pixel figure, bearded and in a white T-shirt, works standing at a desk in the workshop. A bubble above him reads “Stamppa. Tuning the stamping app.”
The Lab replaying a Friday morning. All that comes out of the work is the app's name and a neutral phrase.

Fifteen years of leading projects across different industries left me with one rule: no scope gets executed without, at a minimum, validating that the design can handle an atypical operating load. Security isn't a layer you add at the end. You decide it before the first line of code.

With AI, the atypical load is normal use. An AI open to the public with no supervision is like letting a kid out to the park alone. Who knows what could happen. The kid means no harm. The risk is in what's out there. And maybe your project is small. Bots don't check.

What I was going to build

For the Lab I planned three AI demos open to any visitor: a short poem written by the AI and sent to your email, an AI that creates tasks in project management tools, and a figure of me that answers questions about my experience, in my voice.

Before writing code, I wrote the security model: 34 threats and 47 controls. Then I wrote and tested a few pieces. And that's where I applied my own rule: validate the atypical load before you execute.

In an open demo, the atypical load is extreme use. Every request to the AI is paid to whoever provides the service, and it connects through an "application programming interface," better known as an API: the door my page uses to talk to the model. Caps and limits lower the risk, but none of them guaranteed that extreme use wouldn't end in an account I couldn't control. Without a guaranteed ceiling, I didn't open the demos.

What I wanted was to keep practicing: build, test and publish. So the Lab changed. Today it's the pixel figure that replays my work week. No AI, no accounts, no forms. There's no AI account that can blow up.

The numbers

Here's what each case cost, in dollars a month. The demo figures come from my own plans and they're estimates. I assumed 50 visitors a day, three requests each (the most I was going to allow) and half a cent per request, a rounded average of what a poem, a task or an answer with voice cost.

What it could cost per month, in dollars

The AI demos I didn't open

  • Average operationUS$45
  • Worst case, every cap working (voice not counted)US$60
  • Worst case, each demo at its daily capUS$250
  • Worst case, if one cap failedNo ceiling

The Lab today

  • Average operationUS$0
  • Worst caseUS$0
With the caps working, the bill had a ceiling. If one failed, it didn't. The Lab today costs zero, worst case included. The demo figures are estimates from my own plans.

The AI demos I didn't open

  • Average operation: about US$45 (US$23 in requests and US$22 fixed for the voice).
  • Worst case with every cap working: up to US$60, not counting the voice.
  • Worst case with each demo at its daily cap: about US$250.
  • Worst case if one cap failed: there's no number.
  • What limited it: caps I'd write myself, plus a spending limit on the AI provider's account, which I hadn't created yet.

The Lab today

  • Average operation: US$0.
  • Worst case: US$0.
  • What limits it: the update fits inside the free tier. Reading the file has a natural ceiling, because a copy is kept near each visitor for five minutes.

Two numbers help with the worst case. A poem costs about three hundredths of a cent. A bot asking for a million poems would cost about US$300. Each request is cheap. The problem is volume nobody stops.

The demos' worst case, with everything working, was tens of dollars a month. If a cap failed, it had no ceiling. I decided on that difference.

The Lab today has a clear advantage: the cost doesn't depend on visitors. The update runs 24 times a day, 744 a month, with visits or without, and it fits inside the free tier. And the page reads a single file, which is kept as a copy near each visitor for five minutes. Even if a bot asks for it nonstop, my provider fetches it at most once every five minutes in each city. That adds up to about 2.6 million reads a month in the extreme worst case, against 10 million free. That's why the worst case is also US$0.

The seven rules, with what I did

These are the seven things I did, in order.

1. I decided what not to build

I wrote the list of what the system wouldn't do first. It came out short. The Lab takes nothing from visitors: no field to type in, no button that sends anything. The program that updates the page has no public address. It runs only when the clock tells it to: once an hour.

In the AI version, my rule was that the model proposes and the code decides. There's no model in the Lab today, but the idea held: the code decides what goes out. Each time I save a piece of my work, I write a short note. The program reads it only to pick the figure's animation (fix, test, document). That note never goes onto the page.

2. I capped spending before publishing

Every AI request was going to run inside a jar: a cap on cost, calls and time. I call it jarring it. There are no requests to jar in the Lab today, so the jar was the calendar: 24 updates a day and not one more.

Going from two updates a day to 24 was a cost question first. I asked how much it would go up, looked at the math with the worst case, and only then approved it. A monthly limit tells you after the money is gone. A per-request cap keeps it from going.

3. I showed only what I approved

I built a list of projects and approved them one by one. If a project isn't on the list, it doesn't exist for the page. And the name you see comes from that list, not from the project's internal name.

The file the page reads has, for each event, the time, the figure's work station, the type of work, how many saves and a neutral phrase. It doesn't have my notes or my working files.

  1. My work

    • A note for every saved change
    • My working files
    • Each project's internal name
  2. The list I approve

    • Only the projects I approved get through
    • Under the name I chose
    • The status line goes through a cleanup
  3. The page

    • The time
    • The figure's work station
    • The type of work and how many saves
    • A neutral phrase

Left out: my notes, my files, the internal names and the projects I didn't approve.

What goes into the Lab and what comes out. If a project isn't on the list, it doesn't exist for the page.

I did the same with the rest of the site. The construction section says: "Client, company and project names are left out on purpose." In the software section, the university app says it stays private "until the university decides to open it," and it has no public address.

4. I didn't trust what comes in or what goes out

What comes in, I wrote myself, in a hurry, in a note. I treated whatever comes from outside, my own hurry included, like something a stranger wrote.

The only thing I type by hand that shows on the page is a status line of 140 characters at most. It goes through a cleaner: no emails, addresses, folder paths, codes or names from the exclusion list. And the page shows it as plain text, never as code.

On the way out, I made the file readable only from gusmejia.com pages. The Lab page can't be opened inside another site, and it only loads from a short list of allowed sources.

5. I put a person where it matters

The person was me, and the approval point was the list: which projects, at which station, under what name. I defined it in the design, because if you define it later, it almost never gets respected.

On November 17, five projects had activity that the Lab wasn't showing. Three went in once I approved them, under the name I picked. Two are still out. New things wait until I say.

One client's project is never shown. An automated test fails if I add it to the list by mistake.

6. I logged everything and knew what happens if something fails

I made it so that if the update program fails, it deletes nothing: the page keeps the previous file. And the provider that hosts the page logs every update.

That helped on November 17, when the Lab showed an empty week that wasn't empty. The logs said 24 updates a day, all successful, and the file had 342 events. The bug was in my page: when the file didn't arrive, it said "No activity in these seven days." A sign that says something false about my work is also a failure. Now it tells a missing file from an empty week, and it tries again.

7. I attacked it before opening it

Before publishing, I tested the code only against what matters: that no banned name or internal name survives the cleaner, that every project on the list has a name and a phrase, that the update runs when I said, and that the file's format doesn't change without me noticing.

For the AI demos I'd written a plan of practice attacks: text with hidden instructions, bots, hidden links. It's saved for the day there's a guaranteed ceiling. What I don't test, someone else will, and they won't send me the report.

What this isn't

It's not a rule; it's what I did. Maybe in your project the AI does have to be open. Then the cost analysis weighs more, not less, and the seven rules apply the same. Mine doesn't change: you decide it before the code.

I don't publish the names I exclude or the exact caps. That would be handing over the blueprints.

For anyone who wants to check

The Lab page is at gusmejia.com/lab/. The file it reads is lab-data.gusmejia.com/semana.json: you can see it has no notes or internal names. In the browser's developer tools, Network tab, you can see the response headers: the page's content policy and the file's per-site permission. The demo figures come from my cost plans; the Lab's figures come from my notes on the update and from the price list the provider publishes.

If you find something that shouldn't be there, write me. I'd rather hear it from you than from a client.

The card

Four versions of the same card.

Dark and light, in English and Spanish. The dark one goes out on LinkedIn and Instagram.

  • Dark card in English: Security before code. The safest thing I did on my site was decide what not to build.
    Dark · English On social (opens the full-size card)
  • Light card in English: Security before code. The safest thing I did on my site was decide what not to build.
    Light · English (opens the full-size card)
  • Dark card in Spanish: La seguridad va antes que el código. Lo más seguro que hice en mi sitio fue decidir qué no construir.
    Dark · Spanish On social (opens the full-size card)
  • Light card in Spanish: La seguridad va antes que el código. Lo más seguro que hice en mi sitio fue decidir qué no construir.
    Light · Spanish (opens the full-size card)

All notes