fix(core,board,ecommerce,payments,basic): KVE-2026 보안 게이트 6묶음 + 자격증명 전송로 정합
KISA 제보 취약점(KVE-2026-1914/1919/2019/2029/2041/2042/2043/2044)과 그 수정 과정에서 드러난 자격증명 전송로 결함을 함께 해소한다. globalHeaders 는 데이터소스와 apiCall 핸들러에만 적용되는데, 코어 ApiClient 를 직접 부르는 경로들이 그 사실을 모른 채 게이트된 엔드포인트를 호출하고 있었다. 서버는 정당한 사용자를 거부하고 화면은 이미 버튼을 내준 뒤라, 예외도 로그도 없이 그 자리만 비는 형태로만 드러났다. 전송로 10축을 전수 열거해 6건을 고치고, 같은 실수가 반복되지 않도록 규정과 coverage 에 등재했다. 아웃바운드 프록시가 사이트 자기 자신으로 가는 내부 요청까지 가로채 저장이 수십 초씩 걸리던 문제도 함께 고쳤다. 실패가 폴백으로 삼켜져 화면에는 지연으로만 나타났다.
This commit is contained in:
1 parent
8f072895ff
commit
9cf9c3ff8c
104 files changed
+4522
-412
No files matched your search
@@ -156,6 +156,63 @@ class BinaryPathPolicyTest extends TestCase
|
||||
$this->assertTrue(installer_is_composer_binary_path('/usr/local/php99/bin/composer'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 검증 지점과 실행 지점이 같은 정책 파일을 쓰는지 확인합니다.
|
||||
*
|
||||
* 정책이 한 파일에 있어도 어느 한 진입점이 그 파일을 require 하지 않으면
|
||||
* "저장은 막히는데 실행은 통과" 같은 어긋난 상태가 남고, 그 어긋남은 오류를
|
||||
* 남기지 않는다. 그래서 파일 참조 자체를 계약으로 고정한다 (KVE-2026-2043).
|
||||
*/
|
||||
#[Test]
|
||||
public function validation_and_execution_entrypoints_share_the_same_policy_file(): void
|
||||
{
|
||||
$projectRoot = dirname(__DIR__, 3);
|
||||
|
||||
$entrypoints = [
|
||||
'api/check-configuration.php' => $projectRoot.'/public/install/api/check-configuration.php',
|
||||
'includes/task-runner.php' => $projectRoot.'/public/install/includes/task-runner.php',
|
||||
'includes/request-handler.php' => $projectRoot.'/public/install/includes/request-handler.php',
|
||||
];
|
||||
|
||||
foreach ($entrypoints as $label => $path) {
|
||||
$this->assertFileExists($path, "정책 소비 진입점이 사라졌다: {$label}");
|
||||
$this->assertStringContainsString(
|
||||
'binary-path-policy.php',
|
||||
(string) file_get_contents($path),
|
||||
"{$label} 이 공용 정책을 로드하지 않는다 — 자체 판정으로 갈라지면 우회로가 된다"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* UNC·임의 phar 는 (PHP, Composer) 쌍 해석에서도 거부된다.
|
||||
*
|
||||
* 쌍 해석은 자리별 규칙을 재사용하므로 여기서도 같은 결론이 나와야 한다 —
|
||||
* 한쪽만 막히면 그 경로가 우회로가 된다.
|
||||
*/
|
||||
#[Test]
|
||||
public function the_pair_resolver_rejects_unc_and_arbitrary_phar(): void
|
||||
{
|
||||
$this->assertNull(
|
||||
installer_resolve_php_composer_pair('\\\\server\\share\\php.exe /usr/local/bin/composer'),
|
||||
'UNC PHP 경로가 쌍 해석에서 통과했다'
|
||||
);
|
||||
$this->assertNull(
|
||||
installer_resolve_php_composer_pair('/usr/bin/php \\\\server\\share\\composer.phar'),
|
||||
'UNC Composer 경로가 쌍 해석에서 통과했다'
|
||||
);
|
||||
$this->assertNull(
|
||||
installer_resolve_php_composer_pair('/usr/bin/php /tmp/evil.phar'),
|
||||
'임의 이름 phar 가 쌍 해석에서 통과했다'
|
||||
);
|
||||
|
||||
// 정상 조합은 그대로 동작한다 (회귀 방지).
|
||||
$this->assertSame(
|
||||
['php' => '/usr/bin/php', 'composer' => '/usr/local/bin/composer.phar'],
|
||||
installer_resolve_php_composer_pair('/usr/bin/php /usr/local/bin/composer.phar')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 통과해야 하는 토큰 목록.
|
||||
*
|
||||
@@ -171,7 +228,6 @@ class BinaryPathPolicyTest extends TestCase
|
||||
'Plesk 경로' => ['/opt/plesk/php/8.2/bin/php', '패널 환경'],
|
||||
'Windows 드라이브' => ['C:\\php\\php.exe', 'Windows'],
|
||||
'Windows 슬래시' => ['C:/php/php.exe', 'Windows 정방향 슬래시'],
|
||||
'UNC 경로' => ['\\\\server\\share\\php.exe', '네트워크 공유'],
|
||||
'점 포함 디렉토리' => ['/usr/local/php.d/bin/php', '단일 점은 상위 참조가 아님'],
|
||||
];
|
||||
}
|
||||
@@ -200,6 +256,12 @@ class BinaryPathPolicyTest extends TestCase
|
||||
'따옴표' => ['/usr/bin/"php"', '셸 메타문자'],
|
||||
'개행' => ["/usr/bin/php\nid", '제어문자'],
|
||||
'NUL 바이트' => ["/usr/bin/php\x00", '제어문자'],
|
||||
// KVE-2026-2043: UNC 경로는 공격자가 지정한 원격 SMB 공유의 파일을 실행하게 만든다.
|
||||
'UNC 경로' => ['\\\\server\\share\\php.exe', '원격 공유 실행 — KVE-2026-2043'],
|
||||
'UNC 정방향 슬래시' => ['//server/share/php.exe', '원격 공유 실행'],
|
||||
'phar 스트림 래퍼' => ['phar:///tmp/evil.phar/run', 'stream wrapper'],
|
||||
'http 스트림 래퍼' => ['http://evil.example.com/x', 'stream wrapper'],
|
||||
'file 스트림 래퍼' => ['file:///usr/bin/php', 'stream wrapper'],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -215,7 +277,9 @@ class BinaryPathPolicyTest extends TestCase
|
||||
'절대경로 composer' => ['/usr/local/bin/composer', true, '일반 설치'],
|
||||
'composer2' => ['/usr/local/bin/composer2', true, '버전 붙은 이름'],
|
||||
'composer.phar' => ['/opt/composer.phar', true, 'phar 아카이브'],
|
||||
'임의 이름 phar' => ['/opt/tools/mytool.phar', true, 'phar 는 이름 무관 허용'],
|
||||
// KVE-2026-2043: 임의 이름 .phar 허용은 업로드된 아카이브를 그대로 실행시킨다.
|
||||
'임의 이름 phar' => ['/opt/tools/mytool.phar', false, '이름이 composer 계열이 아닌 phar'],
|
||||
'composerN.phar' => ['/opt/composer2.phar', true, '버전 붙은 composer phar'],
|
||||
'composer.bat' => ['C:\\laragon\\bin\\composer\\composer.bat', true, 'Windows 배치'],
|
||||
'composer.exe' => ['C:\\tools\\composer.exe', true, 'Windows 실행 파일'],
|
||||
'임의 스크립트' => ['/tmp/evil.py', false, '인터프리터가 실행할 임의 스크립트 — 이번 취약점'],
|
||||
|
||||
@@ -0,0 +1,153 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Installer;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* 인스톨러 .env 값 직렬화 테스트 (KVE-2026-2042).
|
||||
*
|
||||
* 회귀 배경: `.env` 는 줄 단위 형식이라 사용자 입력에 개행이 섞이면 그 뒤가 새로운
|
||||
* 환경변수 줄로 해석된다. 기존 escapeEnvValue() 는 개행을 조용히 지웠고 그마저도
|
||||
* 일부 값(호스트·DB명·앱 이름·업데이트 URL 등)에는 적용되지 않아, 설치 창이 열려 있는
|
||||
* 동안 임의 환경변수를 주입할 수 있었다.
|
||||
*
|
||||
* 정책: 직렬화기는 CR/LF/NUL 을 만나면 예외를 던진다(조용한 삭제 금지 — 삭제하면
|
||||
* 운영자가 자기가 입력한 값과 다른 값이 저장된 것을 알 수 없다). 값 전달 경로가
|
||||
* 하나이므로 새 필드가 추가돼도 같은 관문을 지난다.
|
||||
*
|
||||
* 정책 파일은 의존성이 없어야 한다 — 인스톨러 본 흐름과 워커 양쪽에서 단독으로
|
||||
* require 되므로, 이 테스트도 BASE_PATH·lang 스텁 없이 파일만 로드한다.
|
||||
*/
|
||||
class EnvValueSerializationTest extends TestCase
|
||||
{
|
||||
public static function setUpBeforeClass(): void
|
||||
{
|
||||
require_once dirname(__DIR__, 3).'/public/install/includes/env-value.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* 정상 값은 큰따옴표로 감싸 반환된다.
|
||||
*/
|
||||
#[Test]
|
||||
public function it_quotes_a_normal_value(): void
|
||||
{
|
||||
$this->assertSame('"g7"', serializeEnvValue('g7'));
|
||||
$this->assertSame('"127.0.0.1"', serializeEnvValue('127.0.0.1'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 빈 값은 빈 따옴표로 반환된다 (기존 동작 보존).
|
||||
*/
|
||||
#[Test]
|
||||
public function it_returns_empty_quotes_for_an_empty_value(): void
|
||||
{
|
||||
$this->assertSame('""', serializeEnvValue(''));
|
||||
}
|
||||
|
||||
/**
|
||||
* 큰따옴표와 백슬래시는 이스케이프된다 (기존 동작 보존).
|
||||
*/
|
||||
#[Test]
|
||||
public function it_escapes_quotes_and_backslashes(): void
|
||||
{
|
||||
$this->assertSame('"a\\\\b"', serializeEnvValue('a\\b'));
|
||||
$this->assertSame('"say \\"hi\\""', serializeEnvValue('say "hi"'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 줄바꿈·NUL 이 섞인 값은 예외로 거부된다 (조용한 삭제 금지).
|
||||
*
|
||||
* @param string $value 주입 시도 값
|
||||
* @param string $reason 거부 사유 (실패 메시지용)
|
||||
*/
|
||||
#[Test]
|
||||
#[DataProvider('lineBreakInjectionProvider')]
|
||||
public function it_rejects_values_containing_line_breaks_or_nul(string $value, string $reason): void
|
||||
{
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
|
||||
serializeEnvValue($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 개행 주입 벡터.
|
||||
*
|
||||
* @return array<string, array{0: string, 1: string}>
|
||||
*/
|
||||
public static function lineBreakInjectionProvider(): array
|
||||
{
|
||||
return [
|
||||
'LF 로 새 변수 줄 주입' => ["g7\nAPP_DEBUG=true", 'LF'],
|
||||
'CR 로 새 변수 줄 주입' => ["g7\rAPP_DEBUG=true", 'CR'],
|
||||
'CRLF 로 새 변수 줄 주입' => ["g7\r\nAPP_DEBUG=true", 'CRLF'],
|
||||
'NUL 바이트' => ["g7\0APP_DEBUG=true", 'NUL'],
|
||||
'선두 개행' => ["\nAPP_DEBUG=true", 'leading LF'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 개행 검사는 값 전체를 본다 — 따옴표 안에 숨겨도 거부된다.
|
||||
*/
|
||||
#[Test]
|
||||
public function it_rejects_line_breaks_even_inside_quotes(): void
|
||||
{
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
|
||||
serializeEnvValue("\"g7\"\nAPP_DEBUG=true");
|
||||
}
|
||||
|
||||
/**
|
||||
* 하위호환 별칭 `escapeEnvValue` 의 두 정의가 모두 단일 관문에 위임한다.
|
||||
*
|
||||
* 종전 구현은 개행을 **조용히 지웠다**. 그 동작이 어느 한쪽에라도 남아 있으면 다음
|
||||
* 호출자가 그 이름을 불러 같은 결함을 다시 들여온다 — 실제로 과거 KVE 수정들이
|
||||
* "한쪽만 고쳐서" 재수정된 이력이 있다.
|
||||
*
|
||||
* 함수를 실행해 대조하지 않고 소스를 검사하는 이유: 두 정의는 BASE_PATH 상수를
|
||||
* 요구하는 파일에 있고, 그 상수를 여기서 박으면 인접 Installer 테스트의 안전 가드가
|
||||
* 걸려 그 테스트들이 조용히 skip 된다(초록인데 검사는 멈춘 상태가 된다).
|
||||
*/
|
||||
#[Test]
|
||||
public function both_legacy_alias_definitions_delegate_to_the_single_gate(): void
|
||||
{
|
||||
$projectRoot = dirname(__DIR__, 3);
|
||||
|
||||
$definitions = [
|
||||
'includes/functions.php' => $projectRoot.'/public/install/includes/functions.php',
|
||||
'includes/installer-runtime.php' => $projectRoot.'/public/install/includes/installer-runtime.php',
|
||||
];
|
||||
|
||||
foreach ($definitions as $label => $path) {
|
||||
$source = (string) file_get_contents($path);
|
||||
|
||||
$this->assertMatchesRegularExpression(
|
||||
'/function escapeEnvValue\(string \$value\): string\s*\{[^}]*return serializeEnvValue\(\$value\);/s',
|
||||
$source,
|
||||
"{$label} 의 escapeEnvValue 가 단일 관문에 위임하지 않는다"
|
||||
);
|
||||
|
||||
$this->assertStringNotContainsString(
|
||||
'str_replace(["\r", "\n"], \'\', $value)',
|
||||
$source,
|
||||
"{$label} 에 개행을 조용히 지우는 경로가 남아 있다 — 그 이름을 부르면 결함이 재유입된다"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 개행이 없는 값은 검사기가 통과시킨다.
|
||||
*/
|
||||
#[Test]
|
||||
public function the_line_break_checker_accepts_clean_values(): void
|
||||
{
|
||||
$this->assertTrue(installer_env_value_is_single_line('https://github.com/gnuboard/g7'));
|
||||
$this->assertTrue(installer_env_value_is_single_line(''));
|
||||
$this->assertFalse(installer_env_value_is_single_line("a\nb"));
|
||||
$this->assertFalse(installer_env_value_is_single_line("a\rb"));
|
||||
$this->assertFalse(installer_env_value_is_single_line("a\0b"));
|
||||
}
|
||||
}
|
||||
@@ -312,12 +312,13 @@ ENV;
|
||||
|
||||
$merged = mergeRuntimeIntoEnv($envContent, $runtime);
|
||||
|
||||
$this->assertStringContainsString('DB_WRITE_HOST=real-host.example.com', $merged);
|
||||
$this->assertStringContainsString('DB_WRITE_PORT=3307', $merged);
|
||||
$this->assertStringContainsString('DB_WRITE_DATABASE=real_db', $merged);
|
||||
$this->assertStringContainsString('DB_WRITE_USERNAME=real_user', $merged);
|
||||
// 값은 전부 serializeEnvValue 를 지나 따옴표로 감싸진다 (개행 주입 차단 관문 일원화).
|
||||
$this->assertStringContainsString('DB_WRITE_HOST="real-host.example.com"', $merged);
|
||||
$this->assertStringContainsString('DB_WRITE_PORT="3307"', $merged);
|
||||
$this->assertStringContainsString('DB_WRITE_DATABASE="real_db"', $merged);
|
||||
$this->assertStringContainsString('DB_WRITE_USERNAME="real_user"', $merged);
|
||||
$this->assertStringContainsString('DB_WRITE_PASSWORD="real_pass"', $merged);
|
||||
$this->assertStringContainsString('DB_PREFIX=real_', $merged);
|
||||
$this->assertStringContainsString('DB_PREFIX="real_"', $merged);
|
||||
|
||||
// Read 라인도 write 와 동기화되어 치환되어야 함
|
||||
$this->assertStringNotContainsString('DB_WRITE_HOST=127.0.0.1', $merged);
|
||||
@@ -350,10 +351,10 @@ ENV;
|
||||
$this->assertStringContainsString("DB_READ_HOST=\n", $merged);
|
||||
$this->assertStringContainsString("DB_READ_DATABASE=\n", $merged);
|
||||
$this->assertStringContainsString("DB_READ_USERNAME=\n", $merged);
|
||||
$this->assertStringNotContainsString('DB_READ_HOST=w-host', $merged);
|
||||
$this->assertStringNotContainsString('DB_READ_DATABASE=wdb', $merged);
|
||||
$this->assertStringNotContainsString('DB_READ_HOST="w-host"', $merged);
|
||||
$this->assertStringNotContainsString('DB_READ_DATABASE="wdb"', $merged);
|
||||
// write 라인은 정상 기록
|
||||
$this->assertStringContainsString('DB_WRITE_HOST=w-host', $merged);
|
||||
$this->assertStringContainsString('DB_WRITE_HOST="w-host"', $merged);
|
||||
}
|
||||
|
||||
public function test_merge_uses_separate_read_when_specified(): void
|
||||
@@ -369,8 +370,8 @@ ENV;
|
||||
|
||||
$merged = mergeRuntimeIntoEnv($envContent, $runtime);
|
||||
|
||||
$this->assertStringContainsString('DB_READ_HOST=r-host', $merged);
|
||||
$this->assertStringContainsString('DB_READ_DATABASE=rdb', $merged);
|
||||
$this->assertStringContainsString('DB_READ_HOST="r-host"', $merged);
|
||||
$this->assertStringContainsString('DB_READ_DATABASE="rdb"', $merged);
|
||||
}
|
||||
|
||||
public function test_merge_appends_db_lines_when_absent_from_template(): void
|
||||
@@ -392,8 +393,8 @@ ENV;
|
||||
$merged = mergeRuntimeIntoEnv($envContent, $runtime);
|
||||
|
||||
// .env.example 에 라인이 없는 비표준 케이스 — 끝에 추가
|
||||
$this->assertStringContainsString('DB_WRITE_HOST=h', $merged);
|
||||
$this->assertStringContainsString('DB_WRITE_DATABASE=d', $merged);
|
||||
$this->assertStringContainsString('DB_WRITE_HOST="h"', $merged);
|
||||
$this->assertStringContainsString('DB_WRITE_DATABASE="d"', $merged);
|
||||
}
|
||||
|
||||
public function test_merge_preserves_db_lines_when_runtime_has_no_db(): void
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Tests\Unit\Installer;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use ReflectionClass;
|
||||
use ValidationApi;
|
||||
@@ -484,29 +485,25 @@ class InstallerSecurityHardeningTest extends TestCase
|
||||
}
|
||||
|
||||
// ========================================================================
|
||||
// Medium-1 — escapeEnvValue 개행 제거
|
||||
// Medium-1 — escapeEnvValue 개행 거부
|
||||
// ========================================================================
|
||||
//
|
||||
// 종전에는 개행을 조용히 지웠다(Medium-1). KVE-2026-2042 정정으로 직렬화기는 개행을
|
||||
// 만나면 예외를 던진다 — 지우면 운영자가 입력한 값과 저장된 값이 달라지는데 그 사실이
|
||||
// 화면에 나타나지 않기 때문이다. 하위호환 별칭 escapeEnvValue 도 같은 관문에 위임한다.
|
||||
|
||||
public function test_escape_env_value_strips_newlines(): void
|
||||
public function test_escape_env_value_rejects_newlines(): void
|
||||
{
|
||||
$payload = "secret\nINJECTED=true";
|
||||
$result = escapeEnvValue($payload);
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
|
||||
// 핵심 보안 속성: 결과에 개행 문자가 없어야 한다 (라인 주입 차단).
|
||||
// INJECTED=true 가 따옴표 내부 일부로 포함되는 것은 문제 아님 — .env 파서는
|
||||
// 따옴표 닫힘 전까지 단일 값으로만 해석.
|
||||
$this->assertStringNotContainsString("\n", $result, 'LF 가 결과에 포함되면 안 됨');
|
||||
$this->assertStringNotContainsString("\r", $result);
|
||||
// 결과는 따옴표로 시작/종료 (라인 주입이 성립하려면 따옴표가 닫힌 뒤 개행이 와야 하나 개행이 제거됨)
|
||||
$this->assertStringStartsWith('"', $result);
|
||||
$this->assertStringEndsWith('"', $result);
|
||||
escapeEnvValue("secret\nINJECTED=true");
|
||||
}
|
||||
|
||||
public function test_escape_env_value_strips_crlf(): void
|
||||
public function test_escape_env_value_rejects_crlf(): void
|
||||
{
|
||||
$result = escapeEnvValue("a\r\nb");
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
|
||||
$this->assertSame('"ab"', $result);
|
||||
escapeEnvValue("a\r\nb");
|
||||
}
|
||||
|
||||
public function test_escape_env_value_preserves_normal_password(): void
|
||||
|
||||
@@ -0,0 +1,154 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Installer;
|
||||
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Step 3 저장 시점의 .env 값 사전 거부 회귀 테스트 (KVE-2026-2042).
|
||||
*
|
||||
* `app_name` / `app_url` / `core_update_github_url` 은 서버측 검증 없이 `$_POST` 에서
|
||||
* 그대로 `.env` 로 흘렀다. `.env` 는 줄 단위 형식이라 값에 개행을 섞으면 그 뒤가 새로운
|
||||
* 환경변수 줄로 해석되어, 설치 창이 열려 있는 동안 임의 환경변수를 주입할 수 있었다.
|
||||
*
|
||||
* 직렬화기(serializeEnvValue)가 최종 관문이지만 그 단계의 실패는 설치 진행 중 예외로
|
||||
* 드러나 어느 입력이 문제인지 알기 어렵다. 그래서 저장 시점에도 필드별로 거부한다.
|
||||
*
|
||||
* 저장/리다이렉트 분기에 도달하지 않도록 DB 검증을 일부러 실패시켜 상태 파일·세션을
|
||||
* 건드리지 않는다.
|
||||
*
|
||||
* @scenario vector=handleStep3Post, payload_class=env_line_injection, expected_outcome=return_invalid_message
|
||||
*
|
||||
* @effects step3_post_rejects_env_line_breaks_before_save
|
||||
*/
|
||||
class InstallerStep3EnvValueGuardTest extends TestCase
|
||||
{
|
||||
public static function setUpBeforeClass(): void
|
||||
{
|
||||
require_once __DIR__.'/stubs/lang_stub.php';
|
||||
|
||||
$projectRoot = dirname(__DIR__, 3);
|
||||
if (! defined('BASE_PATH')) {
|
||||
define('BASE_PATH', $projectRoot);
|
||||
}
|
||||
if (! defined('SUPPORTED_LANGUAGES')) {
|
||||
define('SUPPORTED_LANGUAGES', ['ko' => '한국어', 'en' => 'English']);
|
||||
}
|
||||
|
||||
require_once $projectRoot.'/public/install/includes/functions.php';
|
||||
require_once $projectRoot.'/public/install/includes/binary-path-policy.php';
|
||||
require_once $projectRoot.'/public/install/includes/request-handler.php';
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$_POST = [];
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* Step 3 POST 를 실행하고 에러 배열을 돌려줍니다.
|
||||
*
|
||||
* @param array<string, string> $post POST 본문 (DB 검증은 일부러 실패시킨다)
|
||||
* @return array<string, string> 에러 배열
|
||||
*/
|
||||
private function runStep3(array $post): array
|
||||
{
|
||||
$_POST = $post + [
|
||||
'db_write_host' => '',
|
||||
'db_write_database' => '',
|
||||
'db_write_username' => '',
|
||||
'admin_email' => 'not-an-email',
|
||||
'admin_language' => 'ko',
|
||||
'admin_password' => '',
|
||||
'admin_password_confirm' => '',
|
||||
];
|
||||
|
||||
$formData = [];
|
||||
$errors = [];
|
||||
handleStep3Post('ko', $formData, $errors);
|
||||
|
||||
return $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* 개행이 섞인 .env 대상 필드는 저장 시점에 거부된다.
|
||||
*
|
||||
* @param string $field 필드명
|
||||
* @param string $payload 주입 시도 값
|
||||
*/
|
||||
#[Test]
|
||||
#[DataProvider('lineBreakFieldProvider')]
|
||||
public function it_rejects_line_breaks_in_env_bound_fields(string $field, string $payload): void
|
||||
{
|
||||
$errors = $this->runStep3([$field => $payload]);
|
||||
|
||||
$this->assertArrayHasKey(
|
||||
$field,
|
||||
$errors,
|
||||
"{$field} 에 개행이 섞였는데 저장 시점에 통과했다 — .env 에 임의 변수 줄이 주입된다"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 개행 주입 벡터 (필드 × CR/LF).
|
||||
*
|
||||
* @return array<string, array{0: string, 1: string}>
|
||||
*/
|
||||
public static function lineBreakFieldProvider(): array
|
||||
{
|
||||
return [
|
||||
'app_name + LF' => ['app_name', "그누보드7\nAPP_DEBUG=true"],
|
||||
'app_name + CR' => ['app_name', "그누보드7\rAPP_DEBUG=true"],
|
||||
'app_url + LF' => ['app_url', "https://example.com\nAPP_DEBUG=true"],
|
||||
'app_url + CRLF' => ['app_url', "https://example.com\r\nAPP_DEBUG=true"],
|
||||
'github_url + LF' => ['core_update_github_url', "https://github.com/gnuboard/g7\nAPP_DEBUG=true"],
|
||||
'app_name + NUL' => ['app_name', "그누보드7\0APP_DEBUG=true"],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 스킴 없는 URL 은 거부된다.
|
||||
*/
|
||||
#[Test]
|
||||
public function it_rejects_url_fields_without_an_http_scheme(): void
|
||||
{
|
||||
$errors = $this->runStep3(['app_url' => 'javascript:alert(1)']);
|
||||
|
||||
$this->assertArrayHasKey('app_url', $errors);
|
||||
}
|
||||
|
||||
/**
|
||||
* 정상 값은 이 게이트에 걸리지 않는다 (회귀 방지).
|
||||
*/
|
||||
#[Test]
|
||||
public function it_accepts_normal_values(): void
|
||||
{
|
||||
$errors = $this->runStep3([
|
||||
'app_name' => '그누보드7',
|
||||
'app_url' => 'https://example.com',
|
||||
'core_update_github_url' => 'https://github.com/gnuboard/g7',
|
||||
]);
|
||||
|
||||
$this->assertArrayNotHasKey('app_name', $errors);
|
||||
$this->assertArrayNotHasKey('app_url', $errors);
|
||||
$this->assertArrayNotHasKey('core_update_github_url', $errors);
|
||||
}
|
||||
|
||||
/**
|
||||
* 값이 비어 있으면 URL 형태 검사는 건너뛴다 (선택 입력 보존).
|
||||
*/
|
||||
#[Test]
|
||||
public function it_skips_url_shape_check_for_empty_values(): void
|
||||
{
|
||||
$errors = $this->runStep3([
|
||||
'app_url' => '',
|
||||
'core_update_github_url' => '',
|
||||
]);
|
||||
|
||||
$this->assertArrayNotHasKey('app_url', $errors);
|
||||
$this->assertArrayNotHasKey('core_update_github_url', $errors);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user