refactor(cli): validate --date and escape shell args on logs:scheduled

Reject malformed --date values with a clear error before building any
shell command, and wrap every interpolated value (log paths, filter
expression, line count) in escapeshellarg() so filter options and date
values can no longer break out of the tail/grep pipeline.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Andras BacsaiandClaude Opus 4.7 committed 2026-04-20 12:09:48 +02:00
1 parent 49b5472961
commit bb0c3501ef
2 files changed
+55 -10

No files matched your search

@@ -0,0 +1,35 @@
<?php
use App\Console\Commands\ViewScheduledLogs;
use App\Http\Middleware\CheckForcePasswordReset;
use App\Http\Middleware\DecideWhatToDoWithUser;
use App\Models\InstanceSettings;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Once;
uses(RefreshDatabase::class);
beforeEach(function () {
$this->withoutMiddleware([DecideWhatToDoWithUser::class, CheckForcePasswordReset::class]);
Once::flush();
if (! InstanceSettings::find(0)) {
$settings = new InstanceSettings;
$settings->id = 0;
$settings->saveQuietly();
}
});
describe('logs:scheduled --date option', function () {
test('rejects a malformed date and exits before touching the shell', function () {
$this->artisan('logs:scheduled', ['--date' => '2025-01-01; touch /tmp/pwn'])
->expectsOutputToContain('Invalid date format')
->assertExitCode(ViewScheduledLogs::INVALID);
expect(file_exists('/tmp/pwn'))->toBeFalse();
});
test('accepts a well-formed date', function () {
$this->artisan('logs:scheduled', ['--date' => '2025-01-01'])
->assertExitCode(0);
});
});