Fix: Cursor × security

Cursor writes code you review.
Until the day you stop reviewing.

You're technical — you read the diffs. But agent output compounds faster than review discipline holds. In April 2026, a Cursor agent at PocketOS hit a credential mismatch, went hunting through the codebase, found a Railway token in an unrelated file, and deleted the production database in under ten seconds (thenewstack.io). The answer isn't reviewing harder. It's a codebase where dangerous edits fail loudly, mechanically, before they merge.

Agent drift is an architecture problem, not a diligence problem

When an agent builds from a blank repo, it averages the public code it trained on — and the average includes the bugs. Security reviews of AI-generated apps keep finding the same three regressions again and again: sessions that keep working after a password change, payment webhook handlers that aren't idempotent, and per-tenant data checks that exist in some queries but not all. There's a subtler failure mode for Cursor specifically: the agent pulls whatever files it needs into context, so a prompt about billing routinely ends with edits to auth middleware — it touched what it read. Left unchecked, the project's shape drifts toward the AI's defaults — choices that look reasonable in isolation, stacked into something no one would have designed. Each diff looked fine. The sum is a security posture nobody chose.

How agent edits erode a security posture

Middleware reordered to fix a symptom

The agent moves auth after a body parser to fix a parsing bug, and a route goes momentarily unprotected. The change is two lines. The test that would catch it doesn't exist unless someone wrote it.

Stale training examples in fresh code

Generated Stripe integrations follow years-old public examples — handlers without idempotency, webhooks without signature verification. Provider retries then double-process real money.

A widened query to make a test green

The fastest way past a failing test is often removing a filter. When that filter was the org scope, the test passes and cross-tenant reads open — the diff reads as a simplification.

Types silenced instead of satisfied

An 'as any' to quiet the compiler removes exactly the check that would have flagged a payload mismatch — the 400-in-production kind that typechecks fine.

Auth edited as a side effect

Cursor edits what's in context. Sessions, guards, and middleware get pulled in constantly because everything imports them — so unrelated tasks quietly reshape your most sensitive code.

The wall: boundaries enforced by lint, not memory

useDeploy's DDD layering is enforced by ESLint: domain code cannot import Express, Prisma, or anything from the infrastructure layers, and the rule runs in pre-commit and CI. When an agent takes a shortcut across a boundary — reaching for the database from domain logic, bypassing the repository layer that carries the tenant guard — the commit fails with a named rule. The boundary doesn't depend on what was in the context window.

pre-commit — the boundary says no
 1  $ git commit -m "fix: billing edge case"
 2  eslint: apps/server/src/modules/billing/domain/subscription.ts
 3    error  '@prisma/client' import not allowed in domain/
 4           (boundaries/element-types)
 5  husky — pre-commit hook exited with code 1
 6  
 7  # the agent reached for the database from the domain layer,
 8  # skipping the org-scoped repository. mechanically rejected.

What the base makes structurally true

Tenant scope the agent can't refactor away

Data access goes through org-scoped repositories backed by a Prisma query guard; cross-org requests return 404. Dropping the scope means changing guarded plumbing that tests assert on — not deleting one WHERE clause.

Webhooks that already learned the lesson

Billing webhooks are idempotent by externalOrderId over a durable outbox. The stale-Stripe-example failure mode has nothing to regress to.

Sessions as server-side state

Sessions live in Postgres and are revocable; ending concurrent sessions on a credential change is a documented flag, not a rewrite an agent has to get right from scratch.

Contracts that catch invented fields

Client types are generated from the server's OpenAPI schema, and CI fails when they drift. An agent that changes a payload on one side without the other gets a red build, not a runtime 400.

A gate with teeth

450+ automated tests and a Playwright E2E suite run in CI on every merge — including assertions on the cross-org 404 and auth flows. 'Looks plausible' doesn't ship.

Throttles and signatures at the edges

Rate limiting by tier (IP + email on auth), HMAC-signed outgoing webhooks, and secrets confined to a Zod-validated env schema — the perimeter is code, not convention.

Migration path: point the agent at the base

This one plays to your strengths — you migrate with the same agent that got you here. Clone the base, open it in Cursor, and move your app module by module: each bounded context on the base has the same shape (domain, application, infrastructure, interfaces), so 'port the invoicing feature into a new module following the existing ones' is a prompt Cursor executes well — the repo's own structure is its best few-shot example. The in-repo rules file gives the agent the project's conventions from the first prompt, the ESLint boundaries reject its shortcuts, and the OpenAPI contract keeps client and server honest while both are in motion. Start with your most sensitive module — the one where a drifted query hurts most — and let the guardrails carry the rest.

Cursor × security, asked directly

Won't lint-enforced boundaries slow the agent down?+
They redirect it. Agents thrive on fast, unambiguous feedback — a named lint error is a better signal than a vague review comment three days later. In practice the agent learns the layering from the error messages and the existing modules, and stops proposing violations.
I already have a codebase. Is this a full rewrite?+
No — it's a module-by-module migration. Each feature moves into its own bounded context on the base while the rest keeps running. Auth, billing, tenancy, and jobs are already built, so what you port is product logic, not plumbing.
Does this replace code review?+
It makes review tractable. Machines catch the mechanical classes — boundary violations, contract drift, regression of tested behavior — so human review spends its budget on intent and design, which is the part machines are worst at.
What about the vulnerabilities in Cursor itself?+
Real, but a different layer: editor CVEs are about your machine and are patched by updating Cursor. This page is about your application — the code the agent writes and ships. A hardened base protects your users regardless of which editor version wrote the diff.

One license. Two ways to own it.

CORE

Founder

$99one-time

A frozen snapshot of UseDeploy. Yours forever, no updates.

  • Frozen-version zip download
  • Full source, commercial use, unlimited projects
  • All 800+ tests · all docs pages
  • 14-day refund
RECOMMENDED

LATEST + UPDATES

Lifetime

$199$249one-time

Always the latest UseDeploy. Re-download every release, free.

  • Latest-version zip — re-downloadable forever
  • Every future release at no extra charge
  • Priority Discord support
  • All 800+ tests · all docs pages
  • 14-day refund

Keep the speed. Add the walls.

A DDD base with lint-enforced boundaries, typed contracts, and a 450+ test CI gate — built so an agent can move fast without moving your security.