Security beyond the checklist in a Laravel app · Part 6 of 6
Supply chain, logging and the unexpected: composer audit, what to record, and failing closed
The three categories a feature team reaches last: composer audit as a CI gate for the code you did not write, a security log that records refusals without the password, and a write wrapped in a transaction that fails closed. Plus the whole series in one table.
By Abhishek Fouzdar
The last three OWASP categories are the ones a feature-focused team reaches last, because none of them is about a feature. Software Supply Chain Failures is about the code you did not write. Security Logging and Alerting Failures is about whether you would know. And Mishandling of Exceptional Conditions, new to the 2025 list, is about what the application does when something goes wrong that it did not plan for. This final part gives NoteMini from part 5 a dependency gate, a security log, and a fail-closed path through its riskiest write, and then stands back to look at the whole.
1. The code you did not write
Most of a Laravel application is other people's code. The vendor directory is larger than everything the team wrote, it runs with the application's full privileges, and it changes on a schedule nobody controls. Supply-chain failures are the category where a line you never read becomes the hole, and the defining property is that nothing in your own code or your own tests will show it. The instrument is a different one, and Composer ships it:
$ composer audit
No security vulnerability advisories found.
composer audit checks every installed package, including the transitive ones pulled in by the packages you chose, against a database of known advisories. A clean result today is not a clean result next week, because the advisory database grows while the lock file stays still; a package that was fine when it was installed becomes a known vulnerability the day an advisory is published, with no change to your code. That is why the check belongs in continuous integration, on every push, where it fails the build:
- name: Audit dependencies for known advisories
run: composer audit --locked
--locked audits composer.lock rather than resolving fresh, so the gate checks exactly what would be deployed. Two habits go with it. The lock file is committed, so that every environment installs the identical set of versions and the audit means something; an application that resolves dependencies fresh on each deploy is an application whose vendor directory nobody can name. And composer outdated --direct is read periodically, because the gap between "no known advisory" and "years behind" is where the next advisory lands: a dependency that cannot be updated when the advisory arrives is the supply-chain failure that the famous ones all have in common. The gate does not keep dependencies current; it makes the day they stop being safe a failed build instead of a breach.
2. Whether you would know
For five parts, every attack in the attack suite was refused, and every refusal was silent. A note another team tried to read returned a 403 and wrote nothing down. A login with the wrong password returned a message and wrote nothing down. An application that refuses an attack and records nothing is an application where a thousand refused attacks and the one that was not refused look identical from the operator's chair: like nothing happening. Logging and alerting failures are the category of not knowing, and the breaches it names ran for months and years not because the attacker was quiet but because nobody was listening.
NoteMini gets a dedicated log channel so the security events are in one place, not buried in the request log:
'security' => [
'driver' => 'single',
'path' => storage_path('logs/security.log'),
'level' => 'info',
],
And the events worth an alert are written to it: a failed login, a lockout, every authorization denial, and every change to an admin role. The authorization denials come from one place, a Gate::after callback, so that a new policy added next year is logged without anyone remembering to log it:
Gate::after(function (?User $user, string $ability, ?bool $result) {
if ($result === false) {
Log::channel('security')->warning('authz.denied', [
'user_id' => $user?->getAuthIdentifier(),
'ability' => $ability,
'path' => request()->path(),
'ip' => request()->ip(),
]);
}
});
The hard rule of this section is in the fields, not the events: the log records who and what and where, and never the secret. A failed login logs the email and the IP and not the password that was tried; a log that holds credentials is a second copy of the thing you were protecting, in plain text, in a file that is backed up and shipped to a log aggregator and read by more people than the database is. The test is written to that rule as much as to the event:
it('logs a failed login without the password', function () {
$user = User::factory()->create(['password' => 'the real password']);
Log::shouldReceive('channel')->with('security')->andReturnSelf();
Log::shouldReceive('warning')->once()->withArgs(function (string $message, array $context) use ($user) {
return $message === 'auth.failed'
&& ($context['email'] ?? null) === $user->email
&& ! in_array('the wrong password', $context, true)
&& ! array_key_exists('password', $context);
});
Log::shouldReceive('info')->andReturnNull();
$this->post('/login', ['email' => $user->email, 'password' => 'the wrong password']);
});
The test asserts both halves: that the event is recorded, and that the attempted password is nowhere in what was recorded. The log is the input to the part this series does not cover, which is alerting: a rate of auth.failed across many accounts is credential stuffing, a burst of authz.denied from one user is someone trying doors, and a admin.role_changed nobody expected is the one that pages a human at night. The log is only useful if something reads it, but nothing can read what was never written, and for five parts nothing was written.
3. What the application does when something goes wrong
The 2025 list added a category for the behaviour that the other nine assume: that the application, faced with something it did not plan for, does the safe thing. Mishandling of Exceptional Conditions is failing open when you should fail closed, leaving half a change written when the second half fails, and turning an unexpected state into a 500 that, with debug on, is the disclosure from part 5. The scanner met this category by accident twice in this series, both times as a POST that returned 500 when the row it needed had been deleted by another request a moment earlier.
NoteMini's riskiest write is the one that touches two stores at once: duplicating a note copies database rows and files. Written the direct way, it does each step as it comes:
$copy = $note->team->notes()->make(['title' => $note->title.' (copy)', 'body' => $note->body]);
$copy->author()->associate($request->user());
$copy->save();
foreach ($note->attachments as $attachment) {
$path = 'attachments/'.$copy->id.'/'.Str::uuid().'.bin';
Storage::disk('local')->put($path, Storage::disk('local')->get($attachment->path));
$copy->attachments()->create([/* … */]);
}
The copy note is saved, and then the attachments are copied one by one. If a source file is missing, because an attachment row points at a file that a failed upload never wrote, or that another request has just removed, the loop fails partway, and the copy note is already in the database: a note that exists but is not the copy anyone asked for, with some of its attachments and not others. The request returns a 500, and the shelf is left in a state no code intended.
The test asserts the state, not the status:
it('leaves no half-made copy when duplicating a note fails partway', function () {
Storage::fake('local');
$alice = owner();
$note = Note::factory()->for($alice->teams->first())->for($alice, 'author')->create(['title' => 'Original']);
Attachment::factory()->for($note)->create(['path' => 'attachments/'.$note->id.'/gone.bin']);
$before = Note::count();
try {
$this->actingAs($alice)->post("/notes/{$note->id}/duplicate");
} catch (\Throwable) {
// the point is the state afterward, however the request ended
}
expect(Note::count())->toBe($before);
});
⨯ it leaves no half-made copy when duplicating a note fails partway
Failed asserting that 2 is identical to 1.
Two notes where there should be one: the original and the half-made copy. The fix is to make the whole operation one thing that either happens or does not, which is a transaction, and to check the condition that would fail before trusting it, which is failing closed:
$copy = DB::transaction(function () use ($request, $note) {
$copy = $note->team->notes()->make(['title' => $note->title.' (copy)', 'body' => $note->body]);
$copy->author()->associate($request->user());
$copy->save();
foreach ($note->attachments as $attachment) {
abort_unless(Storage::disk('local')->exists($attachment->path), 409, 'A file is missing; try again.');
$path = 'attachments/'.$copy->id.'/'.Str::uuid().'.bin';
Storage::disk('local')->put($path, Storage::disk('local')->get($attachment->path));
$copy->attachments()->create([/* … */]);
}
return $copy;
});
Two ideas, and they are the whole category. The transaction makes the write atomic: if anything inside it throws, including the abort, the database rolls back and the copy note is gone, so there is no half-made state to find. And abort_unless fails closed: faced with a missing file, the code refuses the whole operation with a 409 rather than carrying on and producing something broken. Failing closed is the rule that connects this to the rest of the series. The SSRF guard in part 1 fails closed, refusing a host it cannot prove is public. The authorization in part 2 fails closed, denying by default. The signature check in part 5 fails closed, refusing a request it cannot verify. A system is secure to the degree that its unexpected paths all lead to "no", and this category is the habit of checking that they do.
The 500s the scanner found belong here too. With APP_DEBUG=false from part 5, an unexpected exception is a plain error page rather than a disclosure, which is the floor. The ceiling is that the foreseeable exceptional conditions, the deleted row, the missing file, the duplicate key, are handled as the 404 or 409 they are, inside a transaction that leaves nothing behind. The difference between the floor and the ceiling is a support ticket that says "it failed" versus a data-integrity incident that nobody noticed for a month.
The series, in one table
Every part named an invariant from the attacker's side and left a test that holds it. The whole suite:
| Part | Category | What the test proves |
|---|---|---|
| 1 | the method | the app, the threat model, eleven invariants green on day one |
| 2 | Broken Access Control | a note, an attachment, an admin route and a form field each refuse the wrong person |
| 3 | Injection | a search, a note body, a path and a filename are each data, never code |
| 4 | Authentication & Cryptographic | a token hashed, a password re-checked, a seed encrypted, a code rate-limited |
| 5 | Misconfiguration & Integrity | the headers at the edge, the version hidden, a signature actually checked |
| 6 | Supply Chain, Logging, Exceptional | the audit gate, the security log, the write that rolls back |
The attack suite went from eleven tests to thirty, the feature suite to thirty-eight, and both stayed green through every part. The ZAP baseline went from eleven warnings to two, both understood and left on purpose, with no failures and sixty-five rules passing. composer audit is clean and gated in CI.
What the series was, and was not
It was a way of working, applied ten times: name the invariant as the attacker would break it, write the test that proves it from the other side, introduce the weakness the way a real codebase gets it, fix it at the layer that holds, keep the test, and let the scanner and the audit catch what tests are blind to. It was not a checklist, because a checklist tells you what to add and this told you how to know. The tools were ordinary and mostly already in the framework: a policy, route model binding, a bound query, an escaped echo, a hash, an encrypted cast, a rate limiter, a signed URL, a transaction, composer audit. What the series added is the order to reach for them and a test for each that fails before it passes.
The one honest limit is the one the scanner kept demonstrating: the automated tools found the headers and the versions and the dependency advisories, and were blind to every access-control, injection and authentication bug, which is most of the list. Those were found by tests written as the attacker, and writing those tests is the skill the whole series was really about. A tool runs the checklist; a person writes the test that the checklist could never contain.
The application, NoteMini, is in the shipbytes/blog-examples repository, one commit per part, with the attack suite, the feature suite, and the ZAP reports for every part under scans/. Clone it, run bin/dev attack, and turn a fix back off to watch its test go red: that is the series in one command.
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
6 / 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