What a breach actually looks like
Most don't look like the movies.
The last breach we helped clean up wasn't a state actor. It was a .env file that briefly got committed during a rebase. The PR was reverted in eleven minutes. By the time the team realized what had happened, a scraper had already pulled the file, hit a Stripe key, and started running test charges from a server in Lithuania. The whole window was about two hours. The cleanup took a week.
What made it expensive wasn't the sophistication of the attack. It was that nobody had thought about what was protecting the keys, what would notice if they got out, or who would be paged when the charges started flowing. Those aren't launch day questions. They are commit one questions.
Security is a build time decision. Eight habits, applied early, decide whether your bad day costs a Slack message or a lawyer.
Start with a threat model
You can't defend what you haven't named. A threat model is a one page document that answers three questions: what are you protecting, who would want it, and what happens if they get it. The output is rarely longer than the menu at a small restaurant.
When teams skip this, every later security decision becomes a guess. We've watched a team spend two weeks debating WAF rules for an internal admin tool that, on inspection, didn't store anything more sensitive than a list of the company's office plants. We've also watched a team treat a customer health records app like a public marketing site because nobody had named the data.
We do this in the kickoff meeting, before any code. One whiteboard. Three columns: assets, adversaries, impact. Every later decision (where to put auth, what to log, what to encrypt) gets to point back to it. If a control doesn't map to something in those three columns, we don't build it.
Validate on the server
The browser is a hostile environment. Anything your form does, an attacker can skip with five minutes of curl. Client validation exists for user experience: it stops a typo from reaching the server. Server validation is what stops the typo from being a SQL injection.
The failure mode is almost always the same story. Team adds Zod on the React form, sees the red error message work, ships. A month later someone notices that a "phone number" field has been accepting essays, or a subject field accepts raw HTML, lands in an admin dashboard, and fires a script the moment a ticket is opened.
Every server endpoint we ship validates its own input independently of any client. On TanStack projects we use the inputValidator block on every server function. On Express or similar, a Zod schema at the route handler. The rule is simple: if data didn't pass the validator, it doesn't reach the handler. The client check is a courtesy. The server check is the contract.
Authorize every endpoint
Hiding a button does not stop a logged in user from hitting the API directly. If the only thing protecting your admin route is that regular users don't see the button, you don't have access control. You have UI conventions.
The classic failure is the IDOR (insecure direct object reference). /api/orders/123 returns order 123 to anyone who's logged in, not just the customer who owns it. We've seen this exact bug in a SaaS admin tool where one tenant could read another tenant's invoices by changing the URL. The fix took two hours. The trust damage took longer.
Every route handler we write runs a permission check against the session, not against the URL. "Is this user allowed to read this specific resource?" gets answered before the data is loaded, not after the response is built. We test this with two accounts during QA, one admin and one regular user, and deliberately try to access each other's data. If something works that shouldn't, we have a bug, not a feature.
Keep secrets out of your code
Once a key is in git history, it's there forever. Force pushes don't help; if the commit was ever pushed, somebody (often a scraper) has already cloned it. Once a key is in a mobile binary, it's there for anyone with strings and ten seconds of curiosity.
The most common version of this is the .env file that "just for now" gets committed during setup, then the team moves on. Six months later it surfaces in a public fork or a leaked backup. The second most common is a hardcoded API key inside a React Native app: developer thought the binary would protect it, attacker ran the IPA through a simple text search and had the key in seconds.
We use secret managers from day one. Cloudflare Secrets for Workers, environment injection at deploy time, no committed .env files in any repo. GitHub secret scanning runs on every project, with hooks that run on each commit and catch the obvious ones (Stripe keys, OpenAI keys, AWS access keys). For mobile, every secret comes from a server call after authentication, never from the bundle.
HTTPS everywhere with HSTS
HTTPS without HSTS is a half measure. The first request to your site, before the browser has cached your cert, can still be intercepted on a hostile network. HSTS tells the browser "never connect to me without TLS again," which closes that window.
What we see go wrong is environments drifting apart. Production is HTTPS. Staging is on a vanity URL that someone forgot to terminate TLS for, but it shares a session cookie scheme with prod. A developer logs into staging from a coffee shop. That session token is now on the wire. Game over for the account, possibly more.
We set HSTS on every host that serves anything authenticated, with max-age of at least a year and includeSubDomains where the subdomain inventory supports it. Production domains go on the HSTS preload list so the protection kicks in on first visit. For mobile apps that handle financial or health data, we pin the certificate, which costs a small amount of engineering for a meaningful raise in attacker effort.
Patch your dependencies
The boring truth about most public breaches is that the vulnerability was already published, often for months. Log4shell sat in the wild for nine years before someone found it. The fix existed within hours of disclosure. Breaches kept happening for weeks because nobody had updated.
The failure mode is the package.json that hasn't been touched in two years. Dependabot opens a PR, nobody reviews it, the PR rots. Six months in there are forty open PRs and the team mentally treats them as noise. By the time a real CVE drops, the merge cost is so high that everyone hesitates, and the window between disclosure and patch becomes the window of compromise.
We turn on Dependabot from day one, set to auto merge minor and patch updates after CI passes. Major version bumps go on a weekly review queue. We watch GitHub's security advisories; when something high severity drops in a library we use, the patch gets prioritized over feature work that day. Boring discipline, large risk reduction.
Log enough to actually investigate
You can't respond to an incident you can't reconstruct. The day after a breach, the question you'll be asked (often by a lawyer) is "what data was accessed and by whom." If your answer is "we don't know," the cost has just multiplied.
The failure mode is logs that exist but don't say enough. Request method and path got captured; user ID didn't. Login attempts got logged; password reset attempts didn't. Logs went to stdout, but stdout in the production container only persisted the last hour. We've watched a team spend three days trying to identify which users were affected because the only timestamp they had was minute resolution.
We log structured events with timestamp, request ID, authenticated user ID, action, and outcome at a minimum. Application errors flow to Sentry. Cloudflare logs persist to object storage with at least 90 days of retention on any path that touches user data. The cost is a few cents a month. The value is being able to answer questions when you have to.
Write the incident response plan now
You don't want to be drafting an incident response plan while the incident is in progress. The hour after you confirm a breach is not when anyone is going to write good customer copy or remember whose AWS root credentials are with whose lawyer.
The failure mode here is almost funny in retrospect. Something happens. The on call developer pages the founder. The founder texts the CTO who's on a flight. Half the team didn't know they were emergency contacts. Nobody knows whether to email customers, or what to say. Then the regulator asks "when did you first become aware," and the honest answer is "around three this morning, give or take."
Every project we ship has a one page incident plan committed to the repo. Names, phone numbers, the order people get called. Decision tree for the first hour: contain, assess, notify. Approved customer comms templates that say "we don't know everything yet, here's what we do know" instead of waiting for full information. The plan rarely changes after launch. It just needs to exist before it's needed.
What this is really about
None of these eight habits are clever. None require a security team. They require an hour at kickoff, a few config files, and a willingness to do the boring thing on the day the boring thing matters.
The cost of designing security in at the start of a project is small. We measure it in hours, not weeks. The cost of bolting it on after an incident is something else entirely: customer comms, lawyer fees, regulator filings, the credit you don't get back, and the founder hours that disappear into rebuilding trust instead of building product.
If you're starting a new build and want a sanity check on your approach, or you've shipped something and want a second set of eyes before it gets bigger, we're happy to spend half an hour on a call. No pitch deck, no commitment. Bring questions, leave with a list.



