fix(security): 스케줄러 Shell/Artisan 명령 실행 하드닝
미출시 예약 작업 기능에서 스케줄 권한만 위임받은 계정이 Shell/Artisan 명령으로 임의 코드를 실행할 수 있던 문제를 선제적으로 차단(KVE-2026-1567). Shell 은 기본 차단 + 실행 파일 화이트리스트 + 셸 미경유 인자배열 실행, Artisan 은 차단목록. 저장 시점(FormRequest)과 실행 시점(Service) 이중 검증. 아울러 공개 release 보다 앞선 미출시 버전들의 CHANGELOG 출시 날짜를 2026-07-14 로 통일.
This commit is contained in:
1 parent
4c73db2e91
commit
ce8e55b390
23 files changed
+957
-25
No files matched your search
@@ -11,8 +11,8 @@ use App\Extension\HookManager;
|
||||
use App\Models\Schedule;
|
||||
use App\Models\ScheduleHistory;
|
||||
use App\Support\OutboundUrlValidator;
|
||||
use App\Support\ScheduleCommandValidator;
|
||||
use Exception;
|
||||
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
@@ -207,10 +207,13 @@ class ScheduleService
|
||||
'output' => $result['output'] ?? null,
|
||||
]);
|
||||
|
||||
// 스케줄 상태 업데이트
|
||||
// 스케줄 상태 업데이트 (다음 실행 시각은 모델이 계산, 영속화는 Repository 경유)
|
||||
$schedule->last_result = ScheduleResultStatus::Success;
|
||||
$schedule->calculateNextRunAt();
|
||||
$schedule->save();
|
||||
$this->scheduleRepository->update($schedule, [
|
||||
'last_result' => ScheduleResultStatus::Success,
|
||||
'next_run_at' => $schedule->next_run_at,
|
||||
]);
|
||||
|
||||
// after_run 훅 실행
|
||||
HookManager::doAction('core.schedule.after_run', $schedule, $history);
|
||||
@@ -226,10 +229,13 @@ class ScheduleService
|
||||
'error_output' => $e->getMessage(),
|
||||
]);
|
||||
|
||||
// 스케줄 상태 업데이트
|
||||
// 스케줄 상태 업데이트 (다음 실행 시각은 모델이 계산, 영속화는 Repository 경유)
|
||||
$schedule->last_result = ScheduleResultStatus::Failed;
|
||||
$schedule->calculateNextRunAt();
|
||||
$schedule->save();
|
||||
$this->scheduleRepository->update($schedule, [
|
||||
'last_result' => ScheduleResultStatus::Failed,
|
||||
'next_run_at' => $schedule->next_run_at,
|
||||
]);
|
||||
|
||||
Log::error('Schedule execution failed', [
|
||||
'schedule_id' => $schedule->id,
|
||||
@@ -247,10 +253,16 @@ class ScheduleService
|
||||
*
|
||||
* @param Schedule $schedule 스케줄
|
||||
* @return array 실행 결과
|
||||
*
|
||||
* @throws Exception 차단목록에 걸린 명령일 때
|
||||
*/
|
||||
private function executeArtisanCommand(Schedule $schedule): array
|
||||
{
|
||||
$output = '';
|
||||
// 저장 시점 검증 도입 이전 데이터나 DB 직접 수정으로 들어온 값을 방어한다
|
||||
// (isUrlCallAllowed 와 동일 사유 — 실행 직전이 마지막 방어선).
|
||||
if (! ScheduleCommandValidator::isArtisanCommandAllowed($schedule->command)) {
|
||||
throw new Exception(__('schedule.artisan_not_allowed'));
|
||||
}
|
||||
|
||||
Artisan::call($schedule->command, [], new BufferedOutput);
|
||||
|
||||
@@ -270,9 +282,19 @@ class ScheduleService
|
||||
*/
|
||||
private function executeShellCommand(Schedule $schedule): array
|
||||
{
|
||||
// 저장 시점 검증 도입 이전 데이터나 DB 직접 수정으로 들어온 값을 방어한다
|
||||
// (isUrlCallAllowed 와 동일 사유 — 실행 직전이 마지막 방어선).
|
||||
$arguments = ScheduleCommandValidator::tokenizeShellCommand($schedule->command);
|
||||
|
||||
if ($arguments === null || ! ScheduleCommandValidator::isShellCommandAllowed($schedule->command)) {
|
||||
throw new Exception(__('schedule.shell_not_allowed'));
|
||||
}
|
||||
|
||||
$timeout = $schedule->timeout ?? 60;
|
||||
|
||||
$result = Process::timeout($timeout)->run($schedule->command);
|
||||
// 문자열이 아닌 인자 배열로 넘겨 `/bin/sh -c` 를 경유하지 않는다 —
|
||||
// 파이프·`;`·`$()` 같은 셸 메타문자가 명령으로 해석될 여지를 없앤다.
|
||||
$result = Process::timeout($timeout)->run($arguments);
|
||||
|
||||
if ($result->failed()) {
|
||||
throw new Exception($result->errorOutput() ?: __('schedule.shell_command_failed'), $result->exitCode());
|
||||
|
||||
Reference in new issue
Block a user