Posts, projects and about-me all carry an image column that could only ever be filled by typing a URL by hand, so every featured image in the database is still a placeholder. Uploads are the missing half of content management. Filenames are generated rather than reused from the client, which is what keeps a double extension or a path traversal out of a web-served directory. The upload surface is restricted to raster formats (no SVG, which can carry script) with a size and dimension ceiling, and throttled at 12/min against the general admin API's 30/min because an upload costs far more than a JSON write. Routes move to per-feature files registered from bootstrap/app.php, since api.php had become a chokepoint for parallel work on this repo.
28 lines
1.2 KiB
PHP
28 lines
1.2 KiB
PHP
<?php
|
|
|
|
use App\Http\Controllers\Api\Admin\MediaController;
|
|
use Illuminate\Support\Facades\Route;
|
|
|
|
/*
|
|
|--------------------------------------------------------------------------
|
|
| Media upload
|
|
|--------------------------------------------------------------------------
|
|
| Registered from bootstrap/app.php. Kept apart from routes/api.php so the
|
|
| upload surface can be reviewed, throttled and locked down on its own.
|
|
|
|
|
| Uploads are far more expensive than a JSON write and are the most likely
|
|
| place for a disk-exhaustion attack, so this group gets its own, much
|
|
| tighter rate limit than the general admin API.
|
|
*/
|
|
|
|
Route::middleware(['auth:sanctum', 'admin', 'throttle:12,1'])->group(function () {
|
|
Route::post('admin/media', [MediaController::class, 'store']);
|
|
Route::delete('admin/media/{path}', [MediaController::class, 'destroy'])
|
|
// Dots are required for the extension, so traversal is refused by the
|
|
// `(?!.*\.\.)` lookahead rather than by simply omitting the character.
|
|
// The controller repeats the check; the pattern just keeps obvious
|
|
// probes from ever reaching the application.
|
|
->where('path', 'media\/(?!.*\.\.)[A-Za-z0-9_\-\/\.]+')
|
|
->name('admin.media.destroy');
|
|
});
|