fix(core): 레이아웃 첨부 URL 을 사이트 상대 경로로 발급하고 저장 게이트가 자기 주소를 외부로 보지 않게 수정
편집기 헤더 「로고 이미지」에 파일을 올린 뒤 저장하면 「HTTPS 프로토콜 URL은 허용되지 않습니다」 422 로 거부되던 결함. 프록시 서빙 URL 이 절대 형태로 발급되어 NoExternalUrls 가 서버 자신의 주소를 외부로 차단했고, 배경 이미지는 style 로 들어가 스캔 밖이어서 로고(propValue)에서만 드러났다. - proxyUrl 을 사이트 상대 경로로 발급 (발급 시점 도메인·스킴에 묶이지 않는다) - SiteAssetHosts 신설: app.url host + 운영자가 선언한 공개 자산 디스크 host 를 브라우저와 같은 정규화 뒤 등가 비교. 요청 Host 헤더는 근거로 쓰지 않고, 흉내 host·protocol-relative·위험 스킴은 종전대로 차단 - 회귀 테스트 4클래스(71 passed) + 시나리오 매니페스트 + Playwright 2케이스, 공개 문서(SECURITY·security·storage-driver·api)와 규정 표 갱신 함께 담긴 릴리즈 정비: - 7.0.11 미출시 섹션의 릴리즈 날짜를 09-09 로 갱신 (코어·board·page·admin_basic·basic·ja 언어팩 3종) - 배포본에 실리는 주석·독블록·시나리오의 내부 호칭을 중립 표현으로 정리하고, 동봉 vendor 자산의 우연한 토큰은 누출 검사에서 경로 규칙으로만 제외 - 버전 bump 검사: github_url 없는 번들을 언어팩과 같은 origin/release 페이로드 기준선으로 판정(상시 경고 제거), 코어 버전 판독이 env 래핑을 읽도록 보정
This commit is contained in:
1 parent
a8a98f6ed0
commit
72f46a6468
33 files changed
+811
-28
No files matched your search
@@ -7,11 +7,13 @@ use App\Extension\HookManager;
|
||||
use App\Models\Permission;
|
||||
use App\Models\Role;
|
||||
use App\Models\Template;
|
||||
use App\Models\TemplateLayout;
|
||||
use App\Models\TemplateLayoutAttachment;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Testing\TestResponse;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
@@ -422,4 +424,109 @@ class TemplateLayoutAttachmentControllerTest extends TestCase
|
||||
$this->assertStringContainsString("/layout-attachments/{$legacy->id}/file", $url);
|
||||
$this->assertStringNotContainsString('cdn.test', $url);
|
||||
}
|
||||
// ─────────────────────────────────────────────────────────────────────────
|
||||
// 업로드 응답 url → 레이아웃 저장 게이트 왕복
|
||||
//
|
||||
// 헤더 「로고 이미지」처럼 값 슬롯이 하나뿐인 컨트롤은 업로드 응답 url 을 props 에 그대로
|
||||
// 넣는다. 그 값이 저장 요청의 NoExternalUrls 를 통과하지 못하면 운영자는 "업로드는
|
||||
// 됐는데 저장은 422" 를 본다. 배경 이미지는 style 로 들어가 스캔되지 않아 드러나지 않았다.
|
||||
// ─────────────────────────────────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
* 업로드 응답 url 을 props 에 넣은 레이아웃을 PUT 합니다.
|
||||
*
|
||||
* @param string $url 업로드 응답 url
|
||||
* @return TestResponse
|
||||
*/
|
||||
private function saveLayoutWithLogo(string $url)
|
||||
{
|
||||
$layout = TemplateLayout::factory()->create([
|
||||
'template_id' => $this->template->id,
|
||||
'name' => 'home',
|
||||
]);
|
||||
|
||||
$content = $layout->content;
|
||||
// 팩토리 기본 endpoint(`/api/{단어}`)는 WhitelistedEndpoint 에 걸린다 — 이 테스트의 축이 아니다.
|
||||
$content['endpoint'] = '/api/public/home';
|
||||
$content['components'] = [[
|
||||
'id' => 'header',
|
||||
'type' => 'composite',
|
||||
'name' => 'Header',
|
||||
'props' => ['logo' => $url],
|
||||
]];
|
||||
|
||||
return $this->withHeaders($this->authHeaders())
|
||||
->putJson("/api/admin/templates/{$this->template->identifier}/layouts/home", [
|
||||
'expected_lock_version' => (int) ($layout->lock_version ?? 0),
|
||||
'content' => $content,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 프록시 변종 — 업로드 응답 url 이 저장 요청을 통과해야 합니다.
|
||||
*
|
||||
* @scenario url_host=site_relative_path
|
||||
*
|
||||
* @effects proxy_url_is_site_relative, issued_asset_url_passes_storage_gate
|
||||
*/
|
||||
public function test_uploaded_proxy_url_is_accepted_by_layout_save(): void
|
||||
{
|
||||
$upload = $this->withHeaders($this->authHeaders())
|
||||
->postJson("/api/admin/templates/{$this->template->identifier}/layout-attachments", [
|
||||
'file' => UploadedFile::fake()->image('logo.png', 48, 24),
|
||||
'layout_name' => 'home',
|
||||
]);
|
||||
$upload->assertStatus(200);
|
||||
$url = (string) $upload->json('data.url');
|
||||
|
||||
$this->assertStringStartsWith('/api/', $url, '프록시 URL 은 사이트 상대 경로여야 합니다');
|
||||
|
||||
$save = $this->saveLayoutWithLogo($url);
|
||||
|
||||
$save->assertStatus(200);
|
||||
$this->assertSame($url, TemplateLayout::where('name', 'home')->first()->content['components'][0]['props']['logo']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 직접 URL(CDN) 변종 — 운영자가 선언한 공개 자산 디스크의 절대 URL 도 저장 요청을 통과해야 합니다.
|
||||
*
|
||||
* @scenario url_host=public_asset_disk
|
||||
*
|
||||
* @effects issued_asset_url_passes_storage_gate
|
||||
*/
|
||||
public function test_uploaded_direct_url_is_accepted_by_layout_save(): void
|
||||
{
|
||||
$this->registerFakeCdnDisk();
|
||||
config(['core.storage.public_asset_disk' => 'fake_cdn']);
|
||||
|
||||
$upload = $this->withHeaders($this->authHeaders())
|
||||
->postJson("/api/admin/templates/{$this->template->identifier}/layout-attachments", [
|
||||
'file' => UploadedFile::fake()->image('logo.png', 48, 24),
|
||||
'layout_name' => 'home',
|
||||
]);
|
||||
$upload->assertStatus(200);
|
||||
$url = (string) $upload->json('data.url');
|
||||
|
||||
$this->assertStringStartsWith('https://cdn.test/assets', $url);
|
||||
|
||||
$save = $this->saveLayoutWithLogo($url);
|
||||
|
||||
$save->assertStatus(200);
|
||||
$this->assertSame($url, TemplateLayout::where('name', 'home')->first()->content['components'][0]['props']['logo']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 선언되지 않은 외부 host 는 여전히 차단되어야 합니다 — 허용 범위가 "서버가 발급하는 주소" 를
|
||||
* 넘어 넓어지지 않았는지 고정한다.
|
||||
*
|
||||
* @scenario url_host=external_undeclared
|
||||
*
|
||||
* @effects external_host_still_rejected
|
||||
*/
|
||||
public function test_external_host_url_is_still_rejected_by_layout_save(): void
|
||||
{
|
||||
$save = $this->saveLayoutWithLogo('https://attacker.example/template-layout-attachments/x.png');
|
||||
|
||||
$save->assertStatus(422);
|
||||
}
|
||||
}
|
||||
@@ -229,7 +229,7 @@ class DevtoolsDebugGateTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* GET 4종은 디버그 ON 에서 정상 응답한다 (게이트만 걸고 기능은 유지 — PO 결정).
|
||||
* GET 4종은 디버그 ON 에서 정상 응답한다 (게이트만 걸고 기능은 유지 — 설계 결정).
|
||||
*/
|
||||
public function test_get_endpoints_respond_when_debug_enabled(): void
|
||||
{
|
||||
|
||||
@@ -1043,7 +1043,7 @@ class ExtensionDocContractTest extends TestCase
|
||||
/**
|
||||
* 확장 README 의 첫 화면이 이미지 배지가 아니라 H1 제목인지 단언합니다.
|
||||
*
|
||||
* PO 결정(2026-08-31): 확장 README 상단의 확장명은 shields.io 이미지 배지가 아니라 평범한
|
||||
* 설계 결정(2026-08-31): 확장 README 상단의 확장명은 shields.io 이미지 배지가 아니라 평범한
|
||||
* H1 마크다운 제목이다. 확장은 20개가 병렬로 존재하는 대등한 구성요소이고, 각자가 코어와
|
||||
* 같은 히어로 브랜딩을 받으면 "이 확장이 곧 독립 프로젝트" 라는 착시를 준다.
|
||||
*
|
||||
@@ -1146,7 +1146,7 @@ class ExtensionDocContractTest extends TestCase
|
||||
/**
|
||||
* 진입 문서 3종의 제목이 「그누보드7 {확장명} {유형}」 을 담는지 단언합니다.
|
||||
*
|
||||
* PO 결정(2026-09-04): 확장 README 제목이 확장명뿐(`# 게시판`)이면 그 문서만 연 사람이
|
||||
* 설계 결정(2026-09-04): 확장 README 제목이 확장명뿐(`# 게시판`)이면 그 문서만 연 사람이
|
||||
* 이것이 그누보드7의 확장인지, 모듈인지 템플릿인지 알 수 없다. README · AGENTS.md ·
|
||||
* docs/README.md 는 제3자가 처음 여는 진입 문서이므로 셋 다 같은 제목을 쓴다.
|
||||
*
|
||||
|
||||
@@ -115,7 +115,7 @@ class DevVendorDetectionTest extends TestCase
|
||||
/**
|
||||
* 재사용 분기가 dev 를 감지해 경고하되 설치를 계속한다 (소스 계약).
|
||||
*
|
||||
* 감지·경고·"설치 계속" 셋이 한 분기 안에 있어야 한다 — 차단으로 바뀌면 PO 결정(D1) 위반이다.
|
||||
* 감지·경고·"설치 계속" 셋이 한 분기 안에 있어야 한다 — 차단으로 바뀌면 설계 결정(D1) 위반이다.
|
||||
*
|
||||
* @effects installer_warns_and_keeps_dev_vendor
|
||||
*/
|
||||
|
||||
@@ -7,6 +7,7 @@ use App\Http\Requests\Layout\UpdateLayoutContentRequest;
|
||||
use App\Http\Requests\Layout\UpdateLayoutExtensionContentRequest;
|
||||
use App\Http\Requests\Layout\UpdateLayoutRequest;
|
||||
use App\Rules\NoExternalUrls;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Tests\TestCase;
|
||||
|
||||
class NoExternalUrlsTest extends TestCase
|
||||
@@ -495,6 +496,160 @@ class NoExternalUrlsTest extends TestCase
|
||||
// 트리에 이 규칙이 붙어 있지 않으면, init_actions·props·actions 의 외부 URL 차단이
|
||||
// 그 경로에서만 조용히 발화하지 않는다.
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────
|
||||
// 사이트 자산 host — 서버가 스스로 발급한 주소는 외부가 아니다
|
||||
//
|
||||
// 레이아웃 첨부 API 가 돌려준 URL(프록시 경로 또는 운영자가 선언한 공개 자산
|
||||
// 디스크의 직접 URL)을 image 위젯이 props 에 넣는데, 그 값을 이 규칙이 "외부" 로
|
||||
// 차단하면 업로드 → 저장이 422 로 끝난다. 배경 이미지는 style 로 들어가 스캔되지
|
||||
// 않아 같은 URL 이 통과했으므로, 증상은 로고(propValue) 에서만 나타났다.
|
||||
// ─────────────────────────────────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
* props.logo 하나를 가진 최소 레이아웃을 만듭니다.
|
||||
*
|
||||
* @param string $url logo 값
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
private function layoutWithLogo(string $url): array
|
||||
{
|
||||
return [
|
||||
'version' => '1.0.0',
|
||||
'layout_name' => 'test',
|
||||
'components' => [
|
||||
[
|
||||
'id' => 'header',
|
||||
'type' => 'composite',
|
||||
'name' => 'Header',
|
||||
'props' => ['logo' => $url],
|
||||
'children' => [],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 규칙 통과 여부를 돌려줍니다.
|
||||
*
|
||||
* @param array<string, mixed> $layout 검사 대상
|
||||
* @return string|null 실패 메시지 (통과면 null)
|
||||
*/
|
||||
private function failureOf(array $layout): ?string
|
||||
{
|
||||
$message = null;
|
||||
$this->rule->validate('content', $layout, function ($m) use (&$message) {
|
||||
$message = (string) $m;
|
||||
});
|
||||
|
||||
return $message;
|
||||
}
|
||||
|
||||
/**
|
||||
* 사이트 자기 host(app.url)의 절대 URL 은 통과해야 합니다 — 프록시 서빙 라우트가 절대
|
||||
* 형태로 발급되던 배포본(7.0.10 이하)에서 저장된 값과, 운영자가 자기 사이트 주소를
|
||||
* 직접 적은 값이 여기에 해당한다.
|
||||
*
|
||||
* @scenario url_host=own_site_absolute
|
||||
*
|
||||
* @effects issued_asset_url_passes_storage_gate
|
||||
*/
|
||||
public function test_passes_with_own_site_absolute_url_in_props(): void
|
||||
{
|
||||
Config::set('app.url', 'https://shop.example.test');
|
||||
|
||||
foreach ([
|
||||
'https://shop.example.test/api/templates/sirsoft-basic/layout-attachments/4/file',
|
||||
'http://shop.example.test/storage/template-layout-attachments/sirsoft-basic/logo.png',
|
||||
'https://SHOP.example.TEST/api/templates/sirsoft-basic/layout-attachments/4/file',
|
||||
] as $url) {
|
||||
$this->assertNull($this->failureOf($this->layoutWithLogo($url)), "자기 host 절대 URL 은 통과해야 합니다: {$url}");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 운영자가 선언한 공개 자산 디스크의 host 는 통과해야 합니다 — 직접 URL(CDN) 변종에서
|
||||
* 첨부 API 가 돌려주는 값이다.
|
||||
*
|
||||
* @scenario url_host=public_asset_disk
|
||||
*
|
||||
* @effects issued_asset_url_passes_storage_gate
|
||||
*/
|
||||
public function test_passes_with_public_asset_disk_host_in_props(): void
|
||||
{
|
||||
Config::set('app.url', 'https://shop.example.test');
|
||||
Config::set('core.storage.public_asset_disk', 'public');
|
||||
Config::set('filesystems.disks.public.url', 'https://cdn.example.test/assets');
|
||||
|
||||
$url = 'https://cdn.example.test/assets/template-layout-attachments/sirsoft-basic/bg.png';
|
||||
|
||||
$this->assertNull($this->failureOf($this->layoutWithLogo($url)), '공개 자산 디스크 host 는 통과해야 합니다');
|
||||
}
|
||||
|
||||
/**
|
||||
* 같은 host 라도 공개 자산 디스크로 선언되지 않았으면 여전히 외부입니다 — 허용의 근거는
|
||||
* "URL 을 만들 수 있는 디스크가 있다" 가 아니라 운영자 선언이다.
|
||||
*
|
||||
* @scenario url_host=external_undeclared
|
||||
*
|
||||
* @effects external_host_still_rejected
|
||||
*/
|
||||
public function test_fails_with_cdn_host_when_public_asset_disk_is_not_declared(): void
|
||||
{
|
||||
Config::set('app.url', 'https://shop.example.test');
|
||||
Config::set('core.storage.public_asset_disk', '');
|
||||
Config::set('filesystems.disks.public.url', 'https://cdn.example.test/assets');
|
||||
|
||||
$url = 'https://cdn.example.test/assets/template-layout-attachments/sirsoft-basic/bg.png';
|
||||
|
||||
$this->assertNotNull($this->failureOf($this->layoutWithLogo($url)), '선언되지 않은 디스크 host 는 차단되어야 합니다');
|
||||
}
|
||||
|
||||
/**
|
||||
* 자기 host 를 흉내 낸 URL 은 전부 차단되어야 합니다 — 접두 문자열 비교로 허용하면
|
||||
* 이 형태들이 통과한다. 판정은 브라우저와 같은 정규화 뒤의 host 등가 비교여야 한다.
|
||||
*
|
||||
* @scenario url_host=lookalike
|
||||
*
|
||||
* @effects external_host_still_rejected
|
||||
*/
|
||||
public function test_fails_with_lookalike_of_own_host(): void
|
||||
{
|
||||
Config::set('app.url', 'https://shop.example.test');
|
||||
Config::set('core.storage.public_asset_disk', '');
|
||||
|
||||
foreach ([
|
||||
'https://shop.example.test.evil.com/x.png',
|
||||
'https://shop.example.test@evil.com/x.png',
|
||||
'https://evil.com\\@shop.example.test/x.png',
|
||||
'https://evil.com/shop.example.test/x.png',
|
||||
'https://evil.com/?u=https://shop.example.test/x.png',
|
||||
'https://shop.example.test%2eevil.com/x.png',
|
||||
// protocol-relative 는 자기 host 라도 종전대로 차단한다 (별도 판정 축)
|
||||
'//shop.example.test/x.png',
|
||||
] as $url) {
|
||||
$this->assertNotNull($this->failureOf($this->layoutWithLogo($url)), "자기 host 흉내는 차단되어야 합니다: {$url}");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 자기 host 허용은 http/https 에만 적용됩니다 — 위험 스킴은 host 가 같아도 차단한다.
|
||||
*
|
||||
* @scenario url_host=dangerous_scheme
|
||||
*
|
||||
* @effects external_host_still_rejected
|
||||
*/
|
||||
public function test_fails_with_dangerous_scheme_even_on_own_host(): void
|
||||
{
|
||||
Config::set('app.url', 'https://shop.example.test');
|
||||
|
||||
foreach ([
|
||||
'ftp://shop.example.test/x.png',
|
||||
'file://shop.example.test/x.png',
|
||||
] as $url) {
|
||||
$this->assertNotNull($this->failureOf($this->layoutWithLogo($url)), "위험 스킴은 host 와 무관하게 차단되어야 합니다: {$url}");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* FormRequest 의 content 배열 규칙에서 NoExternalUrls 인스턴스를 찾는다.
|
||||
*
|
||||
|
||||
@@ -13,6 +13,10 @@
|
||||
*
|
||||
* 축 요약(마커 아님 — 평문): public_asset_disk=unset, row_disk=attachments,
|
||||
* filter_url_hook=absent.
|
||||
*
|
||||
* 뒤의 두 테스트는 별도 매니페스트(layout-attachment-url-storage-gate.yaml)의 축이다 —
|
||||
* 발급 url 이 사이트 상대 경로여야 헤더 「로고 이미지」 같은 propValue 컨트롤의 저장이
|
||||
* 외부 URL 차단 규칙에 걸리지 않는다. 절대 URL 이던 시절 그 저장은 422 였다.
|
||||
*/
|
||||
import { test, expect, issueToken, authenticatePage } from '../../fixtures/auth';
|
||||
import { bodyRootPath } from '../../fixtures/layout-editor';
|
||||
@@ -72,6 +76,16 @@ async function openStyleTab(page: Page): Promise<void> {
|
||||
await page.getByTestId('g7le-property-tab-style').click();
|
||||
}
|
||||
|
||||
/** ⓘ → 속성 편집 → props 탭 (헤더 「로고 이미지」 컨트롤이 있는 탭). */
|
||||
async function openPropsTab(page: Page): Promise<void> {
|
||||
await page.waitForSelector('[data-testid="g7le-overlay-info-button"]', { timeout: 10_000 });
|
||||
await page.getByTestId('g7le-overlay-info-button').click();
|
||||
await page.waitForSelector('[data-testid="g7le-context-menu-edit-props"]', { timeout: 5_000 });
|
||||
await page.getByTestId('g7le-context-menu-edit-props').click();
|
||||
await page.waitForSelector('[data-testid="g7le-property-modal"]', { timeout: 10_000 });
|
||||
await page.getByTestId('g7le-property-tab-props').click();
|
||||
}
|
||||
|
||||
async function enterEditor(page: Page): Promise<void> {
|
||||
await page.goto('/admin/layout-editor/sirsoft-basic?route=%2F');
|
||||
await page.waitForLoadState('domcontentloaded', { timeout: 30_000 });
|
||||
@@ -143,6 +157,8 @@ test.describe('@layout-editor 레이아웃 첨부 URL 발급 모드', () => {
|
||||
|
||||
// 공개 자산 디스크 미설정 = 기본 설치 → 공개 서빙 라우트(프록시) 형태
|
||||
expect(uploaded.url as string).toContain(`/layout-attachments/${uploaded.id}/file`);
|
||||
// 사이트 상대 경로 — 절대 URL 이면 저장 게이트(NoExternalUrls)가 서버 자신의 주소를 외부로 차단한다
|
||||
expect(uploaded.url as string).toMatch(/^\/api\//);
|
||||
|
||||
// 그 주소는 인증 없이 이미지로 열려야 한다 (발행 배경은 방문자에게 로드된다)
|
||||
const served = await page.evaluate(async (url: string) => {
|
||||
@@ -264,9 +280,11 @@ test.describe('@layout-editor 레이아웃 첨부 URL 발급 모드', () => {
|
||||
|
||||
// 방문자 화면 — 저장된 문자열이 실제 요청으로 나가는지 본다.
|
||||
const visitor = await page.context().newPage();
|
||||
// 발급 url 은 사이트 상대 경로다 — 응답 URL(절대)과는 pathname 으로 비교한다.
|
||||
const uploadedPath = new URL(uploaded.url as string, 'https://placeholder.invalid').pathname;
|
||||
const attachmentRequests: number[] = [];
|
||||
visitor.on('response', (res) => {
|
||||
if (res.url() === uploaded.url) attachmentRequests.push(res.status());
|
||||
if (new URL(res.url()).pathname === uploadedPath) attachmentRequests.push(res.status());
|
||||
});
|
||||
await visitor.goto(SANDBOX_ROUTE['sirsoft-basic']);
|
||||
await visitor.waitForLoadState('domcontentloaded', { timeout: 30_000 });
|
||||
@@ -279,4 +297,140 @@ test.describe('@layout-editor 레이아웃 첨부 URL 발급 모드', () => {
|
||||
// 시드 화면은 다음 실행에서 fixture 로 덮이므로 첨부만 정리한다.
|
||||
await deleteAttachment(page, token, uploaded.id);
|
||||
});
|
||||
/**
|
||||
* 헤더 「로고 이미지」는 값 슬롯이 하나뿐인 propValue 컨트롤이라 업로드 응답 url 이 그대로
|
||||
* props 에 들어간다. 그 값이 사이트 상대 경로여야 저장 게이트를 통과한다 — 절대 URL 이던
|
||||
* 시절 이 흐름은 "업로드는 되는데 저장은 422" 였다.
|
||||
*
|
||||
* 공통 레이아웃(_user_base)은 제품 화면이므로 여기서는 저장하지 않는다 — 위젯 값과 캔버스
|
||||
* src 까지만 본다. 저장 왕복은 다음 테스트가 샌드박스 화면에서 잠근다.
|
||||
*/
|
||||
// @scenario url_host=site_relative_path
|
||||
// @effects editor_logo_control_receives_site_relative_url, proxy_url_is_site_relative
|
||||
test('헤더 로고 컨트롤에서 파일 업로드 → 위젯 값·캔버스 src 가 사이트 상대 경로다', async ({ page }) => {
|
||||
test.setTimeout(90_000);
|
||||
const token = issueToken('core.templates.layouts.edit');
|
||||
await authenticatePage(page, token);
|
||||
|
||||
await page.goto('/admin/layout-editor/sirsoft-basic?route=%2F&edit=__base__%2F_user_base');
|
||||
await page.waitForLoadState('domcontentloaded', { timeout: 30_000 });
|
||||
await page.waitForSelector('[data-testid="g7le-preview-frame"]', { timeout: 30_000 });
|
||||
await page.waitForFunction(() => document.querySelectorAll('[data-editor-path]').length > 0, {
|
||||
timeout: 20_000,
|
||||
});
|
||||
|
||||
const headerPath = await page.evaluate(
|
||||
() =>
|
||||
document
|
||||
.querySelector('[data-editor-path][data-editor-name="Header"]')
|
||||
?.getAttribute('data-editor-path') ?? null,
|
||||
);
|
||||
expect(headerPath, '공통 레이아웃에 Header 노드가 있어야 합니다').not.toBeNull();
|
||||
await selectNode(page, headerPath as string);
|
||||
await openPropsTab(page);
|
||||
|
||||
// 로고 값이 환경설정과 연결된 표현식이면 「직접 지정으로 바꾸기」로 열어야 업로드가 가능하다.
|
||||
const replace = page.getByTestId('g7le-image-expression-replace');
|
||||
if (await replace.isVisible().catch(() => false)) {
|
||||
await replace.click();
|
||||
}
|
||||
|
||||
const uploadPromise = page.waitForResponse(
|
||||
(r) =>
|
||||
r.request().method() === 'POST' && /\/layout-attachments$/.test(new URL(r.url()).pathname),
|
||||
{ timeout: 20_000 },
|
||||
);
|
||||
await page
|
||||
.locator('[data-testid="g7le-property-modal"] input[type="file"]')
|
||||
.setInputFiles({ name: 'e2e-logo.png', mimeType: 'image/png', buffer: Buffer.from(PNG_BASE64, 'base64') });
|
||||
const uploadRes = await uploadPromise;
|
||||
expect(uploadRes.status()).toBe(200);
|
||||
const body = (await uploadRes.json()) as { data?: { id?: number; url?: string } };
|
||||
const url = body?.data?.url ?? null;
|
||||
const id = body?.data?.id ?? null;
|
||||
expect(url).not.toBeNull();
|
||||
expect(url as string).toMatch(/^\/api\//);
|
||||
|
||||
// 위젯 값 = 발급 url (가공 없음), 캔버스 Header <img src> 도 같은 값
|
||||
await expect(page.getByTestId('g7le-image-url')).toHaveValue(url as string);
|
||||
await expect
|
||||
.poll(
|
||||
() =>
|
||||
page.evaluate(
|
||||
(p) => document.querySelector(`[data-editor-path="${p}"] img`)?.getAttribute('src') ?? null,
|
||||
headerPath,
|
||||
),
|
||||
{ timeout: 8_000 },
|
||||
)
|
||||
.toBe(url);
|
||||
|
||||
await deleteAttachment(page, token, id);
|
||||
});
|
||||
|
||||
/**
|
||||
* 발급 url 을 이미지 prop(`Img.src` — 로고와 같은 props sink)에 넣고 저장하면 200 이어야 하고,
|
||||
* 그 화면을 연 방문자가 같은 주소를 200 으로 받아야 한다. 절대 URL 이던 시절 이 PUT 은
|
||||
* 「HTTPS 프로토콜 URL은 허용되지 않습니다」 422 였다.
|
||||
*
|
||||
* 저장은 E2E 전용 시드 화면(e2e_sandbox)에 한다 — globalSetup 이 매 실행 fixture 로 덮는다.
|
||||
*/
|
||||
// @scenario url_host=site_relative_path
|
||||
// @effects issued_asset_url_passes_storage_gate, saved_logo_renders_for_visitor
|
||||
test('발급 url 을 이미지 prop 에 넣고 저장 → 200, 방문자 화면이 그 주소를 200 으로 받는다', async ({ page }) => {
|
||||
test.setTimeout(90_000);
|
||||
const token = issueToken('core.templates.layouts.edit');
|
||||
await authenticatePage(page, token);
|
||||
await page.goto('/');
|
||||
await page.waitForLoadState('domcontentloaded', { timeout: 30_000 });
|
||||
|
||||
const uploaded = await uploadAttachment(page, token, 'e2e-prop-gate.png');
|
||||
expect(uploaded.status).toBe(200);
|
||||
expect(uploaded.url as string).toMatch(/^\/api\//);
|
||||
|
||||
const saved = await page.evaluate(
|
||||
async ({ bearer, url }) => {
|
||||
const headers = { Authorization: `Bearer ${bearer}`, Accept: 'application/json' };
|
||||
const show = await fetch('/api/admin/templates/sirsoft-basic/layouts/e2e_sandbox', { headers });
|
||||
const showBody = await show.json().catch(() => null);
|
||||
const data = showBody?.data ?? {};
|
||||
// show 응답의 content 는 편집 페이지용 JSON 문자열이다 (LayoutResource).
|
||||
const content = typeof data.content === 'string' ? JSON.parse(data.content) : data.content;
|
||||
if (!content?.slots?.content?.[0]) return { status: -1, reason: 'sandbox content shape' };
|
||||
const root = content.slots.content[0];
|
||||
root.children = Array.isArray(root.children) ? root.children : [];
|
||||
root.children.push({
|
||||
id: 'e2e_prop_gate_img',
|
||||
type: 'basic',
|
||||
name: 'Img',
|
||||
props: { src: url, alt: 'e2e prop gate', className: 'h-6' },
|
||||
});
|
||||
const put = await fetch('/api/admin/templates/sirsoft-basic/layouts/e2e_sandbox', {
|
||||
method: 'PUT',
|
||||
headers: { ...headers, 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ expected_lock_version: data.lock_version ?? 0, content }),
|
||||
credentials: 'same-origin',
|
||||
});
|
||||
const putBody = await put.json().catch(() => null);
|
||||
return { status: put.status, message: putBody?.message ?? null };
|
||||
},
|
||||
{ bearer: token, url: uploaded.url as string },
|
||||
);
|
||||
expect(saved, saved.message ?? '').toMatchObject({ status: 200 });
|
||||
|
||||
// 방문자 — 저장된 문자열이 실제 요청으로 나가고 200 으로 응답하는지
|
||||
const visitor = await page.context().newPage();
|
||||
const uploadedPath = new URL(uploaded.url as string, 'https://placeholder.invalid').pathname;
|
||||
const statuses: number[] = [];
|
||||
visitor.on('response', (res) => {
|
||||
if (new URL(res.url()).pathname === uploadedPath) statuses.push(res.status());
|
||||
});
|
||||
await visitor.goto(SANDBOX_ROUTE['sirsoft-basic']);
|
||||
await visitor.waitForLoadState('domcontentloaded', { timeout: 30_000 });
|
||||
await expect.poll(() => statuses.length, { timeout: 15_000 }).toBeGreaterThan(0);
|
||||
expect(statuses.every((s) => s === 200)).toBe(true);
|
||||
await expect(visitor.locator(`img[src="${uploaded.url}"]`)).toHaveCount(1);
|
||||
await visitor.close();
|
||||
|
||||
await deleteAttachment(page, token, uploaded.id);
|
||||
});
|
||||
});
|
||||
@@ -10,7 +10,7 @@ use PHPUnit\Framework\TestCase;
|
||||
/**
|
||||
* 설치 2단계(설치 환경 확인)의 Composer 의존성 구성 카드 회귀 테스트 (dev-g7 #658).
|
||||
*
|
||||
* 이 항목은 **선택 항목**이다 — 개발용 패키지가 섞여 있어도 설치는 진행되어야 한다(PO 결정 D1).
|
||||
* 이 항목은 **선택 항목**이다 — 개발용 패키지가 섞여 있어도 설치는 진행되어야 한다(설계 결정 D1).
|
||||
* 게이트로 승격되면 이미 dev vendor 로 준비해 둔 운영자가 설치를 시작조차 못 한다.
|
||||
*
|
||||
* `check-configuration.php` 는 `CHECK_CONFIGURATION_LIBRARY` 모드로 로드해 요청 처리를 막고,
|
||||
|
||||
@@ -255,4 +255,24 @@ class TemplateLayoutAttachmentUrlResolutionTest extends TestCase
|
||||
|
||||
$this->assertProxyUrl($this->service->resolveUrl($this->makeAttachment('s3')));
|
||||
}
|
||||
|
||||
/**
|
||||
* 프록시 URL 은 사이트 상대 경로여야 합니다.
|
||||
*
|
||||
* 절대 URL 로 발급하면 두 가지가 어긋난다 — ① 저장 게이트(NoExternalUrls)가 서버가
|
||||
* 스스로 발급한 주소를 외부로 차단해 업로드 → 저장이 422 로 끝나고, ② 저장된 레이아웃이
|
||||
* 발급 시점의 도메인·스킴에 묶여 주소가 바뀌면 그 이미지가 전부 깨진다.
|
||||
*
|
||||
* @scenario url_host=site_relative_path
|
||||
*
|
||||
* @effects proxy_url_is_site_relative, issued_asset_url_passes_storage_gate
|
||||
*/
|
||||
public function test_proxy_url_is_site_relative_path(): void
|
||||
{
|
||||
$url = $this->service->resolveUrl($this->makeAttachment('attachments'));
|
||||
|
||||
$this->assertStringStartsWith('/api/', $url);
|
||||
$this->assertDoesNotMatchRegularExpression('#^[a-z][a-z0-9+.\-]*:#i', $url, '프록시 URL 에 스킴이 있으면 안 됩니다');
|
||||
$this->assertStringNotContainsString('//', $url);
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@ use PHPUnit\Framework\TestCase;
|
||||
/**
|
||||
* 진입 문서 제목 조립 규칙(`ExtensionInventory::docTitle`)을 고정합니다.
|
||||
*
|
||||
* 제목은 「그누보드7 {확장명} {유형}」 이다 (PO 결정 2026-09-04). 확장명이 이미 유형으로
|
||||
* 제목은 「그누보드7 {확장명} {유형}」 이다 (설계 결정 2026-09-04). 확장명이 이미 유형으로
|
||||
* 끝나면 겹쳐 붙이지 않는다 — 이 예외가 깨지면 「그누보드7 Hello 모듈 모듈」 이 되는데,
|
||||
* 계약 테스트는 같은 헬퍼로 기대값을 만들므로 그 형태도 초록으로 통과한다. 그래서 규칙
|
||||
* 자체는 여기서 리터럴로 고정한다.
|
||||
|
||||
@@ -0,0 +1,133 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Support;
|
||||
|
||||
use App\Support\SiteAssetHosts;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* 사이트 자산 host 판정 단위 테스트
|
||||
*
|
||||
* 저장 게이트(NoExternalUrls)가 "서버가 스스로 발급하는 자산 주소" 를 외부로 오판하지
|
||||
* 않도록, 사이트 자기 host(app.url)와 운영자가 선언한 공개 자산 디스크의 host 를 한
|
||||
* 지점에서 해석한다. 요청 Host 헤더는 근거로 쓰지 않는다 — 위조 가능하다.
|
||||
*/
|
||||
class SiteAssetHostsTest extends TestCase
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
Config::set('app.url', 'https://shop.example.test');
|
||||
Config::set('core.storage.public_asset_disk', '');
|
||||
}
|
||||
|
||||
/**
|
||||
* app.url 의 host 는 항상 포함되어야 합니다 (소문자 정규화).
|
||||
*
|
||||
* @scenario url_host=own_site_absolute
|
||||
*
|
||||
* @effects issued_asset_url_passes_storage_gate
|
||||
*/
|
||||
public function test_hosts_include_app_url_host(): void
|
||||
{
|
||||
Config::set('app.url', 'https://Shop.Example.TEST:8443/sub');
|
||||
|
||||
$this->assertContains('shop.example.test', SiteAssetHosts::hosts());
|
||||
}
|
||||
|
||||
/**
|
||||
* 공개 자산 디스크가 선언되어 있으면 그 디스크의 기준 URL host 가 포함되어야 합니다.
|
||||
*
|
||||
* @scenario url_host=public_asset_disk
|
||||
*
|
||||
* @effects issued_asset_url_passes_storage_gate
|
||||
*/
|
||||
public function test_hosts_include_declared_public_asset_disk_host(): void
|
||||
{
|
||||
Config::set('core.storage.public_asset_disk', 'public');
|
||||
Config::set('filesystems.disks.public.url', 'https://cdn.example.test/assets');
|
||||
|
||||
$this->assertContains('cdn.example.test', SiteAssetHosts::hosts());
|
||||
}
|
||||
|
||||
/**
|
||||
* 미선언·'none'·고아 디스크는 host 를 보태지 않아야 합니다 — 판정은 PublicAssetDisk::resolve()
|
||||
* 를 경유하므로 디스크에 url 이 설정돼 있어도 선언 없이는 외부다.
|
||||
*
|
||||
* @scenario url_host=external_undeclared
|
||||
*
|
||||
* @effects external_host_still_rejected
|
||||
*/
|
||||
public function test_undeclared_disk_host_is_not_included(): void
|
||||
{
|
||||
Config::set('filesystems.disks.public.url', 'https://cdn.example.test/assets');
|
||||
|
||||
foreach (['', 'none', 'vanished_plugin_disk'] as $declared) {
|
||||
Config::set('core.storage.public_asset_disk', $declared);
|
||||
|
||||
$this->assertNotContains('cdn.example.test', SiteAssetHosts::hosts(), "선언값 '{$declared}' 에서 host 가 새면 안 됩니다");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* http/https 절대 URL 이고 host 가 목록에 있을 때만 참이어야 합니다.
|
||||
*
|
||||
* @scenario url_host=own_site_absolute
|
||||
*
|
||||
* @effects issued_asset_url_passes_storage_gate
|
||||
*/
|
||||
public function test_is_site_asset_url_accepts_only_http_urls_on_listed_hosts(): void
|
||||
{
|
||||
$this->assertTrue(SiteAssetHosts::isSiteAssetUrl('https://shop.example.test/api/x'));
|
||||
$this->assertTrue(SiteAssetHosts::isSiteAssetUrl('http://shop.example.test/storage/x.png'));
|
||||
$this->assertTrue(SiteAssetHosts::isSiteAssetUrl(" https://shop.example.test/x\n"));
|
||||
|
||||
// 경로만 있는 값은 host 가 없으므로 이 판정의 대상이 아니다 (호출측이 경로 규칙으로 다룬다)
|
||||
$this->assertFalse(SiteAssetHosts::isSiteAssetUrl('/api/x'));
|
||||
// protocol-relative 는 별도 판정 축 — 자기 host 라도 여기서는 참이 아니다
|
||||
$this->assertFalse(SiteAssetHosts::isSiteAssetUrl('//shop.example.test/x'));
|
||||
// 위험 스킴은 host 와 무관
|
||||
$this->assertFalse(SiteAssetHosts::isSiteAssetUrl('ftp://shop.example.test/x'));
|
||||
$this->assertFalse(SiteAssetHosts::isSiteAssetUrl('javascript://shop.example.test/%0aalert(1)'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 자기 host 를 흉내 낸 URL 은 거짓이어야 합니다 — 브라우저와 같은 정규화 뒤 host 를 비교한다.
|
||||
*
|
||||
* @scenario url_host=lookalike
|
||||
*
|
||||
* @effects external_host_still_rejected
|
||||
*/
|
||||
public function test_is_site_asset_url_rejects_lookalikes(): void
|
||||
{
|
||||
foreach ([
|
||||
'https://shop.example.test.evil.com/x',
|
||||
'https://shop.example.test@evil.com/x',
|
||||
'https://evil.com\\@shop.example.test/x',
|
||||
'https://evil.com/shop.example.test/x',
|
||||
'https://evil.com#shop.example.test',
|
||||
"https://evil.com\t.shop.example.test/x",
|
||||
] as $url) {
|
||||
$this->assertFalse(SiteAssetHosts::isSiteAssetUrl($url), "흉내 URL 은 거짓이어야 합니다: {$url}");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* app.url 이 비어 있거나 host 를 못 읽는 값이면 빈 목록이어야 합니다 (예외 없음).
|
||||
*
|
||||
* @scenario url_host=external_undeclared
|
||||
*
|
||||
* @effects external_host_still_rejected
|
||||
*/
|
||||
public function test_blank_app_url_yields_no_host(): void
|
||||
{
|
||||
foreach (['', 'not a url', '/relative'] as $value) {
|
||||
Config::set('app.url', $value);
|
||||
|
||||
$this->assertSame([], SiteAssetHosts::hosts(), "app.url='{$value}' 에서 host 가 생기면 안 됩니다");
|
||||
$this->assertFalse(SiteAssetHosts::isSiteAssetUrl('https://shop.example.test/x'));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,7 @@ description: |
|
||||
재개 설치에서는 인스톨러 어느 지점에서도 정리가 일어나지 않아, 이전 환경의 캐시가 그대로
|
||||
남았다.
|
||||
|
||||
처치 (PO 결정 D1 — 설치를 차단하지 않는다):
|
||||
처치 (설계 결정 D1 — 설치를 차단하지 않는다):
|
||||
1. 설치 환경 확인(Step 2) 에 「Composer 의존성 구성」 카드를 **선택 항목**으로 추가.
|
||||
경고 상태여도 `isAllRequiredPassed()` 는 이를 보지 않고 `다음` 버튼도 활성이다.
|
||||
2. 설치 로그(Step 5) 에 감지 사실과 정리 명령 안내를 남긴다.
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
feature: 레이아웃 첨부 URL 저장 게이트 통과 (서버가 발급한 주소는 외부가 아니다)
|
||||
|
||||
description: |
|
||||
레이아웃 편집기의 image 위젯으로 파일을 올리면 첨부 API 가 돌려준 url 이 props 에 들어간다.
|
||||
그 url 이 절대 형태(`https://<사이트>/api/templates/.../file`)라 저장 요청의 외부 URL
|
||||
차단 규칙(NoExternalUrls)이 서버 자신이 발급한 주소를 외부로 차단해, 헤더 「로고 이미지」
|
||||
처럼 값 슬롯이 하나뿐인 컨트롤(propValue)에서 업로드는 되고 저장은 422 로 끝났다. 배경
|
||||
이미지는 style 로 들어가 스캔되지 않아 같은 주소가 통과했으므로 증상이 로고에서만 났다.
|
||||
|
||||
결정 사슬:
|
||||
- 생산자: 프록시(공개 서빙 라우트) URL 은 사이트 상대 경로(`/api/...`)로 발급한다. 절대 URL 은
|
||||
저장 게이트 충돌뿐 아니라 저장된 레이아웃을 발급 시점 도메인·스킴에 묶는다.
|
||||
- 게이트: 사이트 자기 host(app.url)와 운영자가 선언한 공개 자산 디스크(PublicAssetDisk::
|
||||
resolve())의 host 는 외부가 아니다 (SiteAssetHosts 단일 판정). 요청 Host 헤더는 위조
|
||||
가능하므로 근거로 쓰지 않는다.
|
||||
- 판정은 접두 문자열 비교가 아니라 브라우저와 같은 정규화 뒤 host 등가 비교 — 흉내 host
|
||||
(`host.evil.com`·`host@evil.com`·`evil.com\@host`)를 통과시키지 않는다.
|
||||
- protocol-relative(`//host/...`)와 http/https 밖의 스킴은 host 가 같아도 종전대로 차단한다.
|
||||
|
||||
coverage_strategy: full
|
||||
|
||||
axes:
|
||||
url_host: [site_relative_path, own_site_absolute, public_asset_disk, external_undeclared, lookalike, dangerous_scheme]
|
||||
|
||||
effects:
|
||||
- proxy_url_is_site_relative
|
||||
- issued_asset_url_passes_storage_gate
|
||||
- external_host_still_rejected
|
||||
# 편집기 로고 컨트롤(propValue)이 파일 업로드 후 받는 값이 사이트 상대 경로다 (E2E)
|
||||
- editor_logo_control_receives_site_relative_url
|
||||
# 발급 url 을 prop 에 넣어 저장한 화면을 방문자가 열면 그 주소가 200 으로 응답한다 (E2E)
|
||||
- saved_logo_renders_for_visitor
|
||||
|
||||
test_files:
|
||||
- tests/Feature/Rules/NoExternalUrlsTest.php
|
||||
- tests/Unit/Support/SiteAssetHostsTest.php
|
||||
- tests/Unit/Services/TemplateLayoutAttachmentUrlResolutionTest.php
|
||||
- tests/Feature/Api/Admin/TemplateLayoutAttachmentControllerTest.php
|
||||
- tests/Playwright/specs/layout-editor/layout-attachment-url-mode.spec.ts
|
||||
|
||||
rules_layer_coverage:
|
||||
- rule: no-storage-disk-direct
|
||||
coverage: 공개 자산 디스크 host 해석은 CoreStorageDriver::url() 경유 — Storage facade 직접 호출 도입 없음
|
||||
Reference in new issue
Block a user