fix(security): 스케줄 셸 인터프리터 인라인 코드 우회 차단

셸 스케줄 검증이 첫 토큰 basename 만 화이트리스트와 대조하고 뒤 인자를
검증하지 않아, 운영자가 bash 를 등록하면 `bash -c id` 로 임의 OS 명령이
실행됐다(KVE-2026-1653). 인터프리터는 범용 크론 용도로 등록을 허용하되,
스크립트 자리(첫 인자)에 형태 규칙을 적용해 인라인 코드·상대경로·트래버설·
artisan 우회·완전거부형(env/awk/make 등)을 저장·실행 양쪽에서 거부한다.
This commit is contained in:
HeuJung committed 2026-08-17 20:59:42 +09:00
1 parent 19424877e8
commit 2fb452aa44
12 files changed
+955 -7

No files matched your search

@@ -2,6 +2,7 @@
namespace Tests\Unit\Services;
use App\Enums\ScheduleResultStatus;
use App\Enums\ScheduleType;
use App\Extension\HookManager;
use App\Models\Schedule;
@@ -9,6 +10,8 @@ use App\Models\ScheduleHistory;
use App\Services\ScheduleService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Facades\Process;
use Illuminate\Validation\ValidationException;
use Tests\TestCase;
/**
@@ -87,6 +90,45 @@ class ScheduleServiceTest extends TestCase
$this->assertSame(1, $result->total());
}
// ========================================================================
// runSchedule() - 실행 직전 방어선 (KVE-2026-1653)
// ========================================================================
/**
* 게이트를 켜고 `bash` 를 등록한 상태라도, DB 에 직접 심어진 `bash -c id` 는
* 실행 직전 방어선에서 차단된다 (저장 검증을 우회해 들어온 값 방어).
*
* @scenario command_class=inline_code, enforcement_point=run
*
* @effects run_time_last_line_of_defense_blocks_inline_code
*/
public function test_run_schedule_blocks_interpreter_inline_code(): void
{
config([
'schedule_security.shell.enabled' => true,
'schedule_security.shell.allowed_binaries' => ['bash'],
]);
Process::fake();
$schedule = Schedule::create([
'name' => 'DB 직접 주입 — 인라인 코드',
'type' => ScheduleType::Shell,
'command' => 'bash -c id',
'expression' => '* * * * *',
'is_active' => true,
]);
try {
$this->scheduleService->runSchedule($schedule);
$this->fail('인라인 코드 스케줄이 실행됨');
} catch (ValidationException) {
// 실행 직전 방어선이 차단 — 아래에서 미실행·실패 기록을 확인한다
}
Process::assertNothingRan();
$this->assertSame(ScheduleResultStatus::Failed, $schedule->fresh()->last_result);
}
// ========================================================================
// delete() - 관계 레코드 명시적 삭제 검증
// ========================================================================