Security beyond the checklist in a Laravel app · Part 1 of 6
The app, the threat model, and a test suite written from the other side
NoteMini, a team notes app written the careful way; a threat model in one paragraph; an attack suite that passes only when the attack fails; OWASP ZAP in Docker, signed in, with eleven warnings and one real bug on the first run.
By Abhishek Fouzdar
A security checklist tells you what to add. It does not tell you what you are protecting, who from, or how the thing you added gets quietly undone by next month's feature. This series takes a small Laravel application through the OWASP Top 10, one weakness at a time: how each one gets written in a codebase that means well, the test that proves it is there, the fix at the layer that holds, and what a scanner saw before and after. This part builds the application, writes its test suite from the attacker's side, and runs the first scan. Laravel 13.40, PHP 8.5, MySQL 8.4, OWASP ZAP 2.17, on 4 November 2026.

The method
Six steps, the same for every part:
- Name the invariant from the other side. Not "notes are protected by a policy" but "a member of another team cannot read, change or delete this note, whatever URL they type", a sentence that an attacker's request either proves or fails to prove.
- Write the test as the attacker. It signs in as the wrong person, or as nobody, and does the thing. It passes only when the thing fails. A test like that is a different document from a feature test: the feature test says the product works, the attack test says a specific misuse does not.
- Introduce the weakness the way it gets introduced. Nobody writes
Note::findOrFail($id)without a policy check on purpose. They write it in a hurry, in a new endpoint, in a feature that did not exist when the policy was. Each part adds a feature the way features get added, and watches a test go red. - Fix it at the layer that holds. Usually the framework already has the tool: a policy, a scoped route binding, a validation rule, a signed URL, a rate limiter. The fix is reaching for it, and knowing which one.
- Keep the test. It is the only proof that survives the next feature.
- Scan before and after, because the scanner sees things the tests were never written for, and because its report is the number the series is measured by.
Step 2 is a convention and step 6 is a tool. Most of this part is the application they run against.
The application, as written
NoteMini is a team notes app. People register, which creates their first team, and sign in. A team has notes, written in Markdown; a note has attachments, and can be shared with anyone by a link. There is a "clip a page" feature that fetches a public URL and turns it into a note, a team page where owners invite and remove members, and an admin area with a user list. It is the kind of application that has every category in the OWASP Top 10 somewhere in it: other people's data, uploads, user-written content, a server that fetches URLs, accounts, an admin.
It is written the way a careful team would write it on a good day, and the point of the series is what happens on the other days. Four people are seeded: Alice owns team Acme, Bob is a member of it, Mallory owns a different team, and there is one admin. Alice has a note titled "Q4 pricing (confidential)". Most of the series is about Mallory and that note.
The parts that matter for what follows:
// app/Policies/NotePolicy.php
public function view(User $user, Note $note): bool
{
return $user->belongsToTeam($note->team);
}
public function delete(User $user, Note $note): bool
{
return $note->user_id === $user->id || $user->ownsTeam($note->team);
}
// routes/web.php
Route::middleware(['auth', 'team'])->group(function () {
Route::get('/notes/{note}', [NoteController::class, 'show'])->name('notes.show');
Route::get('/notes/{note}/attachments/{attachment}', [AttachmentController::class, 'download'])->scopeBindings();
// …
});
Route::middleware(['auth', 'can:admin'])->prefix('admin')->group(function () {
Route::get('/users', [Admin\UserController::class, 'index']);
});
Every controller method that touches a note calls $this->authorize('view', $note) or update or delete first. The team middleware resolves the current team from the session and refuses the request if the user is not a member of any. scopeBindings() on the attachment routes makes Laravel look the attachment up through the note's relationship, so an attachment id under the wrong note is a 404 before the controller runs.
The note body is Markdown, rendered by Laravel's Str::markdown with raw HTML stripped and unsafe link schemes refused:
public function html(): string
{
return Str::markdown($this->body, [
'html_input' => 'strip',
'allow_unsafe_links' => false,
'max_nesting_level' => 10,
]);
}
Uploads go to the local disk, which nginx does not serve, under a name the server chose, and come back as downloads:
$path = $file->storeAs('attachments/'.$note->id, Str::uuid().'.'.$file->extension(), 'local');
// …
return Storage::disk('local')->download(
$attachment->path,
$attachment->original_name,
['Content-Type' => $attachment->mime, 'X-Content-Type-Options' => 'nosniff'],
);
A share link is a forty-character random token with an expiry, and the token is the whole credential. The sign-in form allows five wrong passwords a minute per email and address, says the same thing for a wrong password and an unknown email, and regenerates the session id on success. Passwords are twelve characters or more and, outside the test suite, checked against the Have I Been Pwned list.
The clipper is the one piece that would not be in most codebases at all, and it is there because a server that fetches a URL the user typed is the shape of a server-side request forgery, which is part 5's subject. As written it refuses anything that is not http or https, resolves the hostname itself, requires every address it resolves to to be public, pins the request to the address it checked so the name cannot change its mind between the check and the connection, follows no redirects, and reads at most a megabyte:
$addresses = gethostbynamel($host) ?: [];
if ($addresses === [] || collect($addresses)->contains(fn ($ip) => ! self::isPublic($ip))) {
throw new InvalidArgumentException('That address does not resolve to a public server.');
}
$response = Http::withoutRedirecting()
->timeout(5)
->connectTimeout(3)
->withOptions(['curl' => [CURLOPT_RESOLVE => [$host.':'.$port.':'.$addresses[0]]]])
->get($url);
public static function isPublic(string $ip): bool
{
return filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE | FILTER_FLAG_GLOBAL_RANGE) !== false;
}
Twenty-five feature tests cover all of it, and they pass.
The threat model, in one paragraph
Who is the attacker? For an application like this, overwhelmingly, a customer. Mallory has an account, a team, notes of her own, and every page the application serves to a signed-in user. She can read the HTML, change any id in any URL, add any field to any form, and send any request the browser could send, with any session she owns. Second, a visitor with a link: someone who was sent a share URL, or who found one. Third, the anonymous internet, which mostly means scanners, and which the sign-in form, the registration form and the password reset form face directly. The things being protected are the confidentiality of one team's notes from another, the integrity of the notes and the memberships, and the accounts themselves. The server, the database and the other containers on the network are behind the application, and the clipper is the one door from the application to them.
That paragraph is the difference between a checklist and a threat model. Every test in the next section is one sentence from it, made executable.
A suite written from the other side
The attack suite lives in tests/Attack, runs with bin/dev attack, and follows one rule: every test does what an attacker would do and passes only when it fails. The first eleven:
✓ it refuses a note to a member of another team
✓ it keeps another team's notes out of the list and the search
✓ it refuses an attachment to a member of another team, even by guessing its id
✓ it refuses the admin area to a signed-in user who is not an admin
✓ it does not let a user make themselves an admin through any form
✓ it does not open a shared note to a wrong, expired or revoked token
✓ it refuses a team page, an invite and a removal to a non-member
✓ it renders a note body that carries script as text, not as script
✓ it treats a search term and a sort column as data, not as SQL
✓ it stores an upload where the web server cannot execute or serve it
✓ it refuses to clip an address that resolves to a private network
Tests: 11 passed (52 assertions)
One of them in full, because the shape is the point:
it('refuses a note to a member of another team', function () {
$alice = owner();
$note = Note::factory()->for($alice->teams->first())->for($alice, 'author')->create(['title' => 'Q4 pricing']);
$mallory = owner();
$this->actingAs($mallory)->get("/notes/{$note->id}")->assertForbidden();
$this->actingAs($mallory)->get("/notes/{$note->id}/edit")->assertForbidden();
$this->actingAs($mallory)->put("/notes/{$note->id}", ['title' => 'Changed', 'body' => 'x'])->assertForbidden();
$this->actingAs($mallory)->delete("/notes/{$note->id}")->assertForbidden();
expect($note->fresh()->title)->toBe('Q4 pricing');
});
The last line is not decoration. A 403 says the controller refused; the unchanged title says nothing before the controller did the work anyway. Every test in the suite ends with the state of the world, not the status code.
Some of them pass for reasons worth knowing. The self-promotion test posts is_admin=1 to the registration form and the note form, and nothing happens because is_admin is not in $fillable and never passes through fill() at all; the admin controller sets it with forceFill on a validated boolean, on its own route behind its own gate. The SQL test sends %' or 1=1 -- as a search term and title desc, (select sleep(5)) as a sort column; the term is a bound parameter and the column is matched against a list of three before it reaches orderBy. The clipper test tries http://db:3306/, http://mailpit:8025/api/v1/messages, http://169.254.169.254/latest/meta-data/, file:///etc/passwd and http://[::1]/, and every one is refused before a connection is attempted.
Unlike the race suite in the concurrency series, this suite is green on day one, and that is deliberate. Each later part adds a feature the way features get added, and one of these tests, or a new one next to it, goes red. The suite is the thing that notices.
The ten categories, and where they live here
The 2025 edition of the OWASP Top 10 moved a few things around: server-side request forgery is now under Broken Access Control, cross-site scripting is under Injection, and there is a new tenth category for the way applications handle errors and unexpected states. Where each one is in NoteMini, and which part takes it:
| OWASP 2025 | In NoteMini | Part |
|---|---|---|
| A01 Broken Access Control | Notes, attachments and teams across team lines; the admin gate; mass assignment; CSRF; the clipper (SSRF) | 2, 5 |
| A02 Security Misconfiguration | Debug mode, response headers, cookie flags, what nginx and PHP announce | 5 |
| A03 Software Supply Chain Failures | composer.lock, composer audit, what the build pulls in |
6 |
| A04 Cryptographic Failures | Password hashing, the reset token, the share token, what travels in the clear | 4 |
| A05 Injection | The search, the sort, the Markdown body, uploads, anything handed to a shell | 3 |
| A06 Insecure Design | The share link's expiry, the invite that reveals nothing, rate limits as a design choice | throughout |
| A07 Authentication Failures | Brute force, user enumeration, session fixation, the reset flow, remember-me, a second factor | 4 |
| A08 Software or Data Integrity Failures | Unsigned data trusted on the way back in: serialised state, a signed URL that was not signed | 5 |
| A09 Security Logging and Alerting Failures | What the application records when any of the above is attempted | 6 |
| A10 Mishandling of Exceptional Conditions | Failing open, errors that say too much, a transaction that half happened | 6 |
The scanner
OWASP ZAP runs in Docker as an on-demand service, like k6 did in the other series, through bin/dev scan baseline. The baseline scan spiders the application, passively inspects every request and response, and reports what it saw; it does not attack. Out of the box it sees the front door only, which for this application is the sign-in page, the registration page and the password reset page, nine URLs in all. The interesting surface is behind the sign-in.
The scan therefore signs in. A shell script posts the sign-in form with curl as Alice and prints the session cookie, and a hook script, which ZAP's scan scripts load with --hook, attaches that cookie to every request the scanner makes and keeps the spider away from the sign-out form:
def zap_started(zap, target):
cookie = os.environ.get("SCAN_COOKIE")
if cookie:
zap.replacer.add_rule(
description="session", enabled=True, matchtype="REQ_HEADER",
matchregex=False, matchstring="Cookie", replacement=cookie,
)
zap.spider.exclude_from_scan(".*/logout.*")
Signed in, the spider found 121 URLs. The report:
WARN-NEW: Content Security Policy (CSP) Header Not Set x 11
WARN-NEW: Missing Anti-clickjacking Header x 12
WARN-NEW: X-Content-Type-Options Header Missing x 11
WARN-NEW: Permissions Policy Header Not Set x 11
WARN-NEW: Cross-Origin-Resource-Policy Header Missing or Invalid x 13
WARN-NEW: Server Leaks Version Information via "Server" HTTP Response Header Field x 10
WARN-NEW: Server Leaks Information via "X-Powered-By" HTTP Response Header Field(s) x 10
WARN-NEW: In Page Banner Information Leak x 2
WARN-NEW: Cookie No HttpOnly Flag x 10
WARN-NEW: Big Redirect Detected (Potential Sensitive Information Leak) x 2
WARN-NEW: Information Disclosure - Debug Error Messages x 1
FAIL-NEW: 0 FAIL-INPROG: 0 WARN-NEW: 11 WARN-INPROG: 0 INFO: 0 IGNORE: 0 PASS: 56
Eleven warnings, no failures, fifty-six rules passed. Reading them: seven are response headers that neither Laravel nor nginx sets by default, and the two "leaks" are nginx and PHP announcing their versions, nginx/1.30.4 in the Server header and on nginx's own 404 page, PHP/8.5.12 in X-Powered-By. All of those are part 5. The HttpOnly warning is on the XSRF-TOKEN cookie, which is readable from JavaScript on purpose so that a front end can send it back as a header; the session cookie has the flag. The big redirect is the 302 after a form post carrying the flashed input back to the form, and is noise.
The last one is not noise. Information Disclosure - Debug Error Messages x 1 was a POST /notes/5/share that answered 500 Internal Server Error. The spider had submitted the share form, as it submits every form it finds, and the controller had died:
Carbon\Carbon::rawAddUnit(): Argument #3 ($value) must be of type int|float, string given
The form's day count was validated as an integer and then handed to now()->addDays($data['days']) as the string "7", because validation checks a value and does not cast it. The feature test passed because it posted 3, an integer, which a browser never does. The test now posts '3', the controller casts, and the scanner's first finding against the application was a plain bug that every real user would have hit. A scanner is not a security tool only.
composer audit reports no advisories against the lock file, and that is part 6's starting number.
What went wrong
The session cookie had a different name. The sign-in script looked for notemini_session in curl's cookie jar, found nothing, printed an empty string, and the first "signed-in" scan ran as a guest: nine URLs, twelve warnings, no sign that anything was missing. Laravel 13's config/session.php builds the default cookie name as Str::slug(env('APP_NAME')).'-session', with a hyphen, where earlier versions used an underscore. The scan script now refuses to run with an empty cookie, which is the general lesson: a tool that silently falls back to doing less is a tool that reports success it did not earn.
The application locked the scanner out. Five sign-ins a minute per email and address is the rate limit, and while the sign-in script was being debugged it was run more than five times in a minute, so the sixth attempt got the "too many attempts" page and no cookie. The control worked. The scan script signs in once per run, and the debugging moved to Bob's account.
The spider deleted half the notes. It submits every form it finds, including the delete buttons, and the seeded database was missing most of its notes by the end of the first run. bin/dev reset puts it back, and the general rule is older than ZAP: a scanner runs against a copy of the application that nobody minds losing.
Forms do not go inside paragraphs. The note page put its Delete form and Edit link in a <p>, and the browser's parser closed the paragraph at the <form>, which put the two controls in different grid cells. Not a security finding, but it was in the screenshot, and the screenshot does not lie about markup any more than the scanner does.
Part 2 adds the first new feature to NoteMini, a JSON endpoint for a mobile client, in the way such endpoints usually arrive, and watches a member of another team read Q4 pricing: Broken access control: the id in the URL, the field in the form, the route that forgot.
New posts by email
Get new posts by email. Nothing else, no digests, unsubscribe in one click.
Comments
Comments are GitHub Discussions in shipbytes/discussions. Sign in with GitHub to post.
In this series
1 / 6- OverviewSecurity beyond the checklist in a Laravel app
- Part 1The app, the threat model, and a test suite written from the other side
- Part 2Broken access control: the id in the URL, the field in the form, the route that forgot
- Part 3Injection and output: SQL in the search, a script in the page, a path and a shell
- Part 4Authentication and cryptographic failures: tokens, passwords and a second factor
- Part 5Security misconfiguration and data integrity: headers, debug mode and a signed link
- Part 6Supply chain, logging and the unexpected: composer audit, what to record, and failing closed