Skip to the lesson
CivOps AI Academy · F02BProve It Is Secure: the Security Test Suite for the OWASP Top 10
0%

Chapter 1 · Session 18

Map the risks, then prove access control first

Your platform already has access rules, sign-in that denies by default and quality checks. None of that is proof. This chapter maps each OWASP Top 10 risk to what protects against it today, then has Claude Code write the tests for the biggest one, broken access control, and the check that runs them on every pull request.

40 min2 stepsRuns on a throwaway database in CINo keys needed

By the end of this chapter you can

  • Say the difference between a protection and a proof, and why the proof comes after the system is built.
  • Have Claude Code map the OWASP Top 10:2025 to this platform in docs/owasp.md, marking what is unproven.
  • Get tests for default deny in both directions, cross-site reads and changing the number in the address, running on every pull request.

A protection is not a proof

Sessions 8 and 9 built the locks: row-level security on every table and a sign-in gate that refuses every address the matrix does not open. This session proves the locks hold, today and after every change an agent makes. The difference matters. In a prior build we found 376 of 449 route handlers answering with no sign-in check; one returned a real customer's staff list to anyone, for up to 87 days. Every one of those routes had been written by someone who meant to protect it.

The proof is a suite of tests that tries each door the way an attacker would, and must be refused. It is mapped to the OWASP Top 10, the list of web application risks that IT departments and auditors already recognise [1], so when IT asks "is it secure?", the answer is a page of risks, each with its tests and today's result.

The OWASP Top 10:2025 as testsTen boxes, one per OWASP Top 10:2025 category, each with a test the platform can run on every change. A01 Broken access controldefault deny, cross-site, changed idA02 Misconfigurationdemo switch dead in production, headersA03 Supply chainlockfile, npm audit, DependabotA04 Cryptographic failuresHTTPS only, no secret in bundleA05 Injectionquotes in input stay textA06 Insecure designthe safety rule has a testA07 Authentication failuressign-up closed, old sessions refusedA08 Integrity failuresprotected main, CI must passA09 Logging and alertingevery request: who, what, resultA10 Exceptional conditionserrors show no internals
The OWASP Top 10:2025, one or more tests each. A01, broken access control, is first in the list and first in your suite.

The ten risks on this platform

RiskOn the stamping plantWhat protects it (session)What the suite proves
A01 Broken access controlA supervisor at cle opens another site's lot by changing the number in the addressRow-level security (8), the sign-in gate (9)Refused both ways, cross-site and by id, through the app and straight to the database
A02 Security misconfigurationA demo switch left on makes every visitor an administratorSettings, the start-up key check (10)Demo switches cannot work in production; headers set; every table's security forced
A03 Software supply chain failuresAn agent adds a package with a known flawThe lockfile, CI (3)npm audit and Dependabot, every pull request and every week
A04 Cryptographic failuresThe service role key ends up in the browser's codeServer-only keys (1)No secret in anything the browser downloads; HTTPS only
A05 InjectionA hold reason with a quote in it changes a querySupabase's client sends values separately from the queryHostile text is stored and shown as text; filters cannot be widened
A06 Insecure designThe system releases a hold by itselfThe intent's "never by itself" rule (2)That rule has its own test
A07 Authentication failuresA session still works after sign-outSupabase Auth, invitation only (1, 9)Sign-up refused; expired and signed-out sessions refused
A08 Software or data integrity failuresA change reaches main without review; a record is editedProtected main (1, 10), append-only tables (5)Already proven by Sessions 5 and 10; listed in the map
A09 Security logging and alerting failuresData was exposed and nobody can say who saw itNothing yetEvery request leaves a line saying who, what, when and the result, with no secrets in it
A10 Mishandling of exceptional conditionsAn error page shows the SQL, or an error lets the request throughNext.js error pagesA forced error shows a plain message and still refuses

Category names as published in the OWASP Top 10:2025 [1]. When IT wants more detail than ten categories, OWASP's Application Security Verification Standard is the full checklist [2].

Step 1

Map every risk to what protects it, before writing a test

15 minutes

Why

Asking straight away for "security tests" gets a pile of plausible tests that skip whatever the agent did not think of. A map first, risk by risk, names what protects each one today and what proves it, so the gaps are written down where you and IT can see them. It also catches the worst kind of gap: a protection everyone assumes works and nobody has ever tested.

Do this

Paste into Claude Code
Read docs/INTENT.md, docs/matrix.json, docs/access-review.md, docs/clamps.md and docs/runbook.md. Then look through proxy.ts, lib/access/routes.ts, supabase/migrations/, supabase/tests/, the test folders and .github/workflows/. Do not change any code.

On a new branch security/owasp-map, write docs/owasp.md: how each risk in the OWASP Top 10:2025 applies to this platform, for someone who does not write code. One section per risk, A01 to A10, each with:
- what it would look like here, with an example from our plant (a lot, a hold, an inspection, a press);
- what protects against it today, naming the file (or "nothing yet");
- the test that proves the protection works today, naming the file and the test (or "no test yet");
- the test still to write, as one sentence: "given ..., when ..., then ...".

Rules:
- A protection with no test is "unproven", not "covered". A test that only checks that a word appears in a file is not proof.
- If you cannot tell whether something is protected, write "could not tell" and why. Do not guess.
- List every file that uses the Supabase service role key (it skips every access rule), what each one does, and how it limits itself to the user's site.
- End with a summary table: risk, protection, test today, test to write.

Open a pull request titled "OWASP map" and show me the link.

You will see recreated screen

claude — acme-platform
⏺ Read(docs/matrix.json)
⎿ Read 64 lines
⏺ Grep("SUPABASE_SERVICE_ROLE_KEY")
⎿ Found 2 files
1
⏺ Write(docs/owasp.md)
+## A01 Broken access control
+Here: a supervisor at cle opens /lots/9071, a lot from another site.
+Protects today: row-level security on all 8 tables; proxy.ts refuses every route not in lib/access/routes.ts.
+Proven today: supabase/tests/access.test.sql (one allowed and one refused test per matrix cell).
+Unproven: nothing changes the number in /lots/[id] through the app; nothing checks lib/supabase/admin.ts filters by site.
2
⏺ Pull request #41 adds docs/owasp.md. 3 risks are proven by tests today, 6 are protected but unproven, and 1 I could not tell: A09, because I cannot see whether request logs are kept anywhere. Two files use the service role key: the invitation route and the nightly export. The export does not filter by site.3
Claude Code reads the documents and the code, then writes the map. The findings in the summary are the stamping plant's; yours will differ.
  1. It looks for the service role key first. Any file using it skips every access rule, so each one must filter by itself.
  2. Each risk: what it looks like here, what protects it, what proves it, and what is unproven.
  3. The honest counts are the point. "Could not tell" is a finding, not a failure.

Check it worked

Pull request OWASP map adds one file, docs/owasp.md, with ten sections, a list of files that use the service role key, and a summary table where every risk is either proven by a named test or marked unproven.

Fastest path

Read the summary table first, then only the sections marked unproven or could not tell. Those are the work for the rest of this session. Merge the map now; later steps update it as tests arrive.

If it goes wrong

The map says every risk is covered

Ask for the evidence: For each risk you marked covered, name the test file and the test, and tell me what that test does when the protection is removed. If a test only checks that a word appears in a file, mark the risk unproven. We had three tests in one night's work that only checked a word was present, and passed while the feature was broken.

It calls a group of findings "false positives"

Never accept that for a group. Say: For EACH one separately, show me the request you would make with no sign-in and what comes back. Anything that returns data or accepts a change is a real finding. We once had a group of warnings dismissed this way; the routes behind them were open on the live site and returned 23 named customer staff to anyone.

A file uses the service role key and does not filter by site

Write it down as an A01 finding in the map, and fix it in Step 2: the test will prove it. The service role key skips row-level security entirely, so that file is only as safe as the filter written in it.

Broken access control first: four doors

Access control fails in four ways on this stack, and the suite tries each one. Each test runs both ways, because a suite that only checks refusals passes on a site that refuses everyone, including the quality lead at the press [3].

DoorThe test triesMust see
Default deny, both waysEvery address in lib/access/routes.ts signed out, with a forged cookie, and as each role; addresses ending in .pdf or .md; a route nobody listedRefused where the matrix says no, allowed where it says yes, public pages still open, an unlisted route fails the build
Default deny in the databaseEvery table with only the public key, and signed in with no membershipNo rows at all
Cross-siteEach cle role reads, changes and deletes one row of a second, made-up site in every tableNo rows, nothing changed (checked in the database afterwards), nothing deleted
Changing the number in the addressA cle supervisor asks for /lots/<id of the other site's lot>, and every other address with an id in itNot found or not allowed, never the record [4]
The path of a requestA phone browser sends the publishable key and the user's token to the Supabase API, which passes the user to Postgres, where row-level security returns only that user's rows. Server code with the secret key bypasses row-level security and must stay on the server. Phone browserpublishable key+ user's sign-in tokenSupabase APIchecks the token,passes the user onPostgresrow-level securityruns on every queryfor this userRowsonly theirsYour server codesecret key, server onlyThe secret key skips row-level security.It never reaches a browser, a chat or a file.
Why the service role key gets its own test. Requests with the user's sign-in meet row-level security. Server code using the service role key skips it, so every file that uses it must filter by site itself, and the suite fails if a new one appears.
Step 2

Broken access control: the first tests, and the check that runs them

25 minutes

Why

Broken access control is first in the OWASP list and was our worst failure: any signed-in user could open another company's record by changing the number in the address. The tests run on a fresh, throwaway Supabase database inside GitHub Actions, with made-up data and made-up users, so they need no keys, touch neither live project, and run on every pull request. One complete prompt gives the setup, the tests and the workflow together, so the proof arrives with its referee.

Do this

Paste into Claude Code
Read docs/owasp.md, docs/matrix.json and lib/access/routes.ts. Reuse the helpers Session 9's route tests use to sign in as each role; do not copy them.

On a new branch security/access-tests, build the first part of the security suite: A01, broken access control.

1. tests/security/setup.mjs prepares the CI database only (the local Supabase that GitHub Actions starts, never acme-platform-prod or acme-platform-dev):
   - one made-up test user per role in docs/matrix.json at site cle, and one signed-in user with no membership at all;
   - a second, made-up site with code probe, with its own lots, inspections and holds, lot codes starting L-9 and part numbers starting PROBE-, and a supervisor there.
   It may use the local stack's own service role key, which only works on that throwaway database.

2. tests/security.test.mjs, run with Node's built-in test runner (node --test). Keep it out of npm test: add it to Vitest's exclude list, and add an npm script test:security. Name every test with its OWASP number. Tests:
   - Default deny, both ways: every route in lib/access/routes.ts, signed out and with a forged cookie, is refused (the sign-in page for pages, 401 for /api/), including /api/ addresses ending in .pdf and .md. Each role reaches exactly the routes the matrix gives it, and the public pages still open. Every page and route file in app/ must be listed in lib/access/routes.ts, so a route nobody listed fails.
   - Database default deny: with only the public (anon) key, every table returns no rows; signed in with no membership, every table returns no rows.
   - Cross-site: signed in as each cle role, try to read, update and delete one probe-site row in every table, through the database API and through the app's routes. Expect no rows, then check in the database that nothing changed and nothing was deleted. No answer to a cle user may contain PROBE- or a probe lot code.
   - Changing the number in the address: for every route with an id in its address, ask for a probe-site record's id as a cle supervisor. Expect not found or not allowed, never the record.
   - Service role key: fail if a file uses SUPABASE_SERVICE_ROLE_KEY that is not on the list in docs/owasp.md, and test that each listed file only returns the user's own site.
   - Every test first checks that the data it relies on exists (the probe rows are there), so it cannot pass on an empty database.

3. .github/workflows/security.yml, on every pull request and on push to main, with a job named security: start Supabase with the Supabase CLI (migrations and seed), run tests/security/setup.mjs, build the app and start it against that local database, run npm run test:security, and keep the app's log as a downloadable artifact. Do not pipe test commands into anything, so the job fails when a test fails.

4. Do not connect to acme-platform-prod or acme-platform-dev and do not use any secret.

Update docs/owasp.md with the tests that now exist. Push, open a pull request titled "Security suite: access control", wait for the security check to finish, and tell me in plain words how many tests ran, how many tried a door that must stay shut and how many checked a door that must open. If a test fails because the platform really is open, do not change the test: stop and tell me what is open.

You will see recreated screen

claude — acme-platform
⏺ Write(tests/security.test.mjs)
+test("A01 cross-site: a cle supervisor cannot read probe-site holds", async () => {
+ assert.ok(await count("holds", { site: "probe" }) > 0, "probe holds exist");
+ const rows = await asRole("supervisor").from("holds").select().eq("site_id", PROBE);
+ assert.deepEqual(rows.data, []);
+});
1
⏺ Write(.github/workflows/security.yml)
+ - run: supabase start
+ - run: node tests/security/setup.mjs
+ - run: npm run build && (npm start > app.log 2>&1 &)
+ - run: npm run test:security
2
⏺ Bash(gh pr checks --watch)
⎿ security pass 6m12s schema pass 1m48s
⏺ Pull request #42 is green. 214 tests ran: 168 tried a door that must stay shut (signed out, forged cookie, wrong role, probe site, changed id) and were refused; 46 checked that each role still reaches what the matrix gives it. One finding fixed on the way: the nightly export used the service role key without a site filter. It now filters, and a test proves it.3
Claude Code writes the setup, the tests and the workflow, then waits for GitHub's verdict before reporting.
  1. Before testing a refusal, the test proves the probe rows exist. Without that line, it would also pass on an empty database.
  2. The whole platform, built and started inside GitHub Actions against a throwaway database. No key from either live project.
  3. Both directions counted. A suite with only refusals would pass on a site that refuses everyone.

You will see recreated screen

github.com/acme-ops/acme-platform/actions/runs/8812
Summarysecurityschema
▶ A01 default deny
  ✔ /holds signed out → /sign-in
  ✔ /api/lots/9071.pdf signed out → 401
  ✔ forged cookie on /review → /sign-in
▶ A01 cross-site
  ✔ supervisor@cle reads probe holds → 0 rows
  ✔ supervisor@cle updates probe lot → 0 rows, unchanged in database
▶ A01 changed id
  ✔ /lots/90412 (probe) as supervisor@cle → 404
ℹ tests 214  pass 214  fail 0
The security check's log on GitHub. Each line is one door tried.
  1. We trust this check on GitHub, never the summary in the chat.

Check it worked

Pull request Security suite: access control is green on GitHub, with a security check whose log shows A01 tests for default deny, cross-site and changed ids, and docs/owasp.md names them.

Fastest path

"Wait for the security check and stop if the platform really is open" saves two round trips: Claude Code reads the failure while you do something else, and it cannot quietly weaken a test to get green.

If it goes wrong

The workflow fails with: relation "auth.users" does not exist

It started a plain Postgres, which has no Supabase sign-in tables. Say: Start the database in CI with the Supabase CLI (supabase start), as schema.yml does, not a plain postgres service.

A cross-site test fails: a cle user can read probe rows

That is a real hole, and exactly what the suite is for. Do not change the test. Say: The cross-site test shows cle users can read probe rows in <table>. Show me the policy that allows it, write a new migration that fixes it (never edit an applied one), and keep the test. Merge the fix through the normal path; the deploy workflow applies it.

The new tests pass, but nothing seems to have been checked

A test that can never fail is worse than none: it looks like proof. On our platform a probe reported "present" 350 times and "absent" 0 times, because the live site answered 200 for every address. Step 4 removes protections on purpose to show each test going red.

Claude Code says it changed a test so it passes

Say: Undo the change to the test. Never edit, skip or loosen a test to get green. If you think the test is wrong, stop and explain why, and I will decide. Then read the list of changed files on the pull request before the summary.

The check named in a failure is not the file you changed, for example a route list

Some checks compare a generated list with the code. Say: Open the failed check's log, tell me which file it compares against, regenerate it if it is generated, and show me what changed. If the list shows a new unprotected route, stop and tell me.

Knowledge check

A supervisor at one site changes the lot number in the address and sees another site's lot. Which OWASP category is this?

Knowledge check

Why does every access test also check that allowed requests still work?

Knowledge check

Where do the security tests sign in and read data?

References

  1. OWASP Top 10:2025. https://owasp.org/Top10/2025/
  2. OWASP Application Security Verification Standard (ASVS). https://owasp.org/www-project-application-security-verification-standard/
  3. OWASP Cheat Sheet Series: Authorization. https://cheatsheetseries.owasp.org/cheatsheets/Authorization_Cheat_Sheet.html
  4. OWASP Cheat Sheet Series: Insecure Direct Object Reference Prevention. https://cheatsheetseries.owasp.org/cheatsheets/Insecure_Direct_Object_Reference_Prevention_Cheat_Sheet.html
  5. Supabase Docs: Row Level Security. https://supabase.com/docs/guides/database/postgres/row-level-security
  6. Supabase Docs: Local development with the Supabase CLI. https://supabase.com/docs/guides/local-development

Chapter 2 · Session 18

The rest of the Top 10, and show it red first

One prompt adds tests for injection, sign-in failures, misconfiguration, secrets, errors and logging, and fixes whatever they find. Then you prove the suite can fail: on a throwaway branch, Claude Code removes four protections on purpose, and each one must turn a test red.

40 min2 stepsOne branch is never merged

By the end of this chapter you can

  • Have Claude Code add tests for A02, A04, A05, A07, A09 and A10, including the demo switch and secrets in the browser.
  • Make sure the platform keeps a record that can answer "who saw what".
  • Show each kind of test failing with its protection removed, on a throwaway branch, never on a live project.

What the other tests try

RiskThe test triesMust see
A05 InjectionA hold reason of '; drop table holds; -- and a lot note of <script>alert(1)</script>; a filter value with a comma in itStored and shown as plain text, the table still there, no script run, the filter not widened [1]
A07 Authentication failuresSigning up as a stranger; a session after sign-out; an expired sessionAll refused
A02 MisconfigurationThe demo switch on, with the app told it is productionStill refused: a signed-out visitor lands on the sign-in page
A04 Secrets in the browserEvery file the browser downloads, searched for the service role keyNot there. The repository's whole history holds no key either
A10 ErrorsA lot address with a malformed idA plain message, no stack trace or SQL, and still refused
A09 LoggingOne refused and one allowed requestEach leaves one line: when, which user, role, site, address, result. No token, cookie, key or email in it [2]
Step 3

The rest of the Top 10, in one prompt

20 minutes

Why

Each remaining risk needs a different kind of test, and several need a small change to the app to pass: the demo switch read in one place, the request log line, the plain error page. One complete prompt gives Claude Code all of them with the rule that a real problem is fixed with its test in the same pull request. That replaces ten rounds of "now add a test for...", and it touches proxy.ts, so the prompt starts with this Next.js version's own guide.

Do this

Paste into Claude Code
Read docs/owasp.md and tests/security.test.mjs. Before changing proxy.ts or any route, read the guide for this version of Next.js in node_modules/next/dist/docs/ (in Next.js 16 the request middleware file is proxy.ts).

On a new branch security/rest-of-top-10, add these to tests/security.test.mjs, each named with its OWASP number, on the CI database as before:

A05 Injection
- Through the real routes, save a hold reason, a lot note and a search containing '; drop table holds; -- and <script>alert(1)</script>. The database keeps them as plain text, the holds table still exists, and the page shows the text without running a script.
- A filter value with a comma or brackets in it (for example L-1001,site_id.neq.0) does not widen a query: the user still sees only their own site's rows.

A07 Authentication failures
- Public sign-up is refused, and supabase/config.toml has sign-up turned off, matching the live project.
- A session after sign-out, an expired session and a session for a deleted user are all refused.
- If Session 9 required two-step sign-in for the roles that release a hold: a quality lead signed in with one step only cannot release.

A02 Security misconfiguration
- Find every shortcut that fakes a signed-in user (demo mode, test users, bypass flags). Read each one in one file only, and make it refuse to work when VERCEL_ENV is production. Tests: start the app with the switch on and VERCEL_ENV=production, and check a signed-out request to a protected page still lands on the sign-in page; fail if any other file reads the switch.
- Every page sends Content-Security-Policy, X-Content-Type-Options: nosniff and Referrer-Policy, and refuses to be framed by other sites.
- Every public table has row-level security enabled and forced, and every view is security_invoker.

A04 Secrets
- After the build, search every file the browser downloads (.next/static) for the local service role key and the words service_role and sb_secret_. None may appear.
- No variable starting NEXT_PUBLIC_ holds anything but the Supabase URL and the public key.
- In the security workflow, run gitleaks (the command-line tool at a pinned version) over the whole git history, and npm audit --audit-level=high.

A10 Errors
- Ask for a lot with a malformed id, and force a database error in one route: the page shows a plain message with no stack trace and no SQL, and access is still refused, never granted.

A09 Logging
- proxy.ts writes one line per request: time, user id (or "signed out"), role, site, method, address and the result (allowed, refused or error). Never a token, cookie, key, email or password.
- Tests, reading the app's log in CI: a refused request and an allowed request each produce that line; no line contains a cookie, a token or the word password.

Update docs/owasp.md so every risk names its tests. Push, open a pull request titled "Security suite: the rest of the Top 10", wait for the security check, and tell me how many tests ran for each risk. If a test fails because the platform really has the problem, keep the test, fix the cause in the same pull request, and tell me in plain words what was wrong.

You will see recreated screen

claude — acme-platform
⏺ Read(node_modules/next/dist/docs/01-app/03-api-reference/03-file-conventions/proxy.md)
⎿ Read 212 lines
1
⏺ Write(lib/demo.ts)
+// The only file that reads DEMO_MODE. It never works in production.
+export const demoMode = () =>
+ process.env.VERCEL_ENV !== "production" && process.env.DEMO_MODE === "1";
2
⏺ Write(proxy.ts)
+log({ at, user: user?.id ?? "signed out", role, site, method, path, result });
⏺ Bash(gh pr checks --watch)
⎿ security pass 7m03s
⏺ Pull request #43 is green: 287 tests (A01 214, A02 19, A04 6, A05 14, A07 11, A09 9, A10 8, plus npm audit and gitleaks clean). Two real problems found and fixed with their tests: app/demo-login read DEMO_MODE directly, so the switch would have worked in production; and a malformed lot id showed the SQL error on the page. It now shows "Lot not found".3
Claude Code reads the Next.js guide before touching proxy.ts, writes the tests, and fixes what they find.
  1. It reads this version's own guide first. In Next.js 16 the gate is proxy.ts; older advice says middleware.ts.
  2. The demo switch, read in one place and dead in production by code, not by remembering to turn it off.
  3. Counts per risk, and the problems the tests found, in plain words.

Check it worked

The pull request is green, its log shows tests named A02, A04, A05, A07, A09 and A10, gitleaks and npm audit ran, and docs/owasp.md names a test for every risk. Any problem found is fixed in the same pull request with its test.

If it goes wrong

The workflow asks for GITLEAKS_LICENSE

The gitleaks GitHub Action wrapper asks organisation accounts for a licence key; the command-line tool does not. Say: Run the gitleaks command-line tool directly, at a pinned version, instead of the gitleaks action.

The secrets test finds a key in the browser's files, or gitleaks finds one in the history

Treat the key as public. Rotate it the same day: in Supabase, Project Settings, API Keys, create a new secret key and revoke the old one; the integration updates Vercel. Record the date in docs/KEYS.md. Then have Claude Code move the code that used it to the server, with the test proving it.

npm audit fails on a finding in a package you never added

Say: npm audit reports <name>. Tell me which package pulls it in, whether a fixed version exists, and whether it runs in the app or only during the build. Do not lower the audit level. Update the parent package if a fix exists; if not, write the finding into docs/owasp.md with an owner and a date.

Claude Code says it cannot test the log

The app's log is saved by the workflow (Step 2). Say: Read the app's log file in the CI job after each test request, and assert on the line that request produced. A test that only checks that proxy.ts mentions a log function is not proof.

Claude Code tells you the tests pass, but the check on GitHub is red

Say: The security check is red. Show me the exact command, its exit code and the last 20 lines of its log from GitHub. Never pipe a test command into anything: the pipe's exit code hides the test's. Trust the check, never the summary.

Show it red first

A test that has never failed may not be testing anything. The only way to know is to remove the protection and watch the test go red. We learned this the expensive way: a check stayed green for weeks while what it guarded was broken, and a fix to our password reset was only trusted after its test failed 4 of 11 checks against the old code and passed 11 of 11 after.

A test that can failFour steps: test passes, break the rule, the test must fail, restore the rule; a test still green when the rule is broken is not testing it. Before you trust a test, watch it fail for the right reason1Test passesprotection in place2Remove iton a throwaway branch only3Test must failred proves it checks therule4Restoredelete the throwaway branch;main stays greenStill green at step 3? The test was not testing the rule.
A test that can fail. Red at step 3 proves the test is tied to its protection. Green there means it is not, and must be fixed.

You do this on a throwaway branch whose pull request is a draft, never merged. Its defects only ever reach the throwaway database inside GitHub Actions. Never remove a protection on acme-platform-prod: real records would be open while you watch.

Step 4

Show it red first, on a throwaway branch

15 minutes

Why

Until each kind of test has been seen failing with its protection removed, the green suite is a hope. Planting four defects on one throwaway branch proves, in one CI run, that the cross-site, default-deny, demo-switch and secrets tests each catch the thing they guard. Any defect that turns nothing red is a gap, found now rather than by an attacker.

Do this

Paste into Claude Code
Show me the security suite can fail. This branch is thrown away and must never be merged. Its changes only reach the throwaway database inside GitHub Actions.

From main, create the branch security/red-first-do-not-merge and plant four defects, one commit each:
1. A new migration that replaces the holds read policy with one that lets any signed-in user read every site's holds.
2. In lib/access/routes.ts, mark /lots/[id] as public.
3. In .github/workflows/security.yml, start the app with the demo switch on and VERCEL_ENV=production.
4. A browser component that shows process.env.NEXT_PUBLIC_SERVICE_ROLE_KEY, with that variable set to the local service role key in the workflow's build step.

Do not change any test. Push, open a DRAFT pull request titled "DO NOT MERGE: red-first check of the security suite", wait for the security check, and give me a table: each defect, the tests that failed because of it (name and message), and any defect that turned nothing red.

Then close the pull request without merging and delete the branch on GitHub and on this computer. Show me git branch -a so I can see it is gone.

If a defect turned nothing red, the suite has a gap. Ask Claude Code, on a new branch from main: Defect <n> from the red-first check turned no test red. Write the test that catches it, show it failing against that defect on a throwaway branch, and open a pull request with the test only.

You will see recreated screen

github.com/acme-ops/acme-platform/pull/44
DO NOT MERGE: red-first check of the security suite #44
DraftThis pull request is still a work in progress1
Merging is blocked
The draft pull request: red, as it must be. The required checks make it impossible to merge.
  1. A draft cannot be merged by accident, and it is closed at the end.
  2. Red is the result you want here.

You will see recreated screen

claude — acme-platform
⏺ Defect 1 (holds readable by every site) → 4 failed: A01 cross-site: supervisor@cle reads probe holds — expected 0 rows, got 6; and 3 more, one per cle role. Defect 2 (/lots/[id] public) → 3 failed: A01 default deny: /lots/90412 signed out — expected /sign-in, got 200. Defect 3 (demo switch in production) → 2 failed: A02 demo switch: /review signed out with DEMO_MODE=1 and VERCEL_ENV=production — expected /sign-in, got 200. Defect 4 (key in the browser) → 2 failed: A04 secrets: service role key found in .next/static/chunks/app/page-3f2a.js.1
⏺ Bash(gh pr close 44 --delete-branch)
⎿ ✓ Closed pull request #44 and deleted branch security/red-first-do-not-merge
2
⏺ Bash(git branch -a)
⎿ * main remotes/origin/main
Claude Code's table: every planted defect caught by at least one test.
  1. Each defect, the tests it turned red, and the message. Every defect caught: no gap.
  2. Closed unmerged and deleted. The planted migration was never applied anywhere but CI's throwaway database.

Check it worked

The draft pull request was red, with at least one failed test named for each of the four defects; it is closed without merging; git branch -a no longer lists the branch; and any gap now has its own test on main.

Fastest path

All four defects go in one branch and one CI run. One at a time would take four runs for the same proof, because the test names already tell you which defect each failure belongs to.

If it goes wrong

A defect turned nothing red

The test meant to catch it can never fail, or does not exist. Write the missing test as above, and show it red against that defect before merging it. Every new test from now on is shown red first: put "Shown red first: how" in the pull request template.

Claude Code edits a test on the red-first branch to explain the failure

Say: Do not change any test on this branch. Revert that commit and report the failures as they are. The point is to see the suite as it is on main.

Claude Code offers to remove the protection on the development or live project instead

Refuse. Say: Only plant defects on this branch, in files. Never change acme-platform-prod or acme-platform-dev. The deny rules from Session 1 also stop db push and db reset.

Someone approved the red-first pull request

It cannot merge while the security check is red, which is why that check is required (Step 7). Close it now. If a planted change ever reaches main, revert it at once with a pull request and check the live project with the Security Advisor.

Knowledge check

Why must the demo switch refuse to work in production by code, not just be turned off there?

Knowledge check

You plant a defect that opens another site's holds and the suite stays green. What does that tell you?

Knowledge check

Why does every request leave a log line with the user, address and result?

References

  1. OWASP Cheat Sheet Series: Injection Prevention. https://cheatsheetseries.owasp.org/cheatsheets/Injection_Prevention_Cheat_Sheet.html
  2. OWASP Cheat Sheet Series: Logging. https://cheatsheetseries.owasp.org/cheatsheets/Logging_Cheat_Sheet.html
  3. OWASP Cheat Sheet Series: Secrets Management. https://cheatsheetseries.owasp.org/cheatsheets/Secrets_Management_Cheat_Sheet.html
  4. Next.js Docs: proxy.ts (formerly middleware). https://nextjs.org/docs/app/api-reference/file-conventions/proxy
  5. Supabase Docs: Understanding API keys. https://supabase.com/docs/guides/api/api-keys
  6. Gitleaks (open-source secret scanner). https://github.com/gitleaks/gitleaks

Chapter 3 · Session 18

Keep it proven: every week, and signed

New flaws are found in old packages every week, and settings change outside pull requests. A weekly run re-proves the suite and checks the live site from outside, with an alarm you have heard go off. Then the dashboards: Supabase's Security Advisor, Dependabot and the logs. Last, the security check becomes required and owner two signs the map.

25 min3 stepsEnds with a gate

By the end of this chapter you can

  • Schedule a weekly security run that also checks the live site signed out, and fire its alarm once on purpose.
  • Get Supabase's Security Advisor clean on both projects, Dependabot on, and request logs kept long enough to answer "who saw what".
  • Make the security check required on main and have owner two sign docs/owasp.md.
Step 5

A weekly security run, and an alarm you have heard

10 minutes

Why

The pull request check only runs when someone changes the code, but risk changes without a pull request: a flaw is announced in a package you already use, or a setting is changed in a dashboard. A weekly run re-proves the whole suite and checks the live site from outside, signed out, changing nothing. And an alarm nobody has heard is not an alarm: on our platform a nightly check caught a real fault ten nights running, but the step that should have opened an issue was broken, so nobody heard.

Do this

Paste into Claude Code
On a new branch security/weekly, add .github/workflows/security-weekly.yml:
- It runs every Monday at 06:17 UTC, and by hand (workflow_dispatch) with one input, fire_alarm (true or false, default false).
- On main: the whole security suite on a fresh CI database, exactly as security.yml does; gitleaks over the whole history; npm audit --audit-level=high.
- Against the live site https://acme-platform.vercel.app, signed out only, changing nothing: http:// redirects to https://; every protected page in lib/access/routes.ts lands on the sign-in page; every /api/ route answers 401; the security headers are there; and an address that must never exist, /this-page-must-not-exist-7f3a, answers 404. A protected page that answers 200 with anything but the sign-in page is a failure. A 5xx or a timeout is "could not measure" and also fails the run, never counts as a pass.
- If fire_alarm is true, one step fails on purpose with the message "alarm test".
- If anything fails, open a GitHub issue labelled security, assigned to both owners (ask me for their GitHub usernames), with the failing step's name, the run's link and the first 40 lines of its log. Give the workflow only the permissions it needs: contents read and issues write.
Do not sign in to the live site and do not use any secret.

Push, open a pull request titled "Weekly security run", wait for the checks, and tell me the result.

After it merges, run it by hand with the alarm on, check the issue arrives, close it, then run it again with the alarm off:

Open

https://github.com/acme-ops/acme-platform/actions/workflows/security-weekly.yml

Choose Run workflow, set fire_alarm to true, and press Run workflow.

You will see recreated screen

github.com/acme-ops/acme-platform/actions/workflows/security-weekly.yml
All workflowscischemasecuritysecurity-weeklydeploy
security-weekly
This workflow has a workflow_dispatch event trigger.
Use workflow fromBranch: main ▾
fire_alarmtrue ▾1
Run workflow
Running the weekly workflow by hand, with the alarm test on.
  1. True for the alarm test only. The weekly schedule always runs with false.

You will see recreated screen

github.com/acme-ops/acme-platform/issues/45
Weekly security run failed: alarm test
Labels: security · Assignees: both owners1
Failing step: alarm test · Run: github.com/acme-ops/acme-platform/actions/runs/8840
Error: alarm test
live site: 31 checks, 31 passed, 0 could not measure
must-not-exist /this-page-must-not-exist-7f3a → 404 ✔
Close issue
The issue the alarm opened: this is what a real failure will look like on a Monday.
  1. Both owners are assigned, so it reaches someone even when one of you is away.

Check it worked

The alarm run opened an issue assigned to both owners (now closed), and the run with the alarm off is green, including the live-site checks and the must-not-exist address answering 404.

If it goes wrong

The scheduled run never starts

GitHub runs schedules only from the default branch, so merge the workflow first. In public repositories it also pauses a schedule after 60 days without activity [1]. Check the Actions tab on the first Monday.

The alarm run fails but no issue appears

The workflow lacks permission to write issues, or the issue step needs a copy of the repository it never made. Say: The alarm failed but no issue was opened. Show me the issue step's log, fix it, and run the alarm test again. The detector working is not enough: the alarm itself must be heard.

Every live-site page reports "present", even the must-not-exist address

The site answers 200 for every address, or sends signed-out visitors to the sign-in page, which also answers 200. That is the check that could only ever say "fine", and we had it. Say: Treat landing on the sign-in page as "refused" for protected pages and "could not measure" for anything else, and make the must-not-exist address fail the run unless it answers 404.

The run is red for something nobody changed

Usually a newly announced flaw in a package. Read the issue, then ask Claude Code which package and whether a fixed version exists. Do not turn the check off; Dependabot (Step 6) often opens the update for you.

Step 6

Advisor clean, Dependabot on, and logs that can say who saw what

10 minutes

Why

Three things are settings in dashboards, not code, so a person sets them and the map records them. Supabase's Security Advisor checks the live database itself for the mistakes that expose data, independently of your tests. Dependabot tells you when a package you use gets a known flaw. And the request lines from Step 3 are only useful if they are kept somewhere long enough to answer "who saw what" after an exposure, which IT must agree.

Do this

Open

https://supabase.com/dashboard/project/abcdefghijklmnopqrst/advisors/security

The live project's Security Advisor. Choose Rerun linter. Then do the same for the development project at https://supabase.com/dashboard/project/tsrqponmlkjihgfedcba/advisors/security.

Open

https://github.com/acme-ops/acme-platform/settings/security_analysis

Turn on Dependabot alerts and Dependabot security updates.

For the logs, ask IT where the company keeps logs and for how long, then add a drain from Vercel to that place. Vercel keeps runtime logs only briefly on its own, and drains depend on your plan: check both on Vercel's site on the day [3].

Open

https://vercel.com/acme-ops/~/settings

Vercel team settings. Open Drains (called Log Drains on older pages), add one for project acme-platform to the destination IT gives you. Any secret it needs is typed by you or IT here, never pasted into Claude Code.

Paste into Claude Code, after replacing the <...> parts
On a new branch security/advisor-and-logs, update docs/owasp.md:
- A02: Supabase Security Advisor on acme-platform-prod and acme-platform-dev checked on <today's date>: <paste "no errors", or the name of each finding>.
- A03: Dependabot alerts and security updates are on; npm audit runs on every pull request and every week.
- A09: request lines go to <where IT keeps logs> through a Vercel drain set up by <name> on <date>, kept for <how long IT agreed>. Who may read them: <roles>. If there is no drain yet, write "could not measure who saw what before <date>" with an owner and a date to fix it.
Add the drain to docs/KEYS.md by name, with where its secret lives (never the value). If any Advisor finding is an error, write a new migration that fixes it, with a test in tests/security.test.mjs, in this pull request. Open a pull request titled "Security: advisor, dependencies and logs" and wait for the checks.

You will see recreated screen

supabase.com/dashboard/project/abcdefghijklmnopqrst/advisors/security
Security Advisor
Rerun linter
The Security Advisor after the rerun: no errors on the live project.
  1. Errors (RLS disabled, a security definer view) mean stop and fix before anything else.
  2. The "RLS enabled, no policy" notes from Session 5 are gone since Session 8.

You will see recreated screen

github.com/acme-ops/acme-platform/settings/security_analysis
GeneralRulesActionsSecrets and variablesCode security
Dependabot
Dependabot alerts1
Dependabot security updates2
Dependabot on for the repository.
  1. Alerts: you hear about a flaw in a package you use.
  2. Updates: Dependabot opens the pull request with the fix, which then meets every check like any other change.

Check it worked

Both projects' Security Advisors show no errors; Dependabot alerts and updates are on; and docs/owasp.md says where request lines are kept and for how long, or names the gap with an owner and a date.

Fastest path

Send IT the question about logs on the day you start this session: "where do we keep application logs, and for how long?" The answer usually takes longer than everything else here.

If it goes wrong

The Advisor shows RLS Disabled in Public, or Policy Exists RLS Disabled

A table can be read through the website's public key. Stop. In Claude Code: The Security Advisor says RLS disabled on <table>. Write a new migration that enables and forces row-level security on it, add the table to the A01 tests, and open a pull request. Then ask how it happened: a table made by clicking in the dashboard is the usual cause.

The Advisor shows Security Definer View or Function Search Path Mutable

In Claude Code: The Security Advisor reports <finding> on <name>. Write a new migration that fixes it (security_invoker = true for a view, set search_path = '' for a function) with a test.

Drains are not on your Vercel plan, or IT has no log store yet

Write the gap into docs/owasp.md honestly, with an owner and a date, and raise it in the IT package (Session 21). Until it is fixed, the true answer to "who saw what" for any exposure is "could not measure".

Step 7

Make the security check required, and sign the map

5 minutes

Why

A security test that can be merged past while red protects nothing on the day it matters. Adding the security check to the ruleset Session 10 set up means no pull request, from you or an agent, can merge with a door open. Owner two reading and approving the map means a second person has checked that every risk has a test, which is what IT will ask in Session 21.

Do this

Open

https://github.com/acme-ops/acme-platform/settings/rules

Open the ruleset protect main. Under Require status checks to pass, choose Add checks, type security and select it. Save.

Paste into Claude Code, after replacing the <...> parts
On a new branch security/sign-off, add to the top of docs/owasp.md: "Reviewed by sam@acme.com on <today's date>. Every risk names its tests; each kind of test was shown red first on <date of the red-first check>. Next review: when any risk's tests change, and every quarter." Add to .github/pull_request_template.md a heading "Shown red first" asking how each new test was seen failing. Open a pull request titled "Sign the OWASP map" and wait for the checks.

Owner two reads docs/owasp.md on GitHub, from the summary table to each unproven item, and approves. Merge.

You will see recreated screen

github.com/acme-ops/acme-platform/settings/rules
GeneralCollaborators and teamsRulesActionsSecrets and variables
protect main
Require status checks to pass
1
Status checkSource
ciGitHub Actions
schemaGitHub Actions
clampsGitHub Actions
securityGitHub Actions
Save changes
The ruleset for main with the security check required, next to the checks from earlier sessions.
  1. security sits beside the checks from Sessions 3, 5 and 10. From now on, a red security check blocks every merge.

Check it worked

The ruleset lists security as a required check, and docs/owasp.md on main starts with owner two's review line.

If it goes wrong

security is not offered when you type it

GitHub only offers checks that have run recently in the repository. Open any pull request so the security check runs once, then add it.

Pull requests wait for ever with "security: Expected — Waiting for status to be reported"

The workflow does not run on every pull request (for example it only runs when certain folders change), so the required check never reports. Say: Make security.yml run on every pull request, with no path filters.

Before you go on · Session 18 is done whenTick each one

Knowledge check

What does the weekly run check that the pull request check cannot?

Knowledge check

Why fire the weekly run's alarm on purpose once?

References

  1. GitHub Docs: Events that trigger workflows (schedule). https://docs.github.com/en/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows
  2. Supabase Docs: Database advisors. https://supabase.com/docs/guides/database/database-advisors
  3. Vercel Docs: Drains. https://vercel.com/docs/drains
  4. GitHub Docs: Dependabot. https://docs.github.com/en/code-security/dependabot
  5. GitHub Docs: Available rules for rulesets (require status checks). https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/managing-rulesets/available-rules-for-rulesets

Chapter 4 · 12 questions · 80% passes

Final assessment

Twelve questions across the session. Score 80% (10 of 12) to pass. Your LMS records your score and each answer; you can review the chapters and try again.

15 min12 questions≈ 15 minutesRetake allowed

Choose one answer for each question, then submit. You will see the right answer and why for every question.

1. What is the difference between a protection and a proof?
2. In docs/owasp.md, a risk has a protection but no test. How is it marked?
3. Which test catches 'any signed-in user opens another site's lot by changing the number in the address'?
4. Why does the suite create a made-up probe site with lot codes and part numbers that are easy to spot?
5. Why does every access test first check that the probe rows exist?
6. A server file uses the Supabase service role key. What must be true?
7. How is a demo or bypass switch made safe?
8. Where are defects planted to show the suite red first?
9. You plant four defects and three turn tests red. What next?
10. What must every request log line contain, and never contain?
11. The weekly run checks the live site signed out. A protected page answers 200. When is that a pass?
12. Why add the security check to the ruleset's required checks?