v7.0.0-beta.7 release
This commit is contained in:
1 parent
c186d9a9c2
commit
0e7fa04b03
36 files changed
+2625
-83
No files matched your search
@@ -79,3 +79,65 @@ if (!function_exists('installer_guard_or_410')) {
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('installer_finalize_is_completed')) {
|
||||
/**
|
||||
* finalize-env.php 전용 멱등 차단 신호.
|
||||
*
|
||||
* 본 함수는 `.env` 의 `INSTALLER_COMPLETED=true` 단독으로만 차단을 판정한다.
|
||||
* `storage/app/g7_installed` 락 파일은 finalize 호출 직전 단계인
|
||||
* `complete_flag` task 가 먼저 생성하므로 차단 사유에서 제외한다.
|
||||
*/
|
||||
function installer_finalize_is_completed(): bool
|
||||
{
|
||||
$basePath = installer_resolve_base_path();
|
||||
$envFile = $basePath . '/.env';
|
||||
|
||||
if (!is_file($envFile)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$env = @parse_ini_file($envFile, false, INI_SCANNER_RAW);
|
||||
if (!is_array($env)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$flag = strtolower(trim((string) ($env['INSTALLER_COMPLETED'] ?? '')));
|
||||
$flag = trim($flag, "\"'");
|
||||
|
||||
return in_array($flag, ['true', '1', 'yes'], true);
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('installer_guard_finalize_or_410')) {
|
||||
/**
|
||||
* finalize-env.php 전용 진입 가드.
|
||||
*
|
||||
* 차단 조건: `.env` 의 `INSTALLER_COMPLETED=true` 단독. `g7_installed` 락 파일
|
||||
* 존재는 차단 사유가 아니다 — complete_flag task 가 락 파일을 먼저 만든 직후
|
||||
* 본 엔드포인트가 호출되어 `.env` 머지를 수행해야 하기 때문이다.
|
||||
*
|
||||
* RCE 공격 표면이 없는 finalize 전용으로 한정 — 일반 인스톨러 엔드포인트는
|
||||
* 계속 `installer_guard_or_410()` 을 사용한다.
|
||||
*/
|
||||
function installer_guard_finalize_or_410(): void
|
||||
{
|
||||
if (!installer_finalize_is_completed()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!headers_sent()) {
|
||||
http_response_code(410);
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
header('X-Installer: disabled');
|
||||
header('Cache-Control: no-store');
|
||||
}
|
||||
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'message' => 'Finalize already completed.',
|
||||
], JSON_UNESCAPED_UNICODE);
|
||||
|
||||
exit;
|
||||
}
|
||||
}
|
||||
@@ -22,7 +22,11 @@ require_once __DIR__ . '/../includes/functions.php';
|
||||
require_once __DIR__ . '/../includes/installer-runtime.php';
|
||||
require_once __DIR__ . '/../includes/installer-state.php';
|
||||
require_once __DIR__ . '/_guard.php';
|
||||
installer_guard_or_410();
|
||||
// finalize 전용 가드 — `.env` 의 INSTALLER_COMPLETED=true 단독으로만 차단한다.
|
||||
// 일반 인스톨러 엔드포인트의 `installer_guard_or_410()` 은 `g7_installed` 락 파일도
|
||||
// 차단 사유로 삼는데, 그 락 파일은 finalize 호출 직전 단계의 complete_flag task 가
|
||||
// 먼저 생성하므로 자가 차단 회귀가 발생한다 (이슈 #371).
|
||||
installer_guard_finalize_or_410();
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// 1. 응답을 즉시 송출하여 브라우저가 완료 UI 를 유지할 수 있게 한다.
|
||||
@@ -68,7 +72,7 @@ try {
|
||||
$envBase = generateEnvContent();
|
||||
|
||||
if ($envBase === null) {
|
||||
error_log('[finalize-env] generateEnvContent() returned null — .env.example missing');
|
||||
addLog('[finalize-env] generateEnvContent() returned null — .env.example missing');
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -79,25 +83,72 @@ try {
|
||||
// ServeCommand 의 mtime watcher 가 다중 재시작을 일으키지 않는다.
|
||||
// atomic rename 대신 file_put_contents 를 사용하여 부모 디렉토리(프로젝트 루트)
|
||||
// 쓰기 권한 요구를 회피 — 기존 인스톨러 권한 안내 (chmod 664 .env + chgrp) 만으로 충분.
|
||||
//
|
||||
// 권한 정책 (#371): finalize-env.php 는 chmod 0600 시도를 수행하지 않는다.
|
||||
// PHP-FPM(www-data) 가 .env 소유자(예: jjh) 와 다른 자체 구축 환경에서는 POSIX 상
|
||||
// chmod 가 거부되며, 또한 인스톨러가 임의로 0600 으로 깎으면 운영자가 의도해서
|
||||
// 설정한 0664/0640 권한이 손상된다. file_put_contents 는 기존 inode 의 권한을
|
||||
// 변경하지 않으므로, 인스톨러 안내 단계의 권한 (chgrp www-data + chmod 664) 이
|
||||
// 그대로 유지된다. 추가 보안 강화는 Step 6 완료 화면 안내 + INSTALL.md 운영
|
||||
// 가이드에 위임.
|
||||
if (@file_put_contents($envPath, $envContent, LOCK_EX) === false) {
|
||||
error_log('[finalize-env] failed to write .env');
|
||||
$lastError = error_get_last();
|
||||
addLog(sprintf(
|
||||
'[finalize-env] file_put_contents FAILED: path=%s, last_error=%s',
|
||||
$envPath,
|
||||
$lastError['message'] ?? 'unknown',
|
||||
));
|
||||
return;
|
||||
}
|
||||
|
||||
@chmod($envPath, 0600);
|
||||
// 머지 후 권한·소유자·그룹 상태를 명시 기록 — 운영자 사후 검증용
|
||||
$envPermsAfter = fileperms($envPath) & 0777;
|
||||
$envOwnerAfter = @fileowner($envPath);
|
||||
$envGroupAfter = @filegroup($envPath);
|
||||
|
||||
$currentEuid = function_exists('posix_geteuid') ? posix_geteuid() : null;
|
||||
$currentEuser = ($currentEuid !== null && function_exists('posix_getpwuid'))
|
||||
? (posix_getpwuid($currentEuid)['name'] ?? (string) $currentEuid)
|
||||
: 'unknown';
|
||||
|
||||
addLog(sprintf(
|
||||
'[finalize-env] .env 머지 완료 (chmod 시도 안 함, 기존 권한 보존): path=%s, perms=%s, owner_uid=%s, group_gid=%s, process_euser=%s',
|
||||
$envPath,
|
||||
decoct($envPermsAfter),
|
||||
$envOwnerAfter === false ? 'unknown' : (string) $envOwnerAfter,
|
||||
$envGroupAfter === false ? 'unknown' : (string) $envGroupAfter,
|
||||
$currentEuser,
|
||||
));
|
||||
|
||||
// runtime.php 삭제 — Provider 가 다음 부팅부터 no-op
|
||||
deleteInstallerRuntime();
|
||||
if (! deleteInstallerRuntime()) {
|
||||
addLog(sprintf(
|
||||
'[finalize-env] deleteInstallerRuntime FAILED: path=%s, last_error=%s. '
|
||||
.'runtime.php 잔존 — InstallerRuntimeServiceProvider 폴백 동작 유지되나 평문 자격증명 보안 우려.',
|
||||
INSTALLER_RUNTIME_PATH,
|
||||
(error_get_last()['message'] ?? 'unknown'),
|
||||
));
|
||||
} else {
|
||||
addLog('[finalize-env] runtime.php 삭제 완료');
|
||||
}
|
||||
|
||||
// state.json 삭제 — setInstallationCompleteSSE 가 본 단계로 위임함
|
||||
// (finalize 가 generateEnvContent() 호출 시 state.config 가 필요했기 때문)
|
||||
if (defined('DELETE_INSTALLER_AFTER_COMPLETE') && DELETE_INSTALLER_AFTER_COMPLETE) {
|
||||
$stateFilePath = BASE_PATH . '/storage/installer-state.json';
|
||||
if (is_file($stateFilePath)) {
|
||||
@unlink($stateFilePath);
|
||||
if (@unlink($stateFilePath) === false) {
|
||||
addLog(sprintf(
|
||||
'[finalize-env] state.json unlink FAILED: path=%s, last_error=%s',
|
||||
$stateFilePath,
|
||||
(error_get_last()['message'] ?? 'unknown'),
|
||||
));
|
||||
} else {
|
||||
addLog('[finalize-env] state.json 삭제 완료');
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
// 예외 시 runtime.php 보존 → Provider 가 계속 config 주입 → 앱 정상 동작.
|
||||
error_log('[finalize-env] unexpected exception: ' . $e->getMessage());
|
||||
addLog('[finalize-env] unexpected exception: ' . $e->getMessage() . ' @ ' . $e->getFile() . ':' . $e->getLine());
|
||||
}
|
||||
@@ -42,7 +42,9 @@ function getInstallationState(): array
|
||||
|
||||
// 파일 읽기 권한 체크
|
||||
if (!is_readable(STATE_PATH)) {
|
||||
error_log("State file is not readable: " . STATE_PATH);
|
||||
$msg = "[installer-state] State file is not readable: " . STATE_PATH;
|
||||
error_log($msg);
|
||||
addLog($msg);
|
||||
return $defaultState;
|
||||
}
|
||||
|
||||
@@ -51,7 +53,9 @@ function getInstallationState(): array
|
||||
|
||||
// 파일 읽기 실패 시 기본 상태 반환
|
||||
if ($content === false) {
|
||||
error_log("Failed to read state file: " . STATE_PATH);
|
||||
$msg = "[installer-state] Failed to read state file: " . STATE_PATH;
|
||||
error_log($msg);
|
||||
addLog($msg);
|
||||
return $defaultState;
|
||||
}
|
||||
|
||||
@@ -61,7 +65,9 @@ function getInstallationState(): array
|
||||
if (json_last_error() !== JSON_ERROR_NONE) {
|
||||
$contentLen = strlen($content);
|
||||
$preview = substr($content, 0, 200);
|
||||
error_log("Failed to parse state file JSON (length={$contentLen}): " . json_last_error_msg() . " / preview: " . $preview);
|
||||
$msg = "[installer-state] Failed to parse state file JSON (length={$contentLen}): " . json_last_error_msg() . " / preview: " . $preview;
|
||||
error_log($msg);
|
||||
addLog($msg);
|
||||
return $defaultState;
|
||||
}
|
||||
|
||||
@@ -79,13 +85,17 @@ function saveInstallationState(array $state): bool
|
||||
// storage 디렉토리 존재 여부 확인 (생성하지 않음)
|
||||
$storageDir = BASE_PATH . '/storage';
|
||||
if (!is_dir($storageDir)) {
|
||||
error_log("Storage directory does not exist: {$storageDir}");
|
||||
$msg = "[installer-state] Storage directory does not exist: {$storageDir}";
|
||||
error_log($msg);
|
||||
addLog($msg);
|
||||
return false;
|
||||
}
|
||||
|
||||
// 디렉토리 쓰기 권한 확인
|
||||
if (!is_writable($storageDir)) {
|
||||
error_log("Storage directory is not writable: {$storageDir}");
|
||||
$msg = "[installer-state] Storage directory is not writable: {$storageDir}";
|
||||
error_log($msg);
|
||||
addLog($msg);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -96,7 +106,9 @@ function saveInstallationState(array $state): bool
|
||||
$content = json_encode($state, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||||
|
||||
if ($content === false) {
|
||||
error_log("Failed to encode state as JSON: " . json_last_error_msg());
|
||||
$msg = "[installer-state] Failed to encode state as JSON: " . json_last_error_msg();
|
||||
error_log($msg);
|
||||
addLog($msg);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -107,7 +119,9 @@ function saveInstallationState(array $state): bool
|
||||
|
||||
$result = @file_put_contents($tmpPath, $content, LOCK_EX);
|
||||
if ($result === false || $result !== strlen($content)) {
|
||||
error_log("Failed to write state tmp file: " . $tmpPath);
|
||||
$msg = "[installer-state] Failed to write state tmp file: " . $tmpPath;
|
||||
error_log($msg);
|
||||
addLog($msg);
|
||||
@unlink($tmpPath);
|
||||
return false;
|
||||
}
|
||||
@@ -115,7 +129,9 @@ function saveInstallationState(array $state): bool
|
||||
@chmod($tmpPath, 0664);
|
||||
|
||||
if (!@rename($tmpPath, STATE_PATH)) {
|
||||
error_log("Failed to rename state tmp file: " . $tmpPath . ' → ' . STATE_PATH);
|
||||
$msg = "[installer-state] Failed to rename state tmp file: " . $tmpPath . ' → ' . STATE_PATH;
|
||||
error_log($msg);
|
||||
addLog($msg);
|
||||
@unlink($tmpPath);
|
||||
return false;
|
||||
}
|
||||
@@ -379,13 +395,17 @@ function addLogBatch(array $messages): bool
|
||||
if (!is_dir($logDir)) {
|
||||
$created = @mkdir($logDir, 0775, true);
|
||||
if (!$created) {
|
||||
error_log("Failed to create log directory: {$logDir}");
|
||||
$msg = "[addLogBatch] Failed to create log directory: {$logDir}";
|
||||
error_log($msg);
|
||||
addLog($msg); // 재귀 가드가 차단하므로 안전 — error_log fallback 만 수행
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!is_writable($logDir)) {
|
||||
error_log("Log directory is not writable: {$logDir}");
|
||||
$msg = "[addLogBatch] Log directory is not writable: {$logDir}";
|
||||
error_log($msg);
|
||||
addLog($msg); // 재귀 가드가 차단
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -412,7 +432,9 @@ function addLogBatch(array $messages): bool
|
||||
|
||||
$handle = @fopen($logFile, 'a');
|
||||
if ($handle === false) {
|
||||
error_log("Failed to open log file: {$logFile}");
|
||||
$msg = "[addLogBatch] Failed to open log file: {$logFile}";
|
||||
error_log($msg);
|
||||
addLog($msg); // 재귀 가드가 차단
|
||||
return false;
|
||||
}
|
||||
flock($handle, LOCK_EX);
|
||||
@@ -425,6 +447,36 @@ function addLogBatch(array $messages): bool
|
||||
}
|
||||
|
||||
function addLog(string $message): bool
|
||||
{
|
||||
// 무한 재귀 가드 — addLog 내부 폴백 경로에서 자기 자신을 다시 호출하면 안 된다.
|
||||
// installer-state.php / session.php / finalize-env.php 등에서 error_log 와 addLog 를
|
||||
// 병행 호출하는 경우, addLog 내부의 인프라 실패 폴백 (storage 쓰기 실패 등) 시
|
||||
// 호출자가 다시 addLog 를 부르면 같은 인프라가 다시 실패하여 무한 재귀가 발생할 수 있다.
|
||||
static $inAddLog = false;
|
||||
if ($inAddLog) {
|
||||
// 재진입: installation.log 시도 skip, PHP error_log 만 호출하고 즉시 종료
|
||||
error_log("[addLog reentrant] " . $message);
|
||||
return false;
|
||||
}
|
||||
$inAddLog = true;
|
||||
|
||||
try {
|
||||
return _addLogInternal($message);
|
||||
} finally {
|
||||
$inAddLog = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* addLog 의 실제 구현 — 무한 재귀 가드를 거친 후 호출된다.
|
||||
*
|
||||
* 본 함수 안에서는 절대 addLog() 를 호출하지 말 것 (무한 재귀 위험).
|
||||
* 내부 폴백은 error_log() 만 사용.
|
||||
*
|
||||
* @param string $message 기록할 메시지
|
||||
* @return bool 성공 여부
|
||||
*/
|
||||
function _addLogInternal(string $message): bool
|
||||
{
|
||||
$logDir = BASE_PATH . '/storage/logs';
|
||||
$logFile = $logDir . '/installation.log';
|
||||
@@ -433,14 +485,18 @@ function addLog(string $message): bool
|
||||
if (!is_dir($logDir)) {
|
||||
$created = @mkdir($logDir, 0775, true);
|
||||
if (!$created) {
|
||||
error_log("Failed to create log directory: {$logDir} (storage 권한 확인 필요)");
|
||||
$msg = "[addLog] Failed to create log directory: {$logDir} (storage 권한 확인 필요)";
|
||||
error_log($msg);
|
||||
addLog($msg); // 재귀 가드가 차단 (본 함수는 이미 가드 안)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// 로그 디렉토리 쓰기 권한 확인
|
||||
if (!is_writable($logDir)) {
|
||||
error_log("Log directory is not writable: {$logDir}");
|
||||
$msg = "[addLog] Log directory is not writable: {$logDir}";
|
||||
error_log($msg);
|
||||
addLog($msg); // 재귀 가드가 차단
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -471,7 +527,9 @@ function addLog(string $message): bool
|
||||
// 파일 핸들 열기 (append 모드)
|
||||
$handle = @fopen($logFile, 'a');
|
||||
if ($handle === false) {
|
||||
error_log("Failed to open log file: {$logFile}");
|
||||
$msg = "[addLog] Failed to open log file: {$logFile}";
|
||||
error_log($msg);
|
||||
addLog($msg); // 재귀 가드가 차단
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -492,7 +550,9 @@ function addLog(string $message): bool
|
||||
clearstatcache(true, $logFile);
|
||||
|
||||
if ($result === false) {
|
||||
error_log("Failed to write log file: {$logFile}");
|
||||
$msg = "[addLog] Failed to write log file: {$logFile}";
|
||||
error_log($msg);
|
||||
addLog($msg); // 재귀 가드가 차단
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,8 +4,15 @@
|
||||
* 세션 관리 및 CSRF 토큰 처리
|
||||
*
|
||||
* 그누보드7 웹 인스톨러의 세션 관리와 CSRF 보호 기능을 제공합니다.
|
||||
*
|
||||
* installer-state.php 를 require 하여 addLog() 함수를 사용 가능하게 한다.
|
||||
* index.php 및 일부 API 엔드포인트가 본 파일을 installer-state.php 보다 먼저
|
||||
* require 하기 때문에, 본 파일 안에서 addLog 호출이 필요한 경우를 위해
|
||||
* 명시적으로 의존성을 선언한다 (이슈 #371).
|
||||
*/
|
||||
|
||||
require_once __DIR__ . '/installer-state.php';
|
||||
|
||||
// 세션이 이미 시작되지 않았으면 시작
|
||||
if (session_status() === PHP_SESSION_NONE) {
|
||||
// 세션 설정
|
||||
@@ -39,7 +46,9 @@ if (session_status() === PHP_SESSION_NONE) {
|
||||
|
||||
if (json_last_error() === JSON_ERROR_NONE && isset($state['g7_locale'])) {
|
||||
$detectedLang = $state['g7_locale'];
|
||||
error_log("[세션 초기화] state.json에서 언어 복원: {$detectedLang}");
|
||||
$msg = "[세션 초기화] state.json에서 언어 복원: {$detectedLang}";
|
||||
error_log($msg);
|
||||
addLog($msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -51,15 +60,21 @@ if (session_status() === PHP_SESSION_NONE) {
|
||||
|
||||
if ($browserLang !== null) {
|
||||
$detectedLang = $browserLang;
|
||||
error_log("[세션 초기화] 브라우저에서 언어 감지: {$browserLang}");
|
||||
$msg = "[세션 초기화] 브라우저에서 언어 감지: {$browserLang}";
|
||||
error_log($msg);
|
||||
addLog($msg);
|
||||
}
|
||||
}
|
||||
|
||||
// 3. 최종 기본값
|
||||
$_SESSION['g7_locale'] = $detectedLang ?? 'ko';
|
||||
error_log("[세션 초기화] 최종 설정 언어: {$_SESSION['g7_locale']}");
|
||||
$msg = "[세션 초기화] 최종 설정 언어: {$_SESSION['g7_locale']}";
|
||||
error_log($msg);
|
||||
addLog($msg);
|
||||
} else {
|
||||
error_log("[세션 초기화] g7_locale 이미 존재: {$_SESSION['g7_locale']}");
|
||||
$msg = "[세션 초기화] g7_locale 이미 존재: {$_SESSION['g7_locale']}";
|
||||
error_log($msg);
|
||||
addLog($msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -138,6 +138,13 @@ return [
|
||||
'recommendation_env_permission' => 'Set .env file permissions to 644 (chmod 644 .env)',
|
||||
'recommendation_https' => 'Use HTTPS in production environment',
|
||||
|
||||
// .env permission hardening hint (Step 5 completion screen, shown when not 0600)
|
||||
'env_hardening_hint_title' => '.env Permission Hardening (Optional)',
|
||||
'env_hardening_hint_current_status' => 'Current .env permission is %s (owner: %s). The most secure permission is 0600 (owner read/write only). To apply additional hardening, run the appropriate command below with sudo based on your environment.',
|
||||
'env_hardening_hint_option_strict' => 'CLI user = web server user (single-user environment)',
|
||||
'env_hardening_hint_option_group' => 'CLI user ≠ web server user (self-hosted server, etc. — group-readable compromise)',
|
||||
'env_hardening_hint_note' => 'Verify your environment before running. Applying the wrong permission may prevent the web server from reading .env and cause the site to stop responding.',
|
||||
|
||||
// Step 5: Complete
|
||||
'installation_info' => 'Installation Information',
|
||||
'installation_complete_message' => 'Gnuboard7 has been successfully installed!',
|
||||
|
||||
@@ -138,6 +138,13 @@ return [
|
||||
'recommendation_env_permission' => '.env 파일 권한을 644로 설정하세요 (chmod 644 .env)',
|
||||
'recommendation_https' => '프로덕션 환경에서는 반드시 HTTPS를 사용하세요',
|
||||
|
||||
// .env 권한 보안 강화 안내 (Step 5 완료 화면, 0600 미적용 시 조건부 노출)
|
||||
'env_hardening_hint_title' => '.env 권한 보안 강화 (선택)',
|
||||
'env_hardening_hint_current_status' => '현재 .env 권한은 %s 입니다 (소유자: %s). 가장 안전한 권한은 0600 (소유자만 읽기·쓰기) 이며, 다음 두 명령 중 환경에 맞는 쪽을 sudo 로 실행하여 추가 보안 강화를 적용할 수 있습니다.',
|
||||
'env_hardening_hint_option_strict' => '명령줄 사용자 = 웹 서버 사용자 (단일 사용자 환경)',
|
||||
'env_hardening_hint_option_group' => '명령줄 사용자 ≠ 웹 서버 사용자 (자체 구축 서버 등 — 그룹 읽기 허용 절충안)',
|
||||
'env_hardening_hint_note' => '명령 실행 전 환경을 확인하세요. 잘못된 권한 적용 시 웹 서버가 .env 를 읽지 못해 사이트가 응답하지 않을 수 있습니다.',
|
||||
|
||||
// Step 5: 완료
|
||||
'installation_info' => '설치 정보',
|
||||
'installation_complete_message' => '그누보드7이 성공적으로 설치되었습니다!',
|
||||
|
||||
@@ -67,6 +67,55 @@ $config = $state['config'] ?? $_SESSION['install_config'] ?? [];
|
||||
. '<strong>' . htmlspecialchars($coreVersion) . '</strong>'
|
||||
. '</p>';
|
||||
|
||||
// .env 권한 권장 강화 안내 — 0600 이 아니면 조건부 노출 (#371)
|
||||
// finalize-env.php 는 chmod 시도를 수행하지 않으므로 인스톨러 안내 단계의 권한
|
||||
// (예: 0664 + chgrp www-data) 이 그대로 유지됨. 운영자가 추가로 0600 적용을
|
||||
// 원할 수 있도록 현재 권한이 0600 미만 (그룹/기타 비트가 있음) 이면 명령 예시 노출.
|
||||
//
|
||||
// OS 가드: chmod/chgrp 는 POSIX 권한 모델 (Linux/macOS/BSD) 에서 동작.
|
||||
// Windows 만 명령이 무의미하므로 Windows 만 비노출.
|
||||
$envPath = BASE_PATH . '/.env';
|
||||
if (PHP_OS_FAMILY !== 'Windows' && is_file($envPath)) {
|
||||
$envPerms = fileperms($envPath) & 0777;
|
||||
if ($envPerms !== 0600) {
|
||||
$envOwnerUid = @fileowner($envPath);
|
||||
$envOwnerName = ($envOwnerUid !== false && function_exists('posix_getpwuid'))
|
||||
? (posix_getpwuid($envOwnerUid)['name'] ?? (string) $envOwnerUid)
|
||||
: 'owner';
|
||||
$webGroupName = function_exists('posix_getegid') && function_exists('posix_getgrgid')
|
||||
? (posix_getgrgid(posix_getegid())['name'] ?? 'www-data')
|
||||
: 'www-data';
|
||||
|
||||
$hardeningCommandSameOwner = sprintf('chmod 600 %s', htmlspecialchars($envPath));
|
||||
$hardeningCommandDifferentOwner = sprintf(
|
||||
'sudo chgrp %s %s && sudo chmod 640 %s',
|
||||
htmlspecialchars($webGroupName),
|
||||
htmlspecialchars($envPath),
|
||||
htmlspecialchars($envPath)
|
||||
);
|
||||
|
||||
$completionExtra .= '<div class="env-hardening-hint">'
|
||||
. '<p class="env-hardening-hint-title">' . htmlspecialchars(lang('env_hardening_hint_title')) . '</p>'
|
||||
. '<p class="env-hardening-hint-status">'
|
||||
. sprintf(
|
||||
htmlspecialchars(lang('env_hardening_hint_current_status')),
|
||||
decoct($envPerms),
|
||||
htmlspecialchars($envOwnerName)
|
||||
)
|
||||
. '</p>'
|
||||
. '<p class="env-hardening-hint-option">'
|
||||
. htmlspecialchars(lang('env_hardening_hint_option_strict'))
|
||||
. '</p>'
|
||||
. '<div class="code-box"><pre>' . $hardeningCommandSameOwner . '</pre></div>'
|
||||
. '<p class="env-hardening-hint-option">'
|
||||
. htmlspecialchars(lang('env_hardening_hint_option_group'))
|
||||
. '</p>'
|
||||
. '<div class="code-box"><pre>' . $hardeningCommandDifferentOwner . '</pre></div>'
|
||||
. '<p class="env-hardening-hint-note">' . htmlspecialchars(lang('env_hardening_hint_note')) . '</p>'
|
||||
. '</div>';
|
||||
}
|
||||
}
|
||||
|
||||
echo renderInstallResultSection('completion', 'success', 'installation_completed', 'installation_complete_message', $completionButtons, $completionExtra);
|
||||
?>
|
||||
|
||||
|
||||
Reference in new issue
Block a user