fix(security): 배포본 소스맵 노출 차단 + 관리자 설정 탭 지연로딩 + 동반 결함 수정
## 소스맵 노출 차단 (공개 이슈 )
배포본에 .map 이 포함돼 원본 TS/TSX 전문(sourcesContent, 한글 주석 포함)이
그대로 노출됐다. 생성·서빙·저장소 유입 3계층을 모두 막는다.
- 빌드 config 15곳(코어 3 + _bundled 12): sourcemap 하드코딩 제거.
G7_BUILD_SOURCEMAP 판정식으로 교체 — 미설정(로컬 npm run build)이면 생성해
개발 디버깅 경험을 보존하고, 0 이면 미생성.
- Build{Core,Module,Plugin,Template}Command: 죽어 있던 --production 플래그 복구.
$productionMode 를 콘솔 문자열에만 쓰고 npm 프로세스에 env 를 넘기지 않아
산출물이 개발 빌드와 동일했다. runNpmCommand 에 $env 를 추가해 주입
(--watch 에는 미주입). Symfony Process 는 부모 환경에 병합하므로 PATH 유실 없음.
- Allowed{Module,Plugin}FileType / {Module,Plugin}Service::getMimeType:
허용 확장자 map 제거 — 익명 200 서빙 차단(템플릿은 원래 미허용, 3종 정책 일치).
- ExtensionBundleService: CSS 번들의 /*# sourceMappingURL=... */ strip 추가.
CSS 는 블록 주석이라 JS 의 //# 패턴으로는 검출되지 않던 구멍.
- 추적 .map 13개 삭제 + .gitignore 전역 *.map 규칙(경로 한정 시 새 확장에서 누락).
실측: 산출 JS 의 sourceMappingURL 13 → 0, 추적 .map 13 → 0,
확장 디렉토리 npm run build 는 여전히 map 생성(개발 경험 회귀 없음).
## 관리자 환경설정 탭 지연 로딩
코어/이커머스/게시판 환경설정 화면이 진입 즉시 전 탭의 데이터소스를 한꺼번에
호출했다. 각 데이터소스에 활성 탭 조건(if)을 걸어 해당 탭에서만 fetch 하도록
변경하고, 결제 플러그인 3종의 테스트모드 상태 조회도 주문설정 탭으로 한정.
## 동반 결함 수정 (무관 결함 — 재발 방지 목적으로 같은 세션 처리)
- 나이스페이먼츠: 체크아웃 캐시 프리페치가 라우트를 가리지 않아 플러그인 번들이
로드되는 모든 페이지(홈/게시판/로그인)에서 주문서를 조회 → 비회원 매번 422.
형제 플러그인(kginicis)의 기존 가드 패턴을 적용해 체크아웃 경로로 한정.
- admin smoke 8건: 대부분 구현이 아니라 테스트 결함이었다 — URL 오타(단수 board),
존재하지 않는 권한키, 앱 로케일이 en 인데 한국어 라벨 로케이터, DataGrid 버튼을
먼저 잡던 휴리스틱 로케이터. 레이아웃에는 sticky className / 안정 id 를 부여.
- PHPDoc ↔ Pint 충돌 3건: 설명 없는 @param 은 no_superfluous_phpdoc_tags 가
삭제해 audit phpdoc-public-method 와 무한 충돌. 한국어 설명을 붙여 양쪽 충족
(리스너 3종의 설명 누락 메서드도 전수 보강).
- Log::spy 500 3건: spy 가 Log::channel('activity') 를 null 로 만들고
logActivity 가 null->info 로 \Error → 같은 줄 catch(\Exception) 은 못 잡아
통과. 운영에선 채널이 항상 로거이므로 제품 무결 → 테스트에 activity 채널
보존 헬퍼 추가.
- NhnKcpApiServiceTest 5건: 스텁이 Unix 바이너리만 만들어 Windows 분기
(pp_cli_exe.exe)에서만 실패. #!/bin/sh 는 Windows 실행 불가 → 파일 내 기존
컨벤션대로 skip 가드.
## 테스트
- 소스맵 범위 130 passed (신규: BuildCommandSourcemapEnv, NoSourcemapArtifacts,
ExtensionBundleService CSS strip, Allowed*FileType 반전, 자산 서빙 거부)
- 결제 3플러그인 505 passed / 0 failed (skipped 9 = Windows 전용 CLI, 사유 명시)
- 나이스페이먼츠 프론트 38 passed (가드 제거 시 red 실증 후 복원)
- E2E: production-sourcemap-exposure.spec.ts 6건 + 시나리오 매니페스트
버전: sirsoft-admin_basic 1.0.2 → 1.0.3, sirsoft-board 1.0.1 → 1.0.2
(각 manifest/package/lock/composer 동기화). 코어 7.0.4 는 미출시 누적.
This commit is contained in:
1 parent
84ca40f0d8
commit
90f154ecc0
132 files changed
+10069
-312
No files matched your search
@@ -12,6 +12,7 @@ class ModuleAssetServingTest extends TestCase
|
||||
use RefreshDatabase;
|
||||
|
||||
private Module $activeModule;
|
||||
|
||||
private string $testModulePath;
|
||||
|
||||
protected function setUp(): void
|
||||
@@ -26,10 +27,10 @@ class ModuleAssetServingTest extends TestCase
|
||||
|
||||
// 테스트용 모듈 디렉토리 생성
|
||||
$this->testModulePath = base_path('modules/test-module');
|
||||
if (!file_exists($this->testModulePath.'/dist/js')) {
|
||||
if (! file_exists($this->testModulePath.'/dist/js')) {
|
||||
mkdir($this->testModulePath.'/dist/js', 0755, true);
|
||||
}
|
||||
if (!file_exists($this->testModulePath.'/dist/css')) {
|
||||
if (! file_exists($this->testModulePath.'/dist/css')) {
|
||||
mkdir($this->testModulePath.'/dist/css', 0755, true);
|
||||
}
|
||||
}
|
||||
@@ -49,11 +50,11 @@ class ModuleAssetServingTest extends TestCase
|
||||
*/
|
||||
private function deleteDirectory(string $dir): bool
|
||||
{
|
||||
if (!file_exists($dir)) {
|
||||
if (! file_exists($dir)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!is_dir($dir)) {
|
||||
if (! is_dir($dir)) {
|
||||
return unlink($dir);
|
||||
}
|
||||
|
||||
@@ -62,7 +63,7 @@ class ModuleAssetServingTest extends TestCase
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!$this->deleteDirectory($dir.DIRECTORY_SEPARATOR.$item)) {
|
||||
if (! $this->deleteDirectory($dir.DIRECTORY_SEPARATOR.$item)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -405,19 +406,31 @@ class ModuleAssetServingTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* Source Map 파일 서빙 테스트
|
||||
* Source Map 파일 서빙 거부 테스트
|
||||
*
|
||||
* 소스맵은 원본 코드 전문을 담고 있어 배포 환경에서 노출되면 안 된다.
|
||||
* 파일이 디스크에 실재하더라도(= 파일 부재로 인한 실패가 아님) 허용 확장자
|
||||
* 목록에서 제외되어 서빙이 거부되어야 한다.
|
||||
*/
|
||||
public function test_serves_sourcemap_file(): void
|
||||
public function test_rejects_sourcemap_file(): void
|
||||
{
|
||||
// Arrange
|
||||
// Arrange: 맵 파일이 실제로 존재하는 상태를 만든다
|
||||
$mapPath = $this->testModulePath.'/dist/js/module.iife.js.map';
|
||||
file_put_contents($mapPath, '{"version":3,"sources":[],"mappings":""}');
|
||||
$this->assertFileExists($mapPath);
|
||||
|
||||
// Act
|
||||
$response = $this->get('/api/modules/assets/test-module/dist/js/module.iife.js.map');
|
||||
// Act: JSON 클라이언트 (에러 본문 확인용)
|
||||
$json = $this->getJson('/api/modules/assets/test-module/dist/js/module.iife.js.map');
|
||||
|
||||
// Assert
|
||||
$response->assertStatus(200);
|
||||
$response->assertHeader('Content-Type', 'application/json');
|
||||
// Assert: 허용 확장자 검증에서 거부 — 맵 내용이 절대 응답에 실리지 않는다
|
||||
$json->assertStatus(422);
|
||||
$json->assertJsonValidationErrors('path');
|
||||
$this->assertStringNotContainsString('mappings', $json->getContent());
|
||||
|
||||
// Act: 브라우저 요청 (Accept 헤더 없음) — 서빙되지 않음을 확인
|
||||
$browser = $this->get('/api/modules/assets/test-module/dist/js/module.iife.js.map');
|
||||
|
||||
// Assert: 200 서빙이 아니어야 한다 (검증 실패 → 리다이렉트)
|
||||
$this->assertNotSame(200, $browser->getStatusCode());
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,7 @@ class PluginAssetServingTest extends TestCase
|
||||
use RefreshDatabase;
|
||||
|
||||
private Plugin $activePlugin;
|
||||
|
||||
private string $testPluginPath;
|
||||
|
||||
protected function setUp(): void
|
||||
@@ -26,10 +27,10 @@ class PluginAssetServingTest extends TestCase
|
||||
|
||||
// 테스트용 플러그인 디렉토리 생성
|
||||
$this->testPluginPath = base_path('plugins/test-plugin');
|
||||
if (!file_exists($this->testPluginPath.'/dist/js')) {
|
||||
if (! file_exists($this->testPluginPath.'/dist/js')) {
|
||||
mkdir($this->testPluginPath.'/dist/js', 0755, true);
|
||||
}
|
||||
if (!file_exists($this->testPluginPath.'/dist/css')) {
|
||||
if (! file_exists($this->testPluginPath.'/dist/css')) {
|
||||
mkdir($this->testPluginPath.'/dist/css', 0755, true);
|
||||
}
|
||||
}
|
||||
@@ -49,11 +50,11 @@ class PluginAssetServingTest extends TestCase
|
||||
*/
|
||||
private function deleteDirectory(string $dir): bool
|
||||
{
|
||||
if (!file_exists($dir)) {
|
||||
if (! file_exists($dir)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!is_dir($dir)) {
|
||||
if (! is_dir($dir)) {
|
||||
return unlink($dir);
|
||||
}
|
||||
|
||||
@@ -62,7 +63,7 @@ class PluginAssetServingTest extends TestCase
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!$this->deleteDirectory($dir.DIRECTORY_SEPARATOR.$item)) {
|
||||
if (! $this->deleteDirectory($dir.DIRECTORY_SEPARATOR.$item)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -419,19 +420,31 @@ class PluginAssetServingTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* Source Map 파일 서빙 테스트
|
||||
* Source Map 파일 서빙 거부 테스트
|
||||
*
|
||||
* 소스맵은 원본 코드 전문을 담고 있어 배포 환경에서 노출되면 안 된다.
|
||||
* 파일이 디스크에 실재하더라도(= 파일 부재로 인한 실패가 아님) 허용 확장자
|
||||
* 목록에서 제외되어 서빙이 거부되어야 한다.
|
||||
*/
|
||||
public function test_serves_sourcemap_file(): void
|
||||
public function test_rejects_sourcemap_file(): void
|
||||
{
|
||||
// Arrange
|
||||
// Arrange: 맵 파일이 실제로 존재하는 상태를 만든다
|
||||
$mapPath = $this->testPluginPath.'/dist/js/plugin.iife.js.map';
|
||||
file_put_contents($mapPath, '{"version":3,"sources":[],"mappings":""}');
|
||||
$this->assertFileExists($mapPath);
|
||||
|
||||
// Act
|
||||
$response = $this->get('/api/plugins/assets/test-plugin/dist/js/plugin.iife.js.map');
|
||||
// Act: JSON 클라이언트 (에러 본문 확인용)
|
||||
$json = $this->getJson('/api/plugins/assets/test-plugin/dist/js/plugin.iife.js.map');
|
||||
|
||||
// Assert
|
||||
$response->assertStatus(200);
|
||||
$response->assertHeader('Content-Type', 'application/json');
|
||||
// Assert: 허용 확장자 검증에서 거부 — 맵 내용이 절대 응답에 실리지 않는다
|
||||
$json->assertStatus(422);
|
||||
$json->assertJsonValidationErrors('path');
|
||||
$this->assertStringNotContainsString('mappings', $json->getContent());
|
||||
|
||||
// Act: 브라우저 요청 (Accept 헤더 없음) — 서빙되지 않음을 확인
|
||||
$browser = $this->get('/api/plugins/assets/test-plugin/dist/js/plugin.iife.js.map');
|
||||
|
||||
// Assert: 200 서빙이 아니어야 한다 (검증 실패 → 리다이렉트)
|
||||
$this->assertNotSame(200, $browser->getStatusCode());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,149 @@
|
||||
/**
|
||||
* E2E: 프로덕션 소스맵 노출 차단 회귀 검증
|
||||
*
|
||||
* @scenario production-sourcemap-exposure
|
||||
* @effects no_sourcemap_requests_from_loaded_bundles,
|
||||
* page_renders_without_map_related_console_errors,
|
||||
* module_sourcemap_asset_request_rejected_even_when_file_exists,
|
||||
* plugin_sourcemap_asset_request_rejected_even_when_file_exists
|
||||
*
|
||||
* 배경: 소스맵(.map)에는 원본 TS/TSX 전문이 담긴다. 배포 산출물에서 (1) 맵 생성 자체를
|
||||
* 막고, (2) 서빙을 거부하며, (3) 저장소 유입을 차단했다.
|
||||
*
|
||||
* 이 spec 은 브라우저 실측으로 두 가지를 고정한다:
|
||||
* - 로드된 코어/확장 번들이 맵을 요청하지 않는다 (sourceMappingURL 주석 부재의 결과)
|
||||
* - 맵 주석 제거가 번들을 깨뜨리지 않았다 (페이지 정상 렌더 + 콘솔 에러 없음)
|
||||
*
|
||||
* 주의: 맵 주석이 남아있는데 .map 만 지운 상태였다면 브라우저가 맵을 요청해 404 가
|
||||
* 발생한다. 이 spec 은 그 회귀(주석/파일 불일치)도 함께 잡는다.
|
||||
*/
|
||||
import { test, expect } from '@playwright/test';
|
||||
|
||||
/** 소스맵 요청으로 간주할 URL 패턴 */
|
||||
const MAP_REQUEST = /\.map(\?|$)/;
|
||||
|
||||
test.describe('프로덕션 소스맵 노출 차단', () => {
|
||||
test('@smoke 사용자 페이지 로드 시 소스맵을 요청하지 않는다', async ({ page }) => {
|
||||
const mapRequests: string[] = [];
|
||||
page.on('request', (req) => {
|
||||
if (MAP_REQUEST.test(req.url())) {
|
||||
mapRequests.push(req.url());
|
||||
}
|
||||
});
|
||||
|
||||
await page.goto('/');
|
||||
await page.waitForLoadState('networkidle', { timeout: 30_000 });
|
||||
|
||||
expect(
|
||||
mapRequests,
|
||||
`소스맵 요청이 발생했습니다(산출물에 sourceMappingURL 주석 잔존): ${mapRequests.join(', ')}`,
|
||||
).toHaveLength(0);
|
||||
});
|
||||
|
||||
test('@smoke 관리자 페이지 로드 시 소스맵을 요청하지 않는다', async ({ page }) => {
|
||||
const mapRequests: string[] = [];
|
||||
page.on('request', (req) => {
|
||||
if (MAP_REQUEST.test(req.url())) {
|
||||
mapRequests.push(req.url());
|
||||
}
|
||||
});
|
||||
|
||||
// 로그인 전 진입 화면이라도 코어 번들(template-engine)은 로드된다
|
||||
await page.goto('/admin');
|
||||
await page.waitForLoadState('networkidle', { timeout: 30_000 });
|
||||
|
||||
expect(
|
||||
mapRequests,
|
||||
`관리자 페이지에서 소스맵 요청 발생: ${mapRequests.join(', ')}`,
|
||||
).toHaveLength(0);
|
||||
});
|
||||
|
||||
test('@smoke 맵 주석 제거 후에도 페이지가 정상 렌더된다', async ({ page }) => {
|
||||
const consoleErrors: string[] = [];
|
||||
page.on('console', (msg) => {
|
||||
if (msg.type() === 'error') {
|
||||
consoleErrors.push(msg.text());
|
||||
}
|
||||
});
|
||||
|
||||
// 정적 에셋(JS/CSS/MAP) 로드 실패만 수집한다. 도메인 API 응답(예: 이커머스
|
||||
// checkout 검증 422)은 소스맵 정책과 무관하므로 이 spec 의 판정 대상이 아니다.
|
||||
const failedAssets: string[] = [];
|
||||
page.on('response', (res) => {
|
||||
if (res.status() >= 400 && /\.(js|css|map)(\?|$)/.test(res.url())) {
|
||||
failedAssets.push(`${res.url()} → ${res.status()}`);
|
||||
}
|
||||
});
|
||||
|
||||
await page.goto('/');
|
||||
await page.waitForLoadState('networkidle', { timeout: 30_000 });
|
||||
|
||||
// 렌더 성공 = 코어 엔진 + 확장 번들이 모두 정상 파싱/실행됨
|
||||
await expect(page.getByTestId('nav-home')).toBeVisible({ timeout: 15_000 });
|
||||
|
||||
// 맵 주석만 남고 파일이 없으면 404 가 뜬다 (주석/파일 불일치 회귀)
|
||||
expect(
|
||||
failedAssets,
|
||||
`에셋 로드 실패(맵/JS/CSS): ${failedAssets.join(' | ')}`,
|
||||
).toHaveLength(0);
|
||||
|
||||
// 맵 주석 제거가 번들을 깨뜨렸다면 파싱/실행 에러가 뜬다.
|
||||
const parseErrors = consoleErrors.filter((e) =>
|
||||
/Unexpected token|SyntaxError|is not defined/i.test(e),
|
||||
);
|
||||
expect(parseErrors, `번들 실행 관련 콘솔 에러: ${parseErrors.join(' | ')}`).toHaveLength(0);
|
||||
});
|
||||
|
||||
test('@smoke 확장 소스맵 에셋은 직접 요청해도 서빙되지 않는다', async ({ request }) => {
|
||||
// 디스크에 맵이 없더라도, 허용 확장자에서 제외됐으므로 200 이 나오면 안 된다.
|
||||
const targets = [
|
||||
'/api/modules/assets/sirsoft-ecommerce/dist/js/module.iife.js.map',
|
||||
'/api/plugins/assets/sirsoft-gdpr/dist/js/plugin.iife.js.map',
|
||||
];
|
||||
|
||||
for (const target of targets) {
|
||||
const res = await request.get(target, { maxRedirects: 0, failOnStatusCode: false });
|
||||
|
||||
expect(res.status(), `${target} 이 200 으로 서빙됨 — 소스맵 노출`).not.toBe(200);
|
||||
|
||||
const body = await res.text().catch(() => '');
|
||||
expect(
|
||||
body.includes('sourcesContent'),
|
||||
`${target} 응답에 원본 코드(sourcesContent)가 포함됨`,
|
||||
).toBe(false);
|
||||
}
|
||||
});
|
||||
|
||||
test('@smoke 결제 플러그인이 체크아웃 외 페이지에서 체크아웃을 프리페치하지 않는다', async ({ page }) => {
|
||||
// 플러그인 번들은 모든 페이지에 로드된다. nicepayments 캐시 프리페치가 경로를
|
||||
// 가리지 않으면 비회원이 모든 페이지에서 422(cart_key_required)를 받는다.
|
||||
const checkoutRequests: string[] = [];
|
||||
page.on('request', (req) => {
|
||||
if (req.url().includes('/sirsoft-ecommerce/checkout')) {
|
||||
checkoutRequests.push(req.url());
|
||||
}
|
||||
});
|
||||
|
||||
await page.goto('/');
|
||||
await page.waitForLoadState('networkidle', { timeout: 30_000 });
|
||||
|
||||
expect(
|
||||
checkoutRequests,
|
||||
`홈에서 체크아웃 프리페치 발생: ${checkoutRequests.join(', ')}`,
|
||||
).toHaveLength(0);
|
||||
});
|
||||
|
||||
test('@smoke 코어 소스맵은 웹루트에서 서빙되지 않는다', async ({ request }) => {
|
||||
const targets = [
|
||||
'/build/core/template-engine.min.js.map',
|
||||
'/build/core/layout-editor.min.js.map',
|
||||
'/build/core/devtools.min.js.map',
|
||||
];
|
||||
|
||||
for (const target of targets) {
|
||||
const res = await request.get(target, { maxRedirects: 0, failOnStatusCode: false });
|
||||
|
||||
expect(res.status(), `${target} 이 200 으로 서빙됨 — 원본 코드 노출`).not.toBe(200);
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -67,7 +67,11 @@ test('@smoke #399 Phase 1.3 - admin_settings 진입 시 sticky-tab-nav 시맨틱
|
||||
|
||||
// TabNavigation composite (variant="default") 가 .tab-nav-default 컨테이너 + .tab-btn-base 탭 버튼을 렌더해야 한다.
|
||||
// 인라인 Tailwind (flex gap-2, flex items-center gap-2 px-4 py-2 ...) → 시맨틱 클래스로 흡수됨.
|
||||
const nav = stickyNav.locator('nav.tab-nav-default').first();
|
||||
//
|
||||
// TabNavigation 은 자신이 <nav> 를 렌더하고 id 를 그 위에 얹는다(Nav id={id}).
|
||||
// 따라서 #tab_navigation 이 곧 nav.tab-nav-default 이며, 그 안에 또 nav 가 있지 않다.
|
||||
const nav = stickyNav;
|
||||
await expect(nav).toHaveClass(/tab-nav-default/);
|
||||
await expect(nav).toBeVisible();
|
||||
const firstTabBtn = nav.locator('button.tab-btn-base').first();
|
||||
await expect(firstTabBtn).toBeVisible();
|
||||
@@ -76,10 +80,15 @@ test('@smoke #399 Phase 1.3 - admin_settings 진입 시 sticky-tab-nav 시맨틱
|
||||
});
|
||||
|
||||
test('@smoke #399 Phase 1.4 - admin_board_settings 진입 시 sticky_header 가 sticky-section-header 시맨틱으로 마운트된다', async ({ page }) => {
|
||||
const token = issueToken('sirsoft-board.settings.view');
|
||||
// admin_board_settings.json 의 permissions 는 `sirsoft-board.settings.read` 다.
|
||||
// (`...settings.view` 는 존재하지 않는 권한 키라 403 Access Denied 로 떨어진다)
|
||||
const token = issueToken('sirsoft-board.settings.read');
|
||||
await authenticatePage(page, token);
|
||||
|
||||
await page.goto('/admin/board/settings');
|
||||
// 게시판 설정의 실제 라우트는 복수형 `/admin/boards/settings` 다.
|
||||
// 단수형 `/admin/board/settings` 는 `*/admin/board/:slug`(게시글 목록) 에 매칭되어
|
||||
// slug="settings" 인 존재하지 않는 게시판을 조회 → 403 으로 떨어진다.
|
||||
await page.goto('/admin/boards/settings');
|
||||
await page.waitForLoadState('domcontentloaded', { timeout: 30_000 });
|
||||
await page.waitForFunction(
|
||||
() => !window.location.pathname.includes('/admin/login') || document.readyState === 'complete',
|
||||
@@ -254,6 +263,13 @@ test('@smoke #399 Phase 1.13 - admin_identity_logs 의 filter_section (필터-
|
||||
|
||||
// Phase 1.13 정정: gap-3 같은 비표준 토큰도 .filter-grid 로 통일.
|
||||
// #advanced_filters 도 filter-grid 시맨틱을 가지도록 표준화 확인.
|
||||
//
|
||||
// 단, #advanced_filters 는 `if: _local.filter.advancedOpen === true` 로 접혀 있는
|
||||
// 조건부 노드다. 고급 검색을 펼치지 않으면 DOM 에 존재하지 않으므로, 실제 사용자
|
||||
// 흐름대로 토글을 먼저 연 뒤 시맨틱을 검증한다.
|
||||
await page.locator('#advanced_filters_toggle').click();
|
||||
|
||||
await expect(page.locator('#advanced_filters')).toBeVisible({ timeout: 10_000 });
|
||||
await expect(page.locator('#advanced_filters')).toHaveClass(/filter-grid/);
|
||||
});
|
||||
|
||||
|
||||
@@ -91,14 +91,9 @@ test('@smoke 본인인증 이력 — 발생 유형(고급 검색) 필터 체크
|
||||
);
|
||||
|
||||
// 고급 검색 토글을 펼치면 발생 유형(origin_type) 7종 체크박스가 추가로 나타나야 한다.
|
||||
// 로케일 비의존: 펼침 토글은 마지막 toggle 성격 버튼 — chevron 아이콘을 가진 버튼을 클릭한다.
|
||||
await page.evaluate(() => {
|
||||
const btns = Array.from(document.querySelectorAll('button'));
|
||||
// '고급 검색' / 'Advanced' 텍스트 또는 chevron 아이콘 보유 버튼
|
||||
const target = btns.find((b) => /고급|advanced/i.test(b.textContent || '')
|
||||
|| b.querySelector('[class*="chevron"]'));
|
||||
(target as HTMLButtonElement | undefined)?.click();
|
||||
});
|
||||
// 토글은 안정적인 id 로 특정한다. 텍스트/chevron 휴리스틱으로 찾으면 DataGrid 의
|
||||
// 행 펼침(Expand row) 버튼 등 다른 chevron 버튼을 먼저 잡아 오작동한다.
|
||||
await page.locator('#advanced_filters_toggle').click();
|
||||
|
||||
await page.waitForFunction(
|
||||
(prev) => document.querySelectorAll('input[type="checkbox"]').length > prev,
|
||||
|
||||
@@ -53,6 +53,19 @@ async function fieldDisabled(page: import('@playwright/test').Page, labelText: s
|
||||
}
|
||||
|
||||
/** 목록에서 주어진 출처 필터로 첫 행의 [편집] 버튼 클릭 */
|
||||
/**
|
||||
* 앱 로케일을 ko 로 고정한다.
|
||||
*
|
||||
* 본 spec 은 한국어 라벨('편집', '정책 키', '+ 정책 추가' 등)로 요소를 특정한다.
|
||||
* 앱 로케일이 en 이면 전부 매칭 실패하므로 첫 페이지 로드 전에 고정해야 한다
|
||||
* (엔진은 localStorage.g7_locale 을 사용).
|
||||
*/
|
||||
async function forceKoreanLocale(page: import('@playwright/test').Page) {
|
||||
await page.addInitScript(() => {
|
||||
try { window.localStorage.setItem('g7_locale', 'ko'); } catch { /* noop */ }
|
||||
});
|
||||
}
|
||||
|
||||
async function openFirstEditModal(page: import('@playwright/test').Page, sourceType: string) {
|
||||
const listResp = page.waitForResponse(
|
||||
(r) =>
|
||||
@@ -74,6 +87,7 @@ async function openFirstEditModal(page: import('@playwright/test').Page, sourceT
|
||||
|
||||
test('@smoke 코어 정책 편집 모달 — 키/강제시점/강제위치만 잠금 + 인증목적·적용대상 포함 그 외 편집가능', async ({ page }) => {
|
||||
await authenticatePage(page, policyToken());
|
||||
await forceKoreanLocale(page);
|
||||
await openFirstEditModal(page, 'core');
|
||||
|
||||
// 잠금 필드 (정책이 걸리는 지점 식별자 3종만)
|
||||
@@ -96,6 +110,7 @@ test('@smoke 코어 정책 편집 모달 — 키/강제시점/강제위치만
|
||||
|
||||
test('@smoke 운영자 정책 편집 모달 — 모든 필드 편집가능 + 안내 문구 미노출', async ({ page }) => {
|
||||
await authenticatePage(page, policyToken());
|
||||
await forceKoreanLocale(page);
|
||||
|
||||
// 운영자 정책이 없으면 생성(테스트 자족) — 생성 후 admin 필터로 편집 진입
|
||||
const createResp = page.waitForResponse(
|
||||
|
||||
@@ -0,0 +1,133 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Extension;
|
||||
|
||||
use App\Console\Commands\Core\BuildCoreCommand;
|
||||
use App\Console\Commands\Module\BuildModuleCommand;
|
||||
use App\Console\Commands\Plugin\BuildPluginCommand;
|
||||
use App\Console\Commands\Template\BuildTemplateCommand;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use ReflectionMethod;
|
||||
use ReflectionNamedType;
|
||||
use Symfony\Component\Process\Process;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* 빌드 커맨드 소스맵 억제 환경변수 주입 테스트
|
||||
*
|
||||
* `--production` 빌드는 소스맵을 생성하지 않아야 한다. 소스맵에는 원본 코드
|
||||
* 전문(sourcesContent)이 담기므로 배포 산출물에 포함되면 코드가 그대로 노출된다.
|
||||
*
|
||||
* 판정 신호는 각 vite config 가 읽는 `G7_BUILD_SOURCEMAP` 환경변수이며,
|
||||
* 빌드 커맨드가 이 값을 npm 프로세스에 주입하는 책임을 진다. 실제 npm 실행 없이
|
||||
* 주입 지점(buildEnv) 과 전달 통로(runNpmCommand 시그니처) 를 검증한다.
|
||||
*/
|
||||
class BuildCommandSourcemapEnvTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* 빌드 커맨드 클래스 목록
|
||||
*
|
||||
* @return array<string, array{class-string}>
|
||||
*/
|
||||
public static function buildCommandProvider(): array
|
||||
{
|
||||
return [
|
||||
'core' => [BuildCoreCommand::class],
|
||||
'module' => [BuildModuleCommand::class],
|
||||
'plugin' => [BuildPluginCommand::class],
|
||||
'template' => [BuildTemplateCommand::class],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 프로덕션 빌드 시 소스맵 억제 환경변수가 주입되는지 테스트
|
||||
*
|
||||
* @param class-string $commandClass 빌드 커맨드 클래스
|
||||
*/
|
||||
#[DataProvider('buildCommandProvider')]
|
||||
public function test_production_build_injects_sourcemap_off_env(string $commandClass): void
|
||||
{
|
||||
$env = $this->invokeBuildEnv($commandClass, productionMode: true);
|
||||
|
||||
$this->assertSame(['G7_BUILD_SOURCEMAP' => '0'], $env);
|
||||
}
|
||||
|
||||
/**
|
||||
* 일반(비프로덕션) 빌드에는 환경변수를 주입하지 않는지 테스트
|
||||
*
|
||||
* 미주입 시 vite config 의 기본값이 적용되어 소스맵이 생성된다.
|
||||
* 개발자가 확장 디렉토리에서 `npm run build` 를 직접 치는 흐름과 동일하게 유지된다.
|
||||
*
|
||||
* @param class-string $commandClass 빌드 커맨드 클래스
|
||||
*/
|
||||
#[DataProvider('buildCommandProvider')]
|
||||
public function test_non_production_build_injects_nothing(string $commandClass): void
|
||||
{
|
||||
$env = $this->invokeBuildEnv($commandClass, productionMode: false);
|
||||
|
||||
$this->assertSame([], $env);
|
||||
}
|
||||
|
||||
/**
|
||||
* runNpmCommand() 가 env 를 전달받을 수 있는 시그니처인지 테스트
|
||||
*
|
||||
* buildEnv() 가 올바른 값을 만들어도 runNpmCommand() 가 이를 받지 못하면
|
||||
* 주입이 프로세스까지 도달하지 못한다(이번 이슈 이전의 죽은 `--production` 상태).
|
||||
*
|
||||
* @param class-string $commandClass 빌드 커맨드 클래스
|
||||
*/
|
||||
#[DataProvider('buildCommandProvider')]
|
||||
public function test_run_npm_command_accepts_env_argument(string $commandClass): void
|
||||
{
|
||||
$method = new ReflectionMethod($commandClass, 'runNpmCommand');
|
||||
$params = $method->getParameters();
|
||||
|
||||
$envParam = null;
|
||||
foreach ($params as $param) {
|
||||
if ($param->getName() === 'env') {
|
||||
$envParam = $param;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$this->assertNotNull($envParam, "{$commandClass}::runNpmCommand() 에 env 파라미터가 없습니다.");
|
||||
|
||||
$type = $envParam->getType();
|
||||
$this->assertInstanceOf(ReflectionNamedType::class, $type);
|
||||
$this->assertSame('array', $type->getName());
|
||||
$this->assertTrue($envParam->isDefaultValueAvailable(), 'env 는 기본값을 가져야 한다(기존 호출부 호환).');
|
||||
$this->assertSame([], $envParam->getDefaultValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Symfony Process 가 지정한 env 를 부모 환경에 병합하는지 테스트
|
||||
*
|
||||
* setEnv() 가 부모 환경을 대체(replace)한다면 PATH 가 소실되어 npm 실행 자체가
|
||||
* 깨진다. 추가분만 넘기는 현재 구현의 전제를 고정한다.
|
||||
*/
|
||||
public function test_process_env_merges_with_parent_environment(): void
|
||||
{
|
||||
$process = new Process(['echo', 'test']);
|
||||
$process->setEnv(['G7_BUILD_SOURCEMAP' => '0']);
|
||||
|
||||
$this->assertSame(['G7_BUILD_SOURCEMAP' => '0'], $process->getEnv());
|
||||
|
||||
// PATH 는 부모 환경에서 상속되므로 setEnv 로 지우지 않는다.
|
||||
$this->assertNotEmpty(getenv('PATH') ?: getenv('Path'), '부모 환경에 PATH 가 있어야 병합 전제가 성립한다.');
|
||||
}
|
||||
|
||||
/**
|
||||
* 커맨드의 private buildEnv() 를 호출합니다.
|
||||
*
|
||||
* @param class-string $commandClass 빌드 커맨드 클래스
|
||||
* @param bool $productionMode 프로덕션 빌드 여부
|
||||
* @return array<string, string> 주입될 환경변수
|
||||
*/
|
||||
private function invokeBuildEnv(string $commandClass, bool $productionMode): array
|
||||
{
|
||||
$command = app($commandClass);
|
||||
$method = new ReflectionMethod($commandClass, 'buildEnv');
|
||||
|
||||
return $method->invoke($command, $productionMode);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Extension;
|
||||
|
||||
use Symfony\Component\Process\Process;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* 소스맵 산출물 재유입 회귀 가드
|
||||
*
|
||||
* 소스맵(.map)에는 원본 TS/TSX 전문(sourcesContent)이 담긴다. 저장소에 유입되면
|
||||
* 그대로 공개 배포판(release)에 실려 코드가 노출된다.
|
||||
*
|
||||
* 방어선은 두 겹이다:
|
||||
* 1) 빌드 단계 — `--production` 이 G7_BUILD_SOURCEMAP=0 을 주입해 생성 자체를 차단
|
||||
* 2) 저장소 단계 — .gitignore 의 전역 `*.map` 규칙으로 유입 차단
|
||||
*
|
||||
* 이 테스트는 (2)가 실효적인지, 그리고 추적 중인 산출 JS 에 맵 참조 주석이
|
||||
* 남아 있지 않은지를 고정한다. 새 확장이 추가될 때 조용히 누락되는 것을 막는다.
|
||||
*/
|
||||
class NoSourcemapArtifactsTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* git 추적 파일 중 .map 이 하나도 없는지 테스트
|
||||
*/
|
||||
public function test_no_sourcemap_files_are_tracked_by_git(): void
|
||||
{
|
||||
$tracked = $this->git(['ls-files', '*.map']);
|
||||
|
||||
$this->assertSame(
|
||||
[],
|
||||
$tracked,
|
||||
"소스맵이 git 에 추적되고 있습니다. 원본 코드가 배포판에 노출됩니다:\n ".
|
||||
implode("\n ", $tracked)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* .gitignore 가 소스맵을 실제로 무시하는지 테스트
|
||||
*
|
||||
* 규칙이 존재해도 다른 규칙에 의해 무력화될 수 있으므로 git 에 직접 판정시킨다.
|
||||
*/
|
||||
public function test_gitignore_actually_ignores_sourcemap_files(): void
|
||||
{
|
||||
$probe = 'public/build/core/__sourcemap_guard_probe__.js.map';
|
||||
|
||||
$result = $this->git(['check-ignore', $probe]);
|
||||
|
||||
$this->assertContains(
|
||||
$probe,
|
||||
$result,
|
||||
'.gitignore 가 .map 을 무시하지 않습니다. 빌드 산출 소스맵이 저장소에 유입될 수 있습니다.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 추적 중인 빌드 산출 JS 에 sourceMappingURL 주석이 없는지 테스트
|
||||
*
|
||||
* 주석만 남고 .map 이 없으면 브라우저가 404 를 일으키고, 주석과 .map 이 함께
|
||||
* 있으면 원본이 노출된다. 배포 산출물에는 둘 다 없어야 한다.
|
||||
*
|
||||
* 판정 대상은 워킹트리(= 지금 배포하면 나갈 상태)다. HEAD(직전 커밋)를 보면
|
||||
* 워킹트리에서 이미 고친 내용을 반영하지 못한다.
|
||||
*/
|
||||
public function test_tracked_build_output_has_no_source_mapping_url(): void
|
||||
{
|
||||
$offenders = $this->git([
|
||||
'grep', '--files-with-matches', 'sourceMappingURL', '--',
|
||||
'public/build/core/*.js',
|
||||
'modules/_bundled/*/dist/js/*.js',
|
||||
'plugins/_bundled/*/dist/js/*.js',
|
||||
'templates/_bundled/*/dist/js/*.js',
|
||||
]);
|
||||
|
||||
$this->assertSame(
|
||||
[],
|
||||
$offenders,
|
||||
"배포 산출 JS 에 소스맵 참조 주석이 남아 있습니다(--production 재빌드 필요):\n ".
|
||||
implode("\n ", $offenders)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* git 명령을 실행하고 출력 라인 배열을 반환합니다.
|
||||
*
|
||||
* @param array<int, string> $args git 인자
|
||||
* @return array<int, string> 출력 라인 (빈 줄 제외)
|
||||
*/
|
||||
private function git(array $args): array
|
||||
{
|
||||
$process = new Process(array_merge(['git'], $args), base_path());
|
||||
$process->run();
|
||||
|
||||
$lines = preg_split('/\R/', trim($process->getOutput())) ?: [];
|
||||
|
||||
return array_values(array_filter($lines, fn (string $line): bool => $line !== ''));
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,7 @@ class AllowedModuleFileTypeTest extends TestCase
|
||||
*/
|
||||
public function test_allows_javascript_files(): void
|
||||
{
|
||||
$rule = new AllowedModuleFileType();
|
||||
$rule = new AllowedModuleFileType;
|
||||
|
||||
$jsFiles = ['dist/js/module.iife.js', 'app.js', 'script.mjs'];
|
||||
|
||||
@@ -32,7 +32,7 @@ class AllowedModuleFileTypeTest extends TestCase
|
||||
*/
|
||||
public function test_allows_css_files(): void
|
||||
{
|
||||
$rule = new AllowedModuleFileType();
|
||||
$rule = new AllowedModuleFileType;
|
||||
$validator = Validator::make(
|
||||
['path' => 'dist/css/module.css'],
|
||||
['path' => $rule]
|
||||
@@ -46,7 +46,7 @@ class AllowedModuleFileTypeTest extends TestCase
|
||||
*/
|
||||
public function test_allows_json_files(): void
|
||||
{
|
||||
$rule = new AllowedModuleFileType();
|
||||
$rule = new AllowedModuleFileType;
|
||||
$validator = Validator::make(
|
||||
['path' => 'data/config.json'],
|
||||
['path' => $rule]
|
||||
@@ -56,17 +56,20 @@ class AllowedModuleFileTypeTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* Source Map 파일이 허용되는지 테스트
|
||||
* Source Map 파일이 차단되는지 테스트
|
||||
*
|
||||
* 소스맵에는 원본 코드 전문(sourcesContent)이 담기므로 서빙되면 안 된다.
|
||||
* 플러그인/템플릿과 동일한 정책이다.
|
||||
*/
|
||||
public function test_allows_sourcemap_files(): void
|
||||
public function test_blocks_sourcemap_files(): void
|
||||
{
|
||||
$rule = new AllowedModuleFileType();
|
||||
$rule = new AllowedModuleFileType;
|
||||
$validator = Validator::make(
|
||||
['path' => 'dist/js/module.iife.js.map'],
|
||||
['path' => $rule]
|
||||
);
|
||||
|
||||
$this->assertTrue($validator->passes());
|
||||
$this->assertFalse($validator->passes());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -74,7 +77,7 @@ class AllowedModuleFileTypeTest extends TestCase
|
||||
*/
|
||||
public function test_allows_image_files(): void
|
||||
{
|
||||
$rule = new AllowedModuleFileType();
|
||||
$rule = new AllowedModuleFileType;
|
||||
$imageFiles = [
|
||||
'images/logo.png',
|
||||
'images/photo.jpg',
|
||||
@@ -100,7 +103,7 @@ class AllowedModuleFileTypeTest extends TestCase
|
||||
*/
|
||||
public function test_allows_font_files(): void
|
||||
{
|
||||
$rule = new AllowedModuleFileType();
|
||||
$rule = new AllowedModuleFileType;
|
||||
$fontFiles = [
|
||||
'fonts/roboto.woff',
|
||||
'fonts/roboto.woff2',
|
||||
@@ -124,7 +127,7 @@ class AllowedModuleFileTypeTest extends TestCase
|
||||
*/
|
||||
public function test_blocks_php_files(): void
|
||||
{
|
||||
$rule = new AllowedModuleFileType();
|
||||
$rule = new AllowedModuleFileType;
|
||||
$phpFiles = ['malicious.php', 'index.phtml', 'shell.php3', 'backdoor.php4', 'exploit.php5', 'hack.phps'];
|
||||
|
||||
foreach ($phpFiles as $file) {
|
||||
@@ -142,7 +145,7 @@ class AllowedModuleFileTypeTest extends TestCase
|
||||
*/
|
||||
public function test_blocks_executable_files(): void
|
||||
{
|
||||
$rule = new AllowedModuleFileType();
|
||||
$rule = new AllowedModuleFileType;
|
||||
$executableFiles = ['malware.exe', 'script.sh', 'run.bat', 'library.dll', 'module.so'];
|
||||
|
||||
foreach ($executableFiles as $file) {
|
||||
@@ -160,7 +163,7 @@ class AllowedModuleFileTypeTest extends TestCase
|
||||
*/
|
||||
public function test_blocks_script_files(): void
|
||||
{
|
||||
$rule = new AllowedModuleFileType();
|
||||
$rule = new AllowedModuleFileType;
|
||||
$scriptFiles = ['exploit.py', 'attack.rb', 'hack.pl', 'malicious.cgi'];
|
||||
|
||||
foreach ($scriptFiles as $file) {
|
||||
@@ -178,7 +181,7 @@ class AllowedModuleFileTypeTest extends TestCase
|
||||
*/
|
||||
public function test_blocks_server_script_files(): void
|
||||
{
|
||||
$rule = new AllowedModuleFileType();
|
||||
$rule = new AllowedModuleFileType;
|
||||
$serverScriptFiles = ['page.asp', 'app.aspx', 'index.jsp', 'api.jspx'];
|
||||
|
||||
foreach ($serverScriptFiles as $file) {
|
||||
@@ -196,7 +199,7 @@ class AllowedModuleFileTypeTest extends TestCase
|
||||
*/
|
||||
public function test_blocks_config_files(): void
|
||||
{
|
||||
$rule = new AllowedModuleFileType();
|
||||
$rule = new AllowedModuleFileType;
|
||||
$configFiles = ['.htaccess', '.htpasswd', '.env'];
|
||||
|
||||
foreach ($configFiles as $file) {
|
||||
@@ -214,7 +217,7 @@ class AllowedModuleFileTypeTest extends TestCase
|
||||
*/
|
||||
public function test_case_insensitive_blocking(): void
|
||||
{
|
||||
$rule = new AllowedModuleFileType();
|
||||
$rule = new AllowedModuleFileType;
|
||||
$caseVariations = ['MALICIOUS.PHP', 'Exploit.Php', 'SCRIPT.EXE', 'attack.PY'];
|
||||
|
||||
foreach ($caseVariations as $file) {
|
||||
@@ -238,9 +241,10 @@ class AllowedModuleFileTypeTest extends TestCase
|
||||
$this->assertContains('js', $extensions);
|
||||
$this->assertContains('css', $extensions);
|
||||
$this->assertContains('json', $extensions);
|
||||
$this->assertContains('map', $extensions);
|
||||
$this->assertContains('png', $extensions);
|
||||
$this->assertContains('woff2', $extensions);
|
||||
// 소스맵은 원본 코드가 노출되므로 허용 목록에서 제외 (플러그인/템플릿과 동일)
|
||||
$this->assertNotContains('map', $extensions);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -248,7 +252,7 @@ class AllowedModuleFileTypeTest extends TestCase
|
||||
*/
|
||||
public function test_blocks_non_string_value(): void
|
||||
{
|
||||
$rule = new AllowedModuleFileType();
|
||||
$rule = new AllowedModuleFileType;
|
||||
$validator = Validator::make(
|
||||
['path' => ['array', 'value']],
|
||||
['path' => $rule]
|
||||
|
||||
@@ -13,7 +13,7 @@ class AllowedPluginFileTypeTest extends TestCase
|
||||
*/
|
||||
public function test_allows_javascript_files(): void
|
||||
{
|
||||
$rule = new AllowedPluginFileType();
|
||||
$rule = new AllowedPluginFileType;
|
||||
|
||||
$jsFiles = ['dist/js/plugin.iife.js', 'app.js', 'script.mjs'];
|
||||
|
||||
@@ -32,7 +32,7 @@ class AllowedPluginFileTypeTest extends TestCase
|
||||
*/
|
||||
public function test_allows_css_files(): void
|
||||
{
|
||||
$rule = new AllowedPluginFileType();
|
||||
$rule = new AllowedPluginFileType;
|
||||
$validator = Validator::make(
|
||||
['path' => 'dist/css/plugin.css'],
|
||||
['path' => $rule]
|
||||
@@ -46,7 +46,7 @@ class AllowedPluginFileTypeTest extends TestCase
|
||||
*/
|
||||
public function test_allows_json_files(): void
|
||||
{
|
||||
$rule = new AllowedPluginFileType();
|
||||
$rule = new AllowedPluginFileType;
|
||||
$validator = Validator::make(
|
||||
['path' => 'data/config.json'],
|
||||
['path' => $rule]
|
||||
@@ -56,17 +56,20 @@ class AllowedPluginFileTypeTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* Source Map 파일이 허용되는지 테스트
|
||||
* Source Map 파일이 차단되는지 테스트
|
||||
*
|
||||
* 소스맵에는 원본 코드 전문(sourcesContent)이 담기므로 서빙되면 안 된다.
|
||||
* 모듈/템플릿과 동일한 정책이다.
|
||||
*/
|
||||
public function test_allows_sourcemap_files(): void
|
||||
public function test_blocks_sourcemap_files(): void
|
||||
{
|
||||
$rule = new AllowedPluginFileType();
|
||||
$rule = new AllowedPluginFileType;
|
||||
$validator = Validator::make(
|
||||
['path' => 'dist/js/plugin.iife.js.map'],
|
||||
['path' => $rule]
|
||||
);
|
||||
|
||||
$this->assertTrue($validator->passes());
|
||||
$this->assertFalse($validator->passes());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -74,7 +77,7 @@ class AllowedPluginFileTypeTest extends TestCase
|
||||
*/
|
||||
public function test_allows_image_files(): void
|
||||
{
|
||||
$rule = new AllowedPluginFileType();
|
||||
$rule = new AllowedPluginFileType;
|
||||
$imageFiles = [
|
||||
'images/logo.png',
|
||||
'images/photo.jpg',
|
||||
@@ -100,7 +103,7 @@ class AllowedPluginFileTypeTest extends TestCase
|
||||
*/
|
||||
public function test_allows_font_files(): void
|
||||
{
|
||||
$rule = new AllowedPluginFileType();
|
||||
$rule = new AllowedPluginFileType;
|
||||
$fontFiles = [
|
||||
'fonts/roboto.woff',
|
||||
'fonts/roboto.woff2',
|
||||
@@ -124,7 +127,7 @@ class AllowedPluginFileTypeTest extends TestCase
|
||||
*/
|
||||
public function test_blocks_php_files(): void
|
||||
{
|
||||
$rule = new AllowedPluginFileType();
|
||||
$rule = new AllowedPluginFileType;
|
||||
$phpFiles = ['malicious.php', 'index.phtml', 'shell.php3', 'backdoor.php4', 'exploit.php5', 'hack.phps'];
|
||||
|
||||
foreach ($phpFiles as $file) {
|
||||
@@ -142,7 +145,7 @@ class AllowedPluginFileTypeTest extends TestCase
|
||||
*/
|
||||
public function test_blocks_executable_files(): void
|
||||
{
|
||||
$rule = new AllowedPluginFileType();
|
||||
$rule = new AllowedPluginFileType;
|
||||
$executableFiles = ['malware.exe', 'script.sh', 'run.bat', 'library.dll', 'module.so'];
|
||||
|
||||
foreach ($executableFiles as $file) {
|
||||
@@ -160,7 +163,7 @@ class AllowedPluginFileTypeTest extends TestCase
|
||||
*/
|
||||
public function test_blocks_script_files(): void
|
||||
{
|
||||
$rule = new AllowedPluginFileType();
|
||||
$rule = new AllowedPluginFileType;
|
||||
$scriptFiles = ['exploit.py', 'attack.rb', 'hack.pl', 'malicious.cgi'];
|
||||
|
||||
foreach ($scriptFiles as $file) {
|
||||
@@ -178,7 +181,7 @@ class AllowedPluginFileTypeTest extends TestCase
|
||||
*/
|
||||
public function test_blocks_server_script_files(): void
|
||||
{
|
||||
$rule = new AllowedPluginFileType();
|
||||
$rule = new AllowedPluginFileType;
|
||||
$serverScriptFiles = ['page.asp', 'app.aspx', 'index.jsp', 'api.jspx'];
|
||||
|
||||
foreach ($serverScriptFiles as $file) {
|
||||
@@ -196,7 +199,7 @@ class AllowedPluginFileTypeTest extends TestCase
|
||||
*/
|
||||
public function test_blocks_config_files(): void
|
||||
{
|
||||
$rule = new AllowedPluginFileType();
|
||||
$rule = new AllowedPluginFileType;
|
||||
$configFiles = ['.htaccess', '.htpasswd', '.env'];
|
||||
|
||||
foreach ($configFiles as $file) {
|
||||
@@ -214,7 +217,7 @@ class AllowedPluginFileTypeTest extends TestCase
|
||||
*/
|
||||
public function test_case_insensitive_blocking(): void
|
||||
{
|
||||
$rule = new AllowedPluginFileType();
|
||||
$rule = new AllowedPluginFileType;
|
||||
$caseVariations = ['MALICIOUS.PHP', 'Exploit.Php', 'SCRIPT.EXE', 'attack.PY'];
|
||||
|
||||
foreach ($caseVariations as $file) {
|
||||
@@ -238,9 +241,10 @@ class AllowedPluginFileTypeTest extends TestCase
|
||||
$this->assertContains('js', $extensions);
|
||||
$this->assertContains('css', $extensions);
|
||||
$this->assertContains('json', $extensions);
|
||||
$this->assertContains('map', $extensions);
|
||||
$this->assertContains('png', $extensions);
|
||||
$this->assertContains('woff2', $extensions);
|
||||
// 소스맵은 원본 코드가 노출되므로 허용 목록에서 제외 (모듈/템플릿과 동일)
|
||||
$this->assertNotContains('map', $extensions);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -248,7 +252,7 @@ class AllowedPluginFileTypeTest extends TestCase
|
||||
*/
|
||||
public function test_blocks_non_string_value(): void
|
||||
{
|
||||
$rule = new AllowedPluginFileType();
|
||||
$rule = new AllowedPluginFileType;
|
||||
$validator = Validator::make(
|
||||
['path' => ['array', 'value']],
|
||||
['path' => $rule]
|
||||
|
||||
@@ -189,6 +189,39 @@ class ExtensionBundleServiceTest extends TestCase
|
||||
$this->assertStringContainsString('sourceMappingURL=/api/modules/assets/ext-a/dist/js/a.js.map', $js);
|
||||
}
|
||||
|
||||
public function test_prod_strips_css_source_mapping_url(): void
|
||||
{
|
||||
$this->app['env'] = 'production';
|
||||
app()->detectEnvironment(fn () => 'production');
|
||||
|
||||
// CSS 는 JS 와 주석 문법이 달라 블록 주석으로 맵을 참조한다.
|
||||
$css = $this->writeFixture('a.css', ".a{color:red}\n/*# sourceMappingURL=a.css.map */");
|
||||
|
||||
$this->moduleManager->shouldReceive('getActiveModules')->andReturn([
|
||||
'ext-a' => $this->fakeExtension('ext-a', 10, null, $css),
|
||||
]);
|
||||
|
||||
$bundle = $this->service()->buildCssBundle('module');
|
||||
|
||||
$this->assertStringNotContainsString('sourceMappingURL', $bundle);
|
||||
// 스타일 본문은 보존되어야 한다 (주석만 제거)
|
||||
$this->assertStringContainsString('.a{color:red}', $bundle);
|
||||
}
|
||||
|
||||
public function test_dev_keeps_css_source_mapping_url(): void
|
||||
{
|
||||
// 기본 testing 환경 = 비프로덕션 → 개발 디버깅을 위해 원본 유지
|
||||
$css = $this->writeFixture('a.css', ".a{color:red}\n/*# sourceMappingURL=a.css.map */");
|
||||
|
||||
$this->moduleManager->shouldReceive('getActiveModules')->andReturn([
|
||||
'ext-a' => $this->fakeExtension('ext-a', 10, null, $css),
|
||||
]);
|
||||
|
||||
$bundle = $this->service()->buildCssBundle('module');
|
||||
|
||||
$this->assertStringContainsString('sourceMappingURL', $bundle);
|
||||
}
|
||||
|
||||
public function test_per_extension_fault_tolerance_skips_missing_file(): void
|
||||
{
|
||||
$good = $this->writeFixture('good.js', '(function(){window.GOOD=1})()');
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
# audit:allow test-scenario-coverage reason: 프로덕션 소스맵 노출 차단(하드닝). 입력 axis(빌드 모드·확장 종류·에셋 종류) cross-product 는 test_files 의 Unit/Feature 가 cover 하고, effects 는 3중 방어선(생성 차단 / 서빙 차단 / 저장소 유입 차단)과 브라우저 실측(맵 요청 부재·렌더 정상)을 enumerate.
|
||||
|
||||
feature: 프로덕션 소스맵 노출 차단 (코어 + 전 확장)
|
||||
|
||||
description: |
|
||||
소스맵(.map)은 sourcesContent 에 원본 TS/TSX 전문(주석 포함)을 담는다. 기존에는
|
||||
모든 vite config 가 sourcemap: true 를 하드코딩하고 `--production` 플래그가 실효가
|
||||
없어, 배포 산출물에 맵이 그대로 실리고 익명 요청으로 서빙됐다.
|
||||
|
||||
3중 방어선으로 차단한다:
|
||||
- 생성 차단: `--production` → Build{Core,Module,Plugin,Template}Command 가
|
||||
G7_BUILD_SOURCEMAP=0 을 npm 프로세스 env 로 주입 → 각 vite config 의 인라인
|
||||
판정식이 sourcemap:false → 맵 파일도, sourceMappingURL 주석도 생성되지 않음
|
||||
- 서빙 차단: 모듈/플러그인 허용 확장자에서 map 제거 (템플릿은 원래 미허용)
|
||||
→ 3종 정책 일치. 디스크에 맵이 실재해도 서빙 거부
|
||||
- 유입 차단: .gitignore 전역 `*.map` + 기존 추적 맵 13개 제거
|
||||
→ 공개 release 배포판에 맵이 실리지 않음
|
||||
|
||||
개발 경험은 보존한다: 환경변수 미설정(로컬 `npm run build`, --watch)이면 기본값
|
||||
true 로 맵이 생성된다.
|
||||
|
||||
axes:
|
||||
build_mode: [production, non_production, watch]
|
||||
extension_type: [core, module, plugin, template]
|
||||
asset_kind: [js, css]
|
||||
sourcemap_env: [unset, zero, false_literal]
|
||||
map_file_on_disk: [present, absent]
|
||||
serving_target: [module_asset, plugin_asset, template_asset, core_webroot]
|
||||
bundle_environment: [production, non_production]
|
||||
|
||||
exclusions:
|
||||
- { build_mode: watch, sourcemap_env: zero, reason: "감시 모드에는 억제를 주입하지 않는다 — 개발 중 디버깅 필요" }
|
||||
- { extension_type: core, serving_target: module_asset, reason: "코어 번들은 웹루트 직접 서빙 — 확장 에셋 라우트를 타지 않음" }
|
||||
|
||||
effects:
|
||||
# 생성 차단 (빌드)
|
||||
- production_build_injects_sourcemap_off_env
|
||||
- non_production_build_injects_nothing
|
||||
- watch_mode_does_not_inject_sourcemap_off
|
||||
- run_npm_command_accepts_env_and_merges_with_parent_environment
|
||||
- vite_config_defaults_to_sourcemap_on_when_env_unset
|
||||
# 서빙 차단
|
||||
- module_sourcemap_asset_request_rejected_even_when_file_exists
|
||||
- plugin_sourcemap_asset_request_rejected_even_when_file_exists
|
||||
- sourcemap_content_never_present_in_rejection_response
|
||||
- allowed_file_types_aligned_across_module_plugin_template
|
||||
# 번들 서비스
|
||||
- prod_strips_js_source_mapping_url
|
||||
- prod_strips_css_source_mapping_url
|
||||
- dev_keeps_css_source_mapping_url
|
||||
- css_style_body_preserved_when_stripping_comment
|
||||
# 저장소 유입 차단
|
||||
- no_sourcemap_files_tracked_by_git
|
||||
- gitignore_actually_ignores_sourcemap_files
|
||||
- tracked_build_output_has_no_source_mapping_url
|
||||
# 브라우저 실측
|
||||
- no_sourcemap_requests_from_loaded_bundles
|
||||
- page_renders_without_map_related_console_errors
|
||||
|
||||
test_files:
|
||||
- tests/Unit/Extension/BuildCommandSourcemapEnvTest.php
|
||||
- tests/Unit/Extension/NoSourcemapArtifactsTest.php
|
||||
- tests/Unit/Services/ExtensionBundleServiceTest.php
|
||||
- tests/Feature/Module/ModuleAssetServingTest.php
|
||||
- tests/Feature/Plugin/PluginAssetServingTest.php
|
||||
- tests/Playwright/specs/production-sourcemap-exposure.spec.ts
|
||||
Reference in new issue
Block a user