laravelstudentsappwithinertia: Locked Page, Open API: A Two-Star Laravel App's Quiet Security Lesson
Inside jobic10/laravelstudentsappwithinertia, where the front door is guarded, the back door is missing, and the course name never became a foreign key.
- The Students page in jobic10/laravelstudentsappwithinertia sits behind auth while the API serving the same records has no guard at all, so the protection is cosmetic.
- Inertia's prop model exists to keep a page and its data on one guarded path, and reaching past it for a separate JSON API creates a second surface that is easy to forget.
- The same shortcut instinct shows up in a string course column that copies every course name instead of referencing it, so a rename or delete breaks student records silently.
- The repo reads as a clean January 2021 time capsule of Jetstream's launch month, which explains the mixed Bootstrap and Tailwind, the copied components, and the unfinished edges.
The Front Door Is Locked. The Back Door Isn't.
Two route files, two different ideas about who gets in. The web routes guard the page you look at. The API routes guard almost nothing.
// routes/web.php
Route::middleware(['auth:sanctum', 'verified'])->get('/students', function () {
return Inertia::render('Students');
})->name('students');
// routes/api.php
Route::middleware('auth:sanctum')->get('/user', function (Request $request) {
return $request->user();
});
Route::apiResource('students', 'App\Http\Controllers\StudentController');
Route::apiResource('courses', 'App\Http\Controllers\CourseController');
The first route is guarded twice over: a Sanctum guard and a verified email check. The second group is guarded by nothing. apiResource expands to index, store, show, update, and destroy for both students and courses, and every one of those endpoints answers an unauthenticated request.
So the page you have to log in to see, and the data you do not. Any client can list, create, modify, or delete every student record without ever logging in. The page is gated, but its data is not. The protection is cosmetic.
How Inertia Splits One Page Into Two Requests
Inertia's contract is simple. The server returns a page component name plus props, the client hydrates it, and the data arrives with the HTML. One request, one guard, one place to get it wrong. The whole point is that you never build a second data path.
This repo renders the Students shell with no props at all. So the page has to fetch its own data, and it calls /api/students from the client. That is a second request, down a second path, with its own middleware and its own guard. Two data paths for one screen, and only one of them got guarded.
The tell is in HandleInertiaRequests::share(). It merges the parent props with an empty array. That method is where global props like the authenticated user are supposed to live. Leaving it blank says props were never the plan.
The Course Name That Should Have Been a Foreign Key
The students table has a course column, and it is a string. The form sets each option's value to the course's name, so every student row stores a copy of a name that also lives in the courses table.
// create_students_table migration
$table->string('course');
$table->date('date_of_enrollment');
<!-- Students.vue -->
<option :value="course.course_name" v-for='course in courses' :key='course.id'>
Rename a course and every student still points at the old name. Delete a course and the students are orphaned with no error. Neither model declares belongsTo or hasMany, because there is no relationship to declare.
| Action | course string | Foreign key |
|---|---|---|
| Rename a course | Students keep the old name | Students follow the new name |
| Delete a course | Students silently orphaned | Restrict or cascade, by choice |
| Filter students by course | String match | Indexed join |
It is the same instinct as the open API. Reach for the simple thing, skip the constraint. A tutorial can afford it. Anything holding real records cannot.
A Time Capsule From January 2021
The repo was created on 2021-01-17, the same month Laravel Jetstream launched. That timing explains almost everything odd about it.
Tailwind arrives from Jetstream, and Bootstrap modal attributes (data-toggle="modal", data-target="#addStudent") sit on the same page. About thirty Jetstream components were copied into resources/js/Jetstream/. auth:sanctum guards a web route where plain auth would do. And response('Student Created', 201) returns plain text from an API that claims to speak JSON.
The unfinished edges belong to the same picture. find() calls are unchecked, so a missing ID throws a 500 instead of a 404. Features::api() is commented out in the config while API token permissions are still configured. The README is the untouched Laravel default. None of this is a failure of skill. It is a scaffold built fast and never revisited.
Props or API? A Decision Table
The repo's real error was not choosing an API. It was doing both without deciding. Here is how to decide.
| Dimension | Data via Inertia props | Data via separate JSON API |
|---|---|---|
| Auth surface | One guarded route | A second route that must be guarded separately |
| Initial page load | Data arrives with the HTML, no extra round trip | Shell loads, then a fetch fires |
| Client-side updates | Full page visits or Inertia partial reloads | Native fetch, no Inertia involvement |
| Coupling | Page and data move together | Page and data can drift apart |
| Failure mode | Missing prop, visible immediately | Unguarded endpoint, invisible until someone finds it |
The last row is the point. When data flows through props, a missing prop is visible the moment you load the page. When it flows through a separate endpoint, an unguarded one is invisible until someone goes looking.
What to Steal, What to Avoid
- Steal the manual attribute assignment. It sidesteps mass-assignment risk by accident, even if it is verbose.
- Steal the Fortify rate limiters on login and two-factor. Sensible defaults, left in place.
- Steal the global
route()mixin. It brings the Laravel routing idiom to every component. - Avoid the unguarded API. If a screen needs a separate endpoint, guard the endpoint.
- Avoid the string
coursecolumn. Use a foreign key and let the database hold the line. - Avoid the empty
share(). If you are not sharing props, you are not using Inertia as intended.





