fix(core): 확장 오토로드 캐시 공집합 덮어쓰기로 인한 전역 500 + 소스맵 노출 차단 복원
오토로드 캐시(psr4)가 공집합으로 덮어써져 모든 모듈/플러그인 컨트롤러가 해석 불가능해지고 확장 화면 전체가 500 이 됐다. 이 매핑은 "DB 설치 목록 × 디스크 활성 디렉토리" 교집합이라 DB 쪽만 일시적으로 비어도(테이블 부재· 설치 중간 실패·testing DB) 정상 매핑이 통째로 소실된다. 코어 라우트는 200 인데 확장 라우트만 전부 500 인 비대칭이 이 결함의 진단 단서다. - 디스크에 확장 디렉토리가 남아 있는데 매핑이 0건이면 기록하지 않고 보존. 정상적인 0건(신규 설치·마지막 확장 삭제)은 디스크도 함께 비어 통과한다 - generateAutoloadFile 에 testing 실 캐시 경로 쓰기 차단. updateComposerAutoload 에만 있던 가드를 생성기 자체로 옮겨 어느 경로로 들어와도 막히게 했다 - extension:update-autoload 가 훅 캐시 재생성 전에 런타임 오토로드를 재등록. 미재등록 시 깨진 매핑으로 훅 캐시가 modules/plugins 0건으로 생성되어 확장 훅이 조용히 사라지고, 복구에 커맨드 2회 실행이 필요했다 소스맵 서빙은 에서 차단했으나 이번 브랜치에서 화이트리스트에 재추가되어 운영에서 원본 코드 전문(sourcesContent)이 노출될 수 있었다. 이 화이트리스트가 확장 에셋 서빙의 유일한 방어선이다. dev 빌드의 sourceMappingURL 404 를 피하면서 운영을 막도록 local 환경에서만 허용하도록 분기하고, 산출물을 production 으로 재빌드해 docroot 에 남아 있던 소스맵을 제거했다. --production 빌드는 소스맵을 생성하지 않을 뿐 기존 파일을 지우지 않는다. CoreUpdateCommandSpawnFailureTest 는 in-process fallback 이 실제 업그레이드 스텝을 돌려 코어 역할·권한·메뉴를 커밋하는데 RefreshDatabase 가 없어, 이후 모든 테스트 클래스가 중복 키로 깨졌다(단독 실행 시 미재현).
This commit is contained in:
1 parent
3044119b37
commit
d6e1f98a4f
17 files changed
+562
-66
No files matched your search
@@ -41,6 +41,12 @@ class UpdateAutoloadCommand extends Command
|
||||
$this->info('오토로드 파일이 성공적으로 생성되었습니다.');
|
||||
$this->line(' → bootstrap/cache/autoload-extensions.php');
|
||||
|
||||
// 방금 생성한 PSR-4 매핑을 현재 프로세스의 ClassLoader 에 즉시 반영.
|
||||
// 이 커맨드는 매핑이 깨진 상태를 복구하는 경로이기도 한데, 재등록 없이 아래
|
||||
// loadModules/loadPlugins 를 호출하면 부팅 시점의 (깨진) 매핑으로 확장 클래스를
|
||||
// 찾지 못해 훅 캐시가 modules/plugins 0건으로 생성된다 — 모든 확장 훅이 조용히 소실.
|
||||
$extensionManager->reregisterRuntimeAutoload();
|
||||
|
||||
// 오토로드 캐시와 동일 생명주기의 정적 훅 매핑 캐시도 함께 재생성.
|
||||
// 코어 업데이트(clearAllCaches → 이 커맨드) 시 코어 리스너 추가/변경/삭제가
|
||||
// 캐시에 반영되도록 보장한다 (미갱신 시 stale 매핑으로 훅 발화 누락/과잉 위험).
|
||||
|
||||
@@ -106,7 +106,7 @@ class ExtensionManager
|
||||
* 매핑을 즉시 유효화한다. 기존 매핑에 경로가 추가되거나 새 네임스페이스가
|
||||
* 등록되며, 동일 매핑은 중복 없이 merge 된다.
|
||||
*/
|
||||
protected function reregisterRuntimeAutoload(): void
|
||||
public function reregisterRuntimeAutoload(): void
|
||||
{
|
||||
if (! class_exists(ClassLoader::class, false)) {
|
||||
return;
|
||||
@@ -135,6 +135,14 @@ class ExtensionManager
|
||||
*/
|
||||
public function generateAutoloadFile(): void
|
||||
{
|
||||
// 테스트 환경에서는 실 캐시 파일을 재생성하지 않는다.
|
||||
// testing DB 의 활성 확장 구성은 개발 DB 와 다르므로, 어떤 경로로든 실 캐시가
|
||||
// 재생성되면 개발 환경 PSR-4 매핑이 testing 기준으로 교체되어 모든 모듈/플러그인
|
||||
// 라우트가 500 이 된다. 생성 로직 자체를 검증하는 테스트는 경로를 치환해 사용한다.
|
||||
if ($this->writesRealCacheFileDuringTests()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 모듈별 오토로드 수집
|
||||
$moduleAutoloads = $this->collectModuleAutoloads();
|
||||
|
||||
@@ -170,6 +178,24 @@ class ExtensionManager
|
||||
// 즉시 경로를 반환하도록 한다(성능). 클래스 로딩은 여전히 lazy — 사용 시점에만 include.
|
||||
$srcClassmap = $this->buildSourceClassmap($psr4);
|
||||
|
||||
// 공집합 산출물로 정상 매핑을 덮어쓰지 않는다.
|
||||
// 이 매핑은 "DB 설치 목록 × 디스크 활성 디렉토리" 교집합이라, DB 쪽만 일시적으로
|
||||
// 비어도(테이블 부재 · 설치 실패로 행 미기록 · 다른 DB 접속) 교집합이 공집합이 된다.
|
||||
// 디스크에 설치 형태의 확장 디렉토리가 남아 있는데 매핑이 0건이면 DB 쪽 조회를
|
||||
// 신뢰할 수 없다는 뜻이므로, 기존 파일을 보존하고 경고만 남긴다.
|
||||
// (정상적인 0건 — 신규 설치 직후 · 마지막 확장 삭제 — 은 디스크도 함께 비어 통과)
|
||||
$extensionDirectories = empty($psr4) ? $this->findInstalledExtensionDirectories() : [];
|
||||
|
||||
if (empty($psr4) && ! empty($extensionDirectories)) {
|
||||
Log::warning('확장 오토로드 매핑이 0건으로 산출되어 기존 캐시를 보존합니다', [
|
||||
'path' => $this->autoloadFilePath,
|
||||
'extension_directories' => $extensionDirectories,
|
||||
'hint' => '확장 테이블(modules/plugins) 조회 결과가 비어 있습니다. DB 연결·마이그레이션 상태를 확인한 뒤 extension:update-autoload 를 다시 실행하세요.',
|
||||
]);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// 파일 내용 생성
|
||||
$content = $this->buildAutoloadFileContent($psr4, $classmap, $files, $vendorAutoloads, $srcClassmap);
|
||||
|
||||
@@ -192,6 +218,52 @@ class ExtensionManager
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 현재 호출이 테스트 환경에서 실 캐시 파일을 건드리는지 판정합니다.
|
||||
*
|
||||
* 경로가 치환된(임시 경로) 인스턴스는 생성 로직 검증용이므로 통과시킨다.
|
||||
*
|
||||
* @return bool 테스트 환경에서 실 캐시 파일을 쓰려는 경우 true
|
||||
*/
|
||||
protected function writesRealCacheFileDuringTests(): bool
|
||||
{
|
||||
return app()->environment('testing')
|
||||
&& $this->autoloadFilePath === base_path('bootstrap/cache/autoload-extensions.php');
|
||||
}
|
||||
|
||||
/**
|
||||
* 디스크에서 설치 형태를 갖춘 확장 디렉토리를 찾습니다.
|
||||
*
|
||||
* `_bundled` / `_pending` 등 내부 디렉토리는 제외하고, composer.json 을 가진
|
||||
* 활성 디렉토리만 센다 (설치된 확장이 남긴 흔적).
|
||||
*
|
||||
* @return array<int, string> 확장 식별자 목록 (예: `modules/sirsoft-board`)
|
||||
*/
|
||||
protected function findInstalledExtensionDirectories(): array
|
||||
{
|
||||
$found = [];
|
||||
|
||||
foreach (['modules' => $this->modulesPath, 'plugins' => $this->pluginsPath] as $type => $basePath) {
|
||||
if (! File::isDirectory($basePath)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach (File::directories($basePath) as $dir) {
|
||||
$name = basename($dir);
|
||||
|
||||
if (str_starts_with($name, '_')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (File::exists($dir.'/composer.json')) {
|
||||
$found[] = $type.'/'.$name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $found;
|
||||
}
|
||||
|
||||
/**
|
||||
* 오토로드 파일 내용을 생성합니다.
|
||||
*
|
||||
|
||||
@@ -20,10 +20,6 @@ class AllowedModuleFileType implements ValidationRule
|
||||
// Data
|
||||
'json',
|
||||
|
||||
// Source maps — dev 빌드의 `//# sourceMappingURL` 이 개별 에셋 서빙 URL 을
|
||||
// 가리키므로 허용 필요. prod 는 ExtensionBundleService 가 참조 자체를 strip 한다.
|
||||
'map',
|
||||
|
||||
// Images
|
||||
'png', 'jpg', 'jpeg', 'svg', 'webp', 'gif', 'ico',
|
||||
|
||||
@@ -43,11 +39,12 @@ class AllowedModuleFileType implements ValidationRule
|
||||
}
|
||||
|
||||
$extension = strtolower(pathinfo($value, PATHINFO_EXTENSION));
|
||||
$allowed = self::getAllowedExtensions();
|
||||
|
||||
if (! in_array($extension, self::ALLOWED_EXTENSIONS, true)) {
|
||||
if (! in_array($extension, $allowed, true)) {
|
||||
$fail(__('validation.module_path.file_type_not_allowed', [
|
||||
'extension' => $extension,
|
||||
'allowed' => implode(', ', self::ALLOWED_EXTENSIONS),
|
||||
'allowed' => implode(', ', $allowed),
|
||||
]));
|
||||
|
||||
return;
|
||||
@@ -57,10 +54,20 @@ class AllowedModuleFileType implements ValidationRule
|
||||
/**
|
||||
* 허용된 확장자 목록 반환
|
||||
*
|
||||
* @return array<string>
|
||||
* 로컬 개발 환경에서만 소스맵(`map`)을 덧붙인다. dev 빌드 산출물은
|
||||
* `//# sourceMappingURL` 이 개별 에셋 서빙 URL 을 가리키므로 서빙되어야
|
||||
* 브라우저 콘솔에 404 가 남지 않는다. 반면 소스맵에는 원본 코드 전문
|
||||
* (`sourcesContent`)이 담겨 있고 이 화이트리스트가 에셋 서빙의 유일한
|
||||
* 방어선이므로, 운영 환경에서는 어떤 경우에도 서빙하지 않는다.
|
||||
*
|
||||
* @return array<string> 허용된 확장자 목록
|
||||
*/
|
||||
public static function getAllowedExtensions(): array
|
||||
{
|
||||
if (app()->environment('local')) {
|
||||
return [...self::ALLOWED_EXTENSIONS, 'map'];
|
||||
}
|
||||
|
||||
return self::ALLOWED_EXTENSIONS;
|
||||
}
|
||||
}
|
||||
@@ -20,10 +20,6 @@ class AllowedPluginFileType implements ValidationRule
|
||||
// Data
|
||||
'json',
|
||||
|
||||
// Source maps — dev 빌드의 `//# sourceMappingURL` 이 개별 에셋 서빙 URL 을
|
||||
// 가리키므로 허용 필요. prod 는 ExtensionBundleService 가 참조 자체를 strip 한다.
|
||||
'map',
|
||||
|
||||
// Images
|
||||
'png', 'jpg', 'jpeg', 'svg', 'webp', 'gif', 'ico',
|
||||
|
||||
@@ -43,11 +39,12 @@ class AllowedPluginFileType implements ValidationRule
|
||||
}
|
||||
|
||||
$extension = strtolower(pathinfo($value, PATHINFO_EXTENSION));
|
||||
$allowed = self::getAllowedExtensions();
|
||||
|
||||
if (! in_array($extension, self::ALLOWED_EXTENSIONS, true)) {
|
||||
if (! in_array($extension, $allowed, true)) {
|
||||
$fail(__('validation.plugin_path.file_type_not_allowed', [
|
||||
'extension' => $extension,
|
||||
'allowed' => implode(', ', self::ALLOWED_EXTENSIONS),
|
||||
'allowed' => implode(', ', $allowed),
|
||||
]));
|
||||
|
||||
return;
|
||||
@@ -57,10 +54,20 @@ class AllowedPluginFileType implements ValidationRule
|
||||
/**
|
||||
* 허용된 확장자 목록 반환
|
||||
*
|
||||
* @return array<string>
|
||||
* 로컬 개발 환경에서만 소스맵(`map`)을 덧붙인다. dev 빌드 산출물은
|
||||
* `//# sourceMappingURL` 이 개별 에셋 서빙 URL 을 가리키므로 서빙되어야
|
||||
* 브라우저 콘솔에 404 가 남지 않는다. 반면 소스맵에는 원본 코드 전문
|
||||
* (`sourcesContent`)이 담겨 있고 이 화이트리스트가 에셋 서빙의 유일한
|
||||
* 방어선이므로, 운영 환경에서는 어떤 경우에도 서빙하지 않는다.
|
||||
*
|
||||
* @return array<string> 허용된 확장자 목록
|
||||
*/
|
||||
public static function getAllowedExtensions(): array
|
||||
{
|
||||
if (app()->environment('local')) {
|
||||
return [...self::ALLOWED_EXTENSIONS, 'map'];
|
||||
}
|
||||
|
||||
return self::ALLOWED_EXTENSIONS;
|
||||
}
|
||||
}
|
||||
@@ -20,10 +20,6 @@ class AllowedTemplateFileType implements ValidationRule
|
||||
// Data
|
||||
'json',
|
||||
|
||||
// Source maps — dev 빌드 산출물의 소스맵 참조 대응.
|
||||
// prod 빌드는 소스맵 참조를 포함하지 않는다.
|
||||
'map',
|
||||
|
||||
// Images
|
||||
'png', 'jpg', 'jpeg', 'svg', 'webp', 'gif',
|
||||
|
||||
@@ -43,11 +39,12 @@ class AllowedTemplateFileType implements ValidationRule
|
||||
}
|
||||
|
||||
$extension = strtolower(pathinfo($value, PATHINFO_EXTENSION));
|
||||
$allowed = self::getAllowedExtensions();
|
||||
|
||||
if (! in_array($extension, self::ALLOWED_EXTENSIONS, true)) {
|
||||
if (! in_array($extension, $allowed, true)) {
|
||||
$fail(__('validation.template_path.file_type_not_allowed', [
|
||||
'extension' => $extension,
|
||||
'allowed' => implode(', ', self::ALLOWED_EXTENSIONS),
|
||||
'allowed' => implode(', ', $allowed),
|
||||
]));
|
||||
|
||||
return;
|
||||
@@ -56,9 +53,21 @@ class AllowedTemplateFileType implements ValidationRule
|
||||
|
||||
/**
|
||||
* 허용된 확장자 목록 반환
|
||||
*
|
||||
* 로컬 개발 환경에서만 소스맵(`map`)을 덧붙인다. dev 빌드 산출물은
|
||||
* `//# sourceMappingURL` 이 개별 에셋 서빙 URL 을 가리키므로 서빙되어야
|
||||
* 브라우저 콘솔에 404 가 남지 않는다. 반면 소스맵에는 원본 코드 전문
|
||||
* (`sourcesContent`)이 담겨 있고 이 화이트리스트가 에셋 서빙의 유일한
|
||||
* 방어선이므로, 운영 환경에서는 어떤 경우에도 서빙하지 않는다.
|
||||
*
|
||||
* @return array<string> 허용된 확장자 목록
|
||||
*/
|
||||
public static function getAllowedExtensions(): array
|
||||
{
|
||||
if (app()->environment('local')) {
|
||||
return [...self::ALLOWED_EXTENSIONS, 'map'];
|
||||
}
|
||||
|
||||
return self::ALLOWED_EXTENSIONS;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user