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

@@ -516,10 +516,224 @@ class ScheduleCommandGuardTest extends TestCase
$response->assertJsonValidationErrors('command');
}
// ========================================================================
// Shell 인터프리터 정책 (KVE-2026-1653)
// ========================================================================
/**
* 게이트를 켜고 `bash` 등 인터프리터를 화이트리스트에 등록해도, 인터프리터에
* 인라인 명령/코드를 넘기는 저장 요청은 422 로 거부된다.
*
* KVE-2026-1653 본체: `bash` 를 화이트리스트에 등록하면 `bash -c id` 가 통과해
* 임의 OS 명령이 실행됐다. 이제 첫 인자가 하이픈(코드 플래그)이면 저장 시점에 거부된다.
*
* @param string $command 인라인 코드/명령 command
*
* @scenario command_class=inline_code, enforcement_point=store
*
* @effects inline_code_flags_rejected
*/
#[DataProvider('interpreterInlineCodeProvider')]
public function test_store_rejects_interpreter_inline_code_even_when_allowlisted(string $command): void
{
$this->enableInterpreterShell();
$response = $this->authRequest()->postJson(route('api.admin.schedules.store'), [
'name' => '인라인 코드 시도',
'type' => ScheduleType::Shell->value,
'command' => $command,
'expression' => '* * * * *',
'frequency' => 'everyMinute',
]);
$response->assertStatus(422, "인라인 코드가 저장됨: {$command}");
$response->assertJsonValidationErrors('command');
}
/**
* 인터프리터 + 절대경로 스크립트 실행은 게이트를 켜고 등록하면 201 로 허용된다
* (범용 크론 기능 회귀 가드).
*
* @param string $command 스크립트 파일 실행 command
*
* @scenario command_class=script_ok, enforcement_point=store
*
* @effects interpreter_script_files_still_run
*/
#[DataProvider('interpreterScriptProvider')]
public function test_store_allows_interpreter_running_absolute_script(string $command): void
{
$this->enableInterpreterShell();
$response = $this->authRequest()->postJson(route('api.admin.schedules.store'), [
'name' => '정상 스크립트 스케줄',
'type' => ScheduleType::Shell->value,
'command' => $command,
'expression' => '* * * * *',
'frequency' => 'everyMinute',
]);
$response->assertStatus(201, "정상 스크립트 실행이 거부됨: {$command}");
}
/**
* `php artisan ...` 를 shell 로 실행하려는 저장 요청은 422 로 거부된다 (Artisan 축 우회 방지).
*
* @param string $command artisan 우회 command
*
* @scenario command_class=artisan_bypass, enforcement_point=store
*
* @effects artisan_via_shell_rejected
*/
#[DataProvider('artisanBypassShellProvider')]
public function test_store_rejects_artisan_via_shell(string $command): void
{
$this->enableInterpreterShell();
$response = $this->authRequest()->postJson(route('api.admin.schedules.store'), [
'name' => 'artisan 우회 시도',
'type' => ScheduleType::Shell->value,
'command' => $command,
'expression' => '* * * * *',
'frequency' => 'everyMinute',
]);
$response->assertStatus(422, "artisan 우회가 저장됨: {$command}");
$response->assertJsonValidationErrors('command');
}
/**
* 완전 거부형 실행기(env/make/xargs/sudo/busybox)는 화이트리스트에 등재돼도 422 로 거부된다.
*
* @param string $command 완전 거부형 command
*
* @scenario command_class=reject_binary, enforcement_point=store
*
* @effects reject_binaries_blocked_even_when_allowlisted
*/
#[DataProvider('rejectBinaryShellProvider')]
public function test_store_rejects_reject_binaries_even_when_allowlisted(string $command): void
{
$this->enableInterpreterShell();
$response = $this->authRequest()->postJson(route('api.admin.schedules.store'), [
'name' => '완전 거부형 시도',
'type' => ScheduleType::Shell->value,
'command' => $command,
'expression' => '* * * * *',
'frequency' => 'everyMinute',
]);
$response->assertStatus(422, "완전 거부형이 저장됨: {$command}");
$response->assertJsonValidationErrors('command');
}
/**
* 기존 shell 스케줄의 command 만 인라인 코드로 바꾸는 update 요청도 거부된다.
*
* @scenario command_class=inline_code, enforcement_point=update
*
* @effects update_falls_back_to_the_stored_type_when_the_request_omits_it
*/
public function test_update_rejects_interpreter_inline_code_without_type_in_request(): void
{
$this->enableInterpreterShell();
$schedule = Schedule::create([
'name' => '기존 스크립트 스케줄',
'type' => ScheduleType::Shell,
'command' => 'bash /app/deploy.sh',
'expression' => '* * * * *',
'is_active' => true,
]);
$response = $this->authRequest()->putJson(
route('api.admin.schedules.update', ['schedule' => $schedule->id]),
['command' => 'bash -c id']
);
$response->assertStatus(422);
$response->assertJsonValidationErrors('command');
}
/**
* 게이트를 켜고 `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_blocks_interpreter_inline_code_injected_directly(): void
{
$this->enableInterpreterShell();
Process::fake();
$schedule = Schedule::create([
'name' => 'DB 직접 주입 — 인라인 코드',
'type' => ScheduleType::Shell,
'command' => 'bash -c id',
'expression' => '* * * * *',
'is_active' => true,
]);
$this->assertScheduleRunIsBlocked($schedule);
Process::assertNothingRan();
}
/**
* 슈퍼 관리자도 인터프리터 인라인 코드는 저장할 수 없다 (권한 분기 무관 동일 차단).
*
* @scenario command_class=inline_code, enforcement_point=store, caller_role=super_admin
*
* @effects inline_code_flags_rejected
*/
public function test_store_rejects_interpreter_inline_code_for_super_admin(): void
{
$this->enableInterpreterShell();
// 검증 계층까지 도달하도록 스케줄 권한을 갖춘 계정에 is_super 를 부여한다 —
// 슈퍼 관리자도 인라인 코드는 저장 단계에서 막힘을 증명하기 위함(권한 게이트가 아니라 검증).
$superAdmin = $this->createScheduleOperator();
$superAdmin->forceFill(['is_super' => true])->save();
$superToken = $superAdmin->createToken('super-token')->plainTextToken;
$response = $this->withHeaders([
'Authorization' => 'Bearer '.$superToken,
'Accept' => 'application/json',
])->postJson(route('api.admin.schedules.store'), [
'name' => '슈퍼 관리자 인라인 코드',
'type' => ScheduleType::Shell->value,
'command' => 'bash -c id',
'expression' => '* * * * *',
'frequency' => 'everyMinute',
]);
$response->assertStatus(422);
$response->assertJsonValidationErrors('command');
}
// ========================================================================
// Helpers
// ========================================================================
/**
* shell 게이트를 켜고 인터프리터·완전거부형을 화이트리스트에 등록합니다.
*
* 인터프리터를 **등재한 상태**로 검증해 "등재돼도 인라인코드/artisan/완전거부형은
* 차단됨" 을 증명한다 (범용 크론 용도로 인터프리터 등록은 정상 운영이다).
*/
private function enableInterpreterShell(): void
{
config([
'schedule_security.shell.enabled' => true,
'schedule_security.shell.allowed_binaries' => [
'bash', 'sh', 'python', 'python3', 'php', 'node', 'perl', 'ruby',
'env', 'make', 'xargs', 'sudo', 'busybox',
],
]);
}
/**
* 파서 분기 페이로드가 실행되었을 때 생성되는 마커 파일 경로.
*
@@ -736,4 +950,66 @@ class ScheduleCommandGuardTest extends TestCase
'SEO 레이아웃 지정' => ['seo:warmup --layout=home'],
];
}
/**
* 인터프리터에 인라인 코드/명령을 넘기는 command 목록 (전부 차단).
*
* @return array<string, array{string}>
*/
public static function interpreterInlineCodeProvider(): array
{
return [
'bash -c id (본체)' => ['bash -c id'],
'sh -c id' => ['sh -c id'],
'python -c 코드' => ['python -c import_os'],
'php -r 코드' => ['php -r phpinfo'],
'node -e 코드' => ['node -e process'],
'perl -e 코드' => ['perl -e system'],
'bash -x 스크립트 앞 옵션' => ['bash -x /app/x.sh'],
];
}
/**
* 인터프리터 + 절대경로 스크립트 command 목록 (전부 허용).
*
* @return array<string, array{string}>
*/
public static function interpreterScriptProvider(): array
{
return [
'python 스크립트' => ['python /app/job.py'],
'php 스크립트' => ['php /app/legacy.php'],
'node 스크립트' => ['node /app/worker.js'],
'스크립트 + 인자' => ['python /app/job.py --daily'],
];
}
/**
* shell 로 artisan 을 실행하려는 command 목록 (전부 차단).
*
* @return array<string, array{string}>
*/
public static function artisanBypassShellProvider(): array
{
return [
'php artisan' => ['php artisan'],
'php 절대경로 artisan' => ['php /var/www/html/artisan'],
];
}
/**
* 완전 거부형 실행기 command 목록 (전부 차단, 메타문자 없음).
*
* @return array<string, array{string}>
*/
public static function rejectBinaryShellProvider(): array
{
return [
'env bash' => ['env bash /app/x.sh'],
'make -f' => ['make -f /tmp/Makefile'],
'xargs' => ['xargs id'],
'sudo' => ['sudo id'],
'busybox' => ['busybox sh'],
];
}
}
@@ -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() - 관계 레코드 명시적 삭제 검증
// ========================================================================
@@ -139,6 +139,220 @@ class ScheduleCommandValidatorTest extends TestCase
$this->assertNull(ScheduleCommandValidator::tokenizeShellCommand(' '));
}
// ========================================================================
// Shell — 인터프리터 정책 (KVE-2026-1653)
// ========================================================================
/**
* 인터프리터에 인라인 코드/명령을 넘기는 형태는 화이트리스트에 등재돼 있어도 차단한다.
*
* KVE-2026-1653 본체: 운영자가 `bash` 를 화이트리스트에 등록하면 `bash -c id` 가
* 통과해 임의 OS 명령이 실행됐다. 스크립트 자리(첫 인자)가 하이픈이면 인라인 코드 플래그다.
*
* @param string $command 인라인 코드/명령을 넘기는 command
*
* @scenario command_class=inline_code, enforcement_point=validator_unit
*
* @effects inline_code_flags_rejected
*/
#[Test]
#[DataProvider('inlineCodeShellCommandProvider')]
public function it_blocks_inline_code_through_interpreters_even_when_allowlisted(string $command): void
{
$this->enableShell(self::interpreterBinaries());
$verdict = ScheduleCommandValidator::inspectShellCommand($command);
$this->assertFalse($verdict['allowed'], "인라인 코드가 통과함: {$command}");
$this->assertSame(ScheduleCommandValidator::SHELL_REASON_INLINE_CODE, $verdict['reason']);
}
/**
* 인터프리터 + 절대경로 스크립트 파일은 통과한다 (범용 크론 기능 회귀 가드).
*
* @param string $command 스크립트 파일을 실행하는 command
*
* @scenario command_class=script_ok, enforcement_point=validator_unit
*
* @effects interpreter_script_files_still_run
*/
#[Test]
#[DataProvider('interpreterScriptShellCommandProvider')]
public function it_allows_interpreters_running_absolute_path_scripts(string $command): void
{
$this->enableShell(self::interpreterBinaries());
$verdict = ScheduleCommandValidator::inspectShellCommand($command);
$this->assertTrue($verdict['allowed'], "정상 스크립트 실행이 차단됨: {$command}");
$this->assertNull($verdict['reason']);
}
/**
* 인터프리터 뒤 스크립트 자리가 artisan 이면 차단한다 (Artisan 축 우회 방지).
*
* @param string $command artisan 을 스크립트로 넘기는 command
*
* @scenario command_class=artisan_bypass, enforcement_point=validator_unit
*
* @effects artisan_via_shell_rejected
*/
#[Test]
#[DataProvider('artisanBypassShellCommandProvider')]
public function it_blocks_artisan_as_the_interpreter_script(string $command): void
{
$this->enableShell(self::interpreterBinaries());
$verdict = ScheduleCommandValidator::inspectShellCommand($command);
$this->assertFalse($verdict['allowed'], "artisan 우회가 통과함: {$command}");
$this->assertSame(ScheduleCommandValidator::SHELL_REASON_INTERPRETER, $verdict['reason']);
}
/**
* 완전 거부형 실행기는 화이트리스트에 등재돼 있어도 차단한다.
*
* env/awk/make/xargs/sudo/busybox 등은 첫 인자가 코드·감싼 명령이라 "스크립트 파일"
* 모델이 성립하지 않는다.
*
* @param string $command 완전 거부형 command
*
* @scenario command_class=reject_binary, enforcement_point=validator_unit
*
* @effects reject_binaries_blocked_even_when_allowlisted
*/
#[Test]
#[DataProvider('rejectBinaryShellCommandProvider')]
public function it_blocks_reject_binaries_even_when_allowlisted(string $command): void
{
$this->enableShell(self::interpreterBinaries());
$verdict = ScheduleCommandValidator::inspectShellCommand($command);
$this->assertFalse($verdict['allowed'], "완전 거부형이 통과함: {$command}");
$this->assertSame(ScheduleCommandValidator::SHELL_REASON_INTERPRETER, $verdict['reason']);
}
/**
* 인터프리터 뒤 스크립트 경로 형태 위반(상대경로 / `..` / `#`)은 차단한다.
*
* @param string $command 경로 형태 위반 command
*
* @scenario command_class=script_path, enforcement_point=validator_unit
*
* @effects script_path_traversal_rejected
*/
#[Test]
#[DataProvider('scriptPathShellCommandProvider')]
public function it_blocks_unsafe_interpreter_script_paths(string $command): void
{
$this->enableShell(self::interpreterBinaries());
$verdict = ScheduleCommandValidator::inspectShellCommand($command);
$this->assertFalse($verdict['allowed'], "안전하지 않은 경로가 통과함: {$command}");
$this->assertSame(ScheduleCommandValidator::SHELL_REASON_SCRIPT_PATH, $verdict['reason']);
}
/**
* 스크립트 없이 인터프리터만 등록하면(REPL/셸 기동) 차단한다.
*
* @param string $command 인자 없는 인터프리터 command
*
* @scenario command_class=no_script, enforcement_point=validator_unit
*
* @effects interpreter_without_script_rejected
*/
#[Test]
#[DataProvider('noScriptShellCommandProvider')]
public function it_blocks_interpreters_without_a_script(string $command): void
{
$this->enableShell(self::interpreterBinaries());
$verdict = ScheduleCommandValidator::inspectShellCommand($command);
$this->assertFalse($verdict['allowed'], "인자 없는 인터프리터가 통과함: {$command}");
$this->assertSame(ScheduleCommandValidator::SHELL_REASON_INTERPRETER, $verdict['reason']);
}
/**
* 인터프리터가 아닌 일반 스크립트는 종전처럼 통과한다 (기존 계약 보존 회귀 가드).
*
* @param string $command 일반 스크립트 command
*
* @scenario command_class=legit_plain_script, enforcement_point=validator_unit
*
* @effects plain_scripts_still_run_without_path_restrictions
*/
#[Test]
#[DataProvider('plainScriptShellCommandProvider')]
public function it_still_allows_plain_non_interpreter_scripts(string $command): void
{
$this->enableShell(['backup.sh']);
$verdict = ScheduleCommandValidator::inspectShellCommand($command);
$this->assertTrue($verdict['allowed'], "일반 스크립트가 차단됨: {$command}");
$this->assertNull($verdict['reason']);
}
/**
* 게이트가 꺼져 있으면 disabled 사유를 돌려준다.
*
* @scenario command_class=inline_code, enforcement_point=validator_unit
*
* @effects rejection_reason_is_reported_per_category
*/
#[Test]
public function it_reports_disabled_when_the_shell_gate_is_off(): void
{
config([
'schedule_security.shell.enabled' => false,
'schedule_security.shell.allowed_binaries' => ['bash'],
]);
$verdict = ScheduleCommandValidator::inspectShellCommand('bash /app/x.sh');
$this->assertFalse($verdict['allowed']);
$this->assertSame(ScheduleCommandValidator::SHELL_REASON_DISABLED, $verdict['reason']);
}
/**
* 화이트리스트 밖 명령은 not_allowlisted 사유를 돌려준다.
*
* @scenario command_class=inline_code, enforcement_point=validator_unit
*
* @effects rejection_reason_is_reported_per_category
*/
#[Test]
public function it_reports_not_allowlisted_for_unregistered_binaries(): void
{
$this->enableShell(['backup.sh']);
$verdict = ScheduleCommandValidator::inspectShellCommand('bash -c id');
$this->assertFalse($verdict['allowed']);
$this->assertSame(ScheduleCommandValidator::SHELL_REASON_NOT_ALLOWED, $verdict['reason']);
}
/**
* 메타문자가 섞인 명령은 metacharacter 사유를 돌려준다.
*
* @scenario command_class=reject_binary, enforcement_point=validator_unit
*
* @effects rejection_reason_is_reported_per_category
*/
#[Test]
public function it_reports_metacharacter_for_commands_with_shell_metacharacters(): void
{
$this->enableShell(self::interpreterBinaries());
$verdict = ScheduleCommandValidator::inspectShellCommand('awk \'BEGIN{system("id")}\'');
$this->assertFalse($verdict['allowed']);
$this->assertSame(ScheduleCommandValidator::SHELL_REASON_METACHARACTER, $verdict['reason']);
}
// ========================================================================
// Artisan — 차단목록
// ========================================================================
@@ -677,4 +891,137 @@ class ScheduleCommandValidatorTest extends TestCase
'옵션 구분자 단독' => ['cache:clear --', ScheduleCommandValidator::ARTISAN_REASON_MALFORMED],
];
}
// ========================================================================
// Data Providers — Shell 인터프리터 정책 (KVE-2026-1653)
// ========================================================================
/**
* 인터프리터 정책 테스트에서 화이트리스트에 등재하는 실행 파일 목록.
*
* 인터프리터·완전거부형을 **등재한 상태**로 판정해 "등재돼도 차단됨" 을 증명한다.
*
* @return array<int, string>
*/
private static function interpreterBinaries(): array
{
return [
'bash', 'sh', 'python', 'python3', 'php', 'node', 'perl', 'ruby',
'env', 'awk', 'make', 'xargs', 'sudo', 'busybox', 'sed',
'backup.sh',
];
}
/**
* 인터프리터에 인라인 코드/명령을 넘기는 command 목록 (전부 차단).
*
* @return array<string, array{string}>
*/
public static function inlineCodeShellCommandProvider(): array
{
return [
'bash -c id (본체)' => ['bash -c id'],
'sh -c id' => ['sh -c id'],
'python -c 코드' => ['python -c import_os'],
'python3 -c 코드' => ['python3 -c import_os'],
'php -r 코드' => ['php -r phpinfo'],
'node -e 코드' => ['node -e process'],
'perl -e 코드' => ['perl -e system'],
'ruby -e 코드' => ['ruby -e exec'],
'bash -x 스크립트 앞 옵션' => ['bash -x /app/x.sh'],
'python -m 모듈' => ['python -m http'],
];
}
/**
* 인터프리터 + 절대경로 스크립트 (전부 허용 — 범용 크론 회귀 가드).
*
* @return array<string, array{string}>
*/
public static function interpreterScriptShellCommandProvider(): array
{
return [
'python 스크립트' => ['python /app/job.py'],
'python3 스크립트' => ['python3 /app/job.py'],
'node 스크립트' => ['node /app/worker.js'],
'php 스크립트' => ['php /app/legacy.php'],
'bash 스크립트' => ['bash /app/deploy.sh'],
'ruby 스크립트' => ['ruby /app/task.rb'],
'perl 스크립트' => ['perl /app/task.pl'],
'스크립트 + 인자' => ['python /app/job.py --daily --verbose'],
];
}
/**
* 인터프리터 뒤 스크립트 자리가 artisan 인 command 목록 (전부 차단).
*
* @return array<string, array{string}>
*/
public static function artisanBypassShellCommandProvider(): array
{
return [
'php artisan tinker' => ['php artisan'],
'php 절대경로 artisan' => ['php /var/www/html/artisan'],
];
}
/**
* 완전 거부형 실행기 command 목록 (전부 차단, 메타문자 없음).
*
* @return array<string, array{string}>
*/
public static function rejectBinaryShellCommandProvider(): array
{
return [
'env bash' => ['env bash /app/x.sh'],
'make -f' => ['make -f /tmp/Makefile'],
'xargs' => ['xargs id'],
'sudo' => ['sudo id'],
'busybox' => ['busybox sh'],
'sed -e' => ['sed -e s/a/b/ /tmp/input.txt'],
];
}
/**
* 인터프리터 뒤 스크립트 경로 형태 위반 command 목록 (전부 차단).
*
* @return array<string, array{string}>
*/
public static function scriptPathShellCommandProvider(): array
{
return [
'상대경로 (python)' => ['python job.py'],
'상대경로 (php ./)' => ['php ./x.php'],
'트래버설' => ['php /app/../../tmp/x.php'],
'해시 위장' => ['php /app/x.php#foo'],
];
}
/**
* 스크립트 없이 인터프리터만 있는 command 목록 (전부 차단).
*
* @return array<string, array{string}>
*/
public static function noScriptShellCommandProvider(): array
{
return [
'bash 단독' => ['bash'],
'python 단독' => ['python'],
];
}
/**
* 인터프리터가 아닌 일반 스크립트 command 목록 (전부 허용 — 기존 계약 보존).
*
* @return array<string, array{string}>
*/
public static function plainScriptShellCommandProvider(): array
{
return [
'실행 파일 단독' => ['backup.sh'],
'인자 포함' => ['backup.sh --full /var/data'],
'절대경로 인자' => ['/usr/local/bin/backup.sh --full'],
'하이픈 인자 (일반 스크립트는 제한 없음)' => ['backup.sh -C /var/data'],
];
}
}
@@ -0,0 +1,76 @@
feature: 예약 작업 Shell 인터프리터 인라인 코드 우회 차단
description: |
Shell 타입 스케줄은 범용 크론탭 대체다 — 그누보드 밖의 python/node/php/bash 스크립트를
주기 실행할 수 있어야 한다. 그래서 인터프리터를 통째로 막지 않고 화이트리스트에 등록할 수
있게 둔다. 위험한 것은 인터프리터 자체가 아니라 인터프리터에게 인라인 코드/명령 문자열을
넘기는 것이다.
종전 `isShellCommandAllowed()` 는 첫 토큰 basename 만 화이트리스트와 대조하고 뒤 인자를
검증하지 않았다. 운영자가 `bash` 를 등록하면 `bash -c id` 가 통과해 임의 OS 명령이 실행됐다
(KVE-2026-1653). 이제 첫 토큰이 스크립트 실행형 인터프리터면 첫 인자(스크립트 자리)에
형태 규칙을 적용한다 — 하이픈 선두(인라인 코드 플래그) 거부, 절대경로 요구, `..`/`#` 금지,
basename≠artisan. 완전 거부형(env/awk/make/xargs/sudo/busybox 등)은 등재돼 있어도 거부한다.
인터프리터가 아닌 일반 스크립트(backup.sh 등)는 기존 계약대로 통과한다.
저장 시점(store/update Rule)과 실행 시점(runSchedule 마지막 방어선)이 같은 판정 함수
`inspectShellCommand()` 를 공유한다 — 한쪽만 고치면 DB 직접 수정이 우회로가 된다.
axes:
command_class: [inline_code, script_ok, artisan_bypass, reject_binary, script_path, no_script, legit_plain_script]
enforcement_point: [validator_unit, store, update, run]
cross_product: |
command_class × enforcement_point 이 핵심이다. 저장 시점과 실행 시점이 같은 판정 함수를
공유해야 하고(한쪽만 고치면 DB 직접 수정이 우회로가 된다), 명령 부류마다 거부 사유가 달라
운영자에게 보이는 메시지가 갈린다.
전 부류는 validator_unit 에서 전수 검증한다. store/update/run 은 같은 판정 함수를 호출할
뿐 별도 분기가 없으므로, HTTP·실행 계층에서는 대표 부류만 검증한다:
- store: inline_code(차단)·script_ok(허용)·artisan_bypass(차단)·reject_binary(차단)
- update: 저장된 타입 폴백 배선이 고유 축이므로 대표 1건(inline_code)
- run: 마지막 방어선의 대표 1건(inline_code) — Feature + Service 두 계층에서
caller_role(위임관리자 / 슈퍼관리자)은 별도 axis 로 두지 않는다. 판정은 권한과 무관한
단일 함수라 결과가 갈리지 않기 때문이다 — 슈퍼관리자도 인라인 코드를 저장할 수 없음을
대표 1건으로 고정한다(effects inline_code_flags_rejected).
exclusions:
- { command_class: script_path, enforcement_point: store, reason: "경로 형태 판정은 validator 단일 지점 — HTTP 계층은 같은 Rule 을 호출할 뿐 별도 분기 없음" }
- { command_class: no_script, enforcement_point: store, reason: "동일 — 판정 분기 없음" }
- { command_class: legit_plain_script, enforcement_point: store, reason: "동일 — 정상 스크립트 허용은 script_ok(store)가 대표" }
- { command_class: script_ok, enforcement_point: update, reason: "update 고유 축은 '요청에 type 없을 때 저장 타입 폴백' 배선 — 판정은 store 와 같은 Rule, 대표 1건(inline_code)으로 검증" }
- { command_class: artisan_bypass, enforcement_point: update, reason: "동일 — 대표 1건으로 검증" }
- { command_class: reject_binary, enforcement_point: update, reason: "동일 — 대표 1건으로 검증" }
- { command_class: script_path, enforcement_point: update, reason: "동일 — 대표 1건으로 검증" }
- { command_class: no_script, enforcement_point: update, reason: "동일 — 대표 1건으로 검증" }
- { command_class: legit_plain_script, enforcement_point: update, reason: "동일 — 대표 1건으로 검증" }
- { command_class: script_ok, enforcement_point: run, reason: "실행 시점 방어선의 대표는 inline_code — 허용 스크립트 실행 회귀는 store(script_ok)가 대표" }
- { command_class: artisan_bypass, enforcement_point: run, reason: "저장 시점에 거부되어 DB 에 남지 않는다. 실행 시점 대표는 inline_code" }
- { command_class: reject_binary, enforcement_point: run, reason: "동일 — 실행 시점 대표는 inline_code" }
- { command_class: script_path, enforcement_point: run, reason: "동일 — 실행 시점 대표는 inline_code" }
- { command_class: no_script, enforcement_point: run, reason: "동일 — 실행 시점 대표는 inline_code" }
- { command_class: legit_plain_script, enforcement_point: run, reason: "정상 스크립트 실행 자체는 기존 shell 실행 테스트가 이미 고정 — 본 기능의 신규 축이 아님" }
effects:
# 판정 — 인터프리터 정책
- inline_code_flags_rejected
- interpreter_script_files_still_run
- artisan_via_shell_rejected
- reject_binaries_blocked_even_when_allowlisted
- script_path_traversal_rejected
- interpreter_without_script_rejected
- plain_scripts_still_run_without_path_restrictions
- rejection_reason_is_reported_per_category
# 엔드투엔드 — 저장·실행 두 지점
- update_falls_back_to_the_stored_type_when_the_request_omits_it
- run_time_last_line_of_defense_blocks_inline_code
# E2E axis 없음: 판정은 전부 서버측이고 레이아웃 JSON·컴포넌트 TSX·엔진 TS 변경이 없다.
# 예약 작업 관리 화면은 config/core.php 에서 is_active=false 로 비노출 상태라 브라우저 경로
# 자체가 존재하지 않는다 (frontend-change-requires-e2e 룰의 대상이 아님).
test_files:
- tests/Unit/Support/ScheduleCommandValidatorTest.php
- tests/Feature/Security/ScheduleCommandGuardTest.php
- tests/Unit/Services/ScheduleServiceTest.php