t0ul

Vibe Coding Securely

Vibe Coding Securely, Ch. 1: The AI Wrote It; You Own It

Part of Vibe Coding Securely, a short, hands-on book about shipping the app an AI built without getting owned.

You can describe an app to an AI now, in plain sentences, and have it running in an afternoon. A login, a database, a little AI feature of its own. That is real, and it is a wonderful thing. I am not here to talk you out of it.

Here is the catch, and the whole reason for this book. The AI writes code it cannot vouch for. It gives you the version that works when everyone is being nice. It rarely gives you the version that holds up when one person is not, and it will not tell you which parts those are. Once the app is live, the gaps are yours. Not the AI’s, not the tool’s. Yours, with your users’ data sitting behind them.

So this book is about finding those gaps and closing them, one at a time, on a small app you run on your own machine. The method is the same every chapter, and it is not complicated:

  1. You look at one weak spot the way an AI tool tends to leave it.
  2. You run a small check that catches it, and watch it fail.
  3. You make the fix.
  4. You run the same check again, and watch it pass.

That is it. Security as something you do while you build, in small moves you can prove, instead of a thing you bolt on at the end and hope about. By the end you will have closed eight of the most common holes in an AI-built app, and, more useful, you will know how to spot the same shapes in your own.

What vibe coding gives you, and what it quietly skips

It helps to be honest about the split. An AI coding tool is genuinely good at the happy path: the button works, the note saves, the page looks right on your screen. That is most of the demo, and most of the dopamine.

What it skips is everything that only matters when someone is unkind. Four things, mostly, and they are the spine of this book:

  • Secrets. The keys and passwords your app needs, and where they end up. Chapter 2.
  • Who is allowed to do what. Logging in is easy to fake. Deciding what each person can actually touch is where it goes wrong. Chapters 3 and 4.
  • Input written to break things. A search box or a note body is not always filled in by a friend. Chapter 5. And when your app has an AI feature of its own, its input is a door too. Chapter 6.
  • The day it goes wrong. What you shipped by accident, and whether you can even see it, let alone stop it. Chapters 7 and 8.

None of these show up in the demo, because the demo is you, being nice to your own app. They show up later, when it is a stranger.

Meet Vibe Notes

We need something to break, so we will not break anything real. Meet Vibe Notes: a tiny notes app, built the way an AI tool builds one. You log in, you write notes, you read them back. That is the whole app, on purpose, so we can hold all of it in our heads and reason about it end to end.

It lives here: github.com/t0ul/vibe-coding-securely.

A word on what it is, so nobody gets the wrong idea. Vibe Notes is a teaching sandbox. It has real weak spots in it, the ones this book fixes, planted the way a real tool actually produces them. You run it on your own machine, you learn on it, and you do not deploy it anywhere. It is the same idea as OWASP’s Juice Shop, scaled down to one short book and one small app.

And if you would rather not touch GitHub at all, that is fine. Every weak spot, and every fix, is written out in these chapters. The repository is here so you can follow along in real code and compare your work to mine, not because you need it to learn the idea.

Setting up, from a bare machine

I will assume you have nothing installed. We need two tools, Node and git, then the app itself. If you already did Git and GitHub the Safe Way, you have git and a GitHub account already, and you can skip straight to cloning.

Node

Node is the thing that runs JavaScript outside of a browser. Vibe Notes is built with it, so you need it to run the app.

  • macOS or Windows: go to nodejs.org, download the “LTS” installer, and run it. Click through the defaults.
  • Linux: the version in your package manager is often old. The simplest reliable path is nodejs.org too, or nvm if you know it.

You want a current, supported version, which is exactly what the “LTS” button gives you. At the time of writing that is Node 24. Check it by opening a terminal and running:

node --version
v24.22.1

The supported lines (Node 22 and Node 24, the long-term ones, and the newest release) are all fine. What you do not want is an end-of-life line such as Node 20 or Node 23: those stop getting security fixes even when a serious one lands, which is not academic, a remote-code-execution bug in Node landed in October 2026 and the old lines will never be patched for it. So install fresh from the “LTS” button rather than using whatever Node happens to be on the machine already. If you get “command not found,” the install did not finish or your terminal needs to be closed and reopened, so it picks up the new tool.

git

git is how you get a copy of the code and, later, see exactly what each fix changed.

  • macOS: run git --version once. If git is missing, macOS offers to install it for you. Say yes.
  • Windows: download it from git-scm.com and run the installer.
  • Linux: sudo apt install git on Debian or Ubuntu, or your distribution’s equivalent.

Check it:

git --version
git version 2.45.2

Get the app, and run it

Now bring the code down and start it. In your terminal:

git clone https://github.com/t0ul/vibe-coding-securely
cd vibe-coding-securely
npm install
npm run dev

git clone copies the repository to a new folder. cd steps into it. npm install reads the project’s list of dependencies and downloads them (npm is Node’s package manager, it came with Node). npm run dev starts the app.

When it is ready you will see a line pointing at a local address:

  ▲ Next.js
  - Local:   http://localhost:3000

Open http://localhost:3000 in your browser. You will see Vibe Notes, asking you to log in. There are two accounts baked in for practice, alice and bob. Click “Log in as alice,” then add a note. Read it back. That is the app, running on your machine, out of nobody’s reach but yours.

Leave that terminal running; it is your app. When you want to stop it, press Ctrl-C in that window.

If it does not start

Two things trip people up here, and both are quick to clear.

If npm install prints errors that mention your Node version, you are on an older Node than Vibe Notes needs. Run node --version again, and if it is an old or end-of-life line, install the current LTS from nodejs.org and run npm install again.

If npm run dev complains that port 3000 is already in use, some other program is sitting on that address. Either stop that other program, or run Vibe Notes somewhere else with npm run dev -- -p 3001, and open http://localhost:3001 instead. Nothing in the book depends on the exact number.

The loop you will use in every chapter

This is the part to slow down on, because every chapter after this one leans on it.

Each weak spot in Vibe Notes has two bookmarks in git, called tags:

  • chN-start: the app with that chapter’s weak spot wide open.
  • chN-done: the same app with the fix in place.

And each chapter ships a small check you run yourself. A check is a short script that pokes the running app and reports what it found. It is written to fail while the weak spot is open, and pass once you have closed it. Think of it as a test that is red until you fix the thing, the same way a failing test nags you until the code is right.

Let me show you the loop once, with chapter 2’s, so the shape is familiar before we get there. Open a second terminal (leave the app running in the first), step into the project, and jump to where chapter 2 begins:

git checkout ch2-start
npm run check:ch2

git checkout ch2-start rewinds the code to that bookmark, the version with the weak spot open. Then the check runs, and this is what it says:

Building, then scanning the browser bundle for a secret...

FOUND: the sync key is in 1 browser file(s), e.g.
  .next/static/chunks/3phdisnd8n76k.js
Anyone who opens the site can read it in DevTools. See chapter 2.

That red “FOUND” is the point, not a problem with your setup. The check just caught a real weakness in the app, the way a test catches a bug: a secret key that was supposed to stay on the server has ended up in the JavaScript every visitor downloads. In chapter 2 we move it where it belongs and run this exact command again, and it goes quiet.

For now, put the app back to its finished state:

git checkout main

main is the app with every fix already in place, so you can always get back to a whole, working version. When you start a chapter, you will check out its start tag, do the work, and prove it with the check. When you are lost or just want to read ahead, git checkout main is home.

One thing you do not need yet: Vibe Notes has an AI feature of its own, which we attack in chapter 6. It runs a model on your own machine, with a tool called Ollama, and no account or key anywhere. Setting that up waits until chapter 6, so it is there when you need it and not a hurdle before then. Everything up to that point runs on Node alone.

How to read this book

In order, and at a keyboard. Each chapter is short, does one thing, and builds on the one before it, so chapter 4 assumes you met the login from chapter 3. Run the checks yourself as you go. Reading that a check turned red is not the same as watching it turn red on your own screen, and the watching is the part that sticks. If you ever feel lost, git checkout main puts the finished app back in front of you, and you can read ahead from there.

There is no rush, and you do not need to be a security person to follow any of it. The whole app is small enough to understand completely, and that is deliberate: you cannot protect what you cannot hold in your head. We keep it small so you can.

Where this leaves us

You have the app running, you have met the two practice accounts, and you have seen the loop: a bookmark for the weak spot, a check that catches it, the fix, the check again. That loop is the whole method. Everything from here is us walking it, one real weakness at a time.

The first one is the most common, and the easiest to do by accident. Your app needs a secret, a key to some service, and the tool helpfully wires it up for you. The trouble is where it puts it. That is the next chapter.

← Vibe Coding Securely