feat(core): 리버스 프록시 신뢰 설정 지원 및 미설정 진단

TLS 가 앞단에서 종단되고 앱에는 HTTP 로 전달되는 구성에서 X-Forwarded-* 가 전부
무시되어 화면 백지·IP 왜곡·webhook 403 이 함께 발생했다. 코어에 신뢰 프록시 설정
지점이 아예 없던 것이 원인이다.

- config/trustedproxy.php 로 내장 TrustProxies 미들웨어에 값을 공급한다.
 bootstrap/app.php 는 건드리지 않는다 — withMiddleware 클로저는 .env 로드 전에
 평가되어 env 가 항상 null 이 되는 조용한 no-op 이다.
- 판정은 App\Support\TrustedProxyDiagnostic 단일 SSoT 에서 계산하고 대시보드
 알림·환경설정 고급 탭·설치 마법사·trusted-proxy:status 네 면이 소비한다.
 판정식은 "HTTPS 인식 실패" 가 아니라 "X-Forwarded-* 수신 중 AND 신뢰 프록시
 미설정" 이다 — HTTP 전용 사이트가 프록시 뒤에 있으면 화면은 정상인 채로
 나머지만 조용히 어긋나기 때문이다.
- 값 편집 UI 와 쓰기 엔드포인트는 두지 않는다(잠금 역설 + XFF 위조 경로).
- 혼합 콘텐츠 차단을 부트스트랩 폴백의 별도 사유로 가른다. 새로고침으로 낫지
 않으므로 버튼을 렌더하지 않고, 원인·조치는 콘솔로 운영자에게 보낸다.
- 대시보드 알림을 심각도로 배치한다 — warning 은 상단 배너, 그 외는 하단 카드.
 같은 알림이 두 곳에 뜨지 않으며, 여러 건은 간격을 두고 쌓인다.

공개 이슈: (@lyg-kaban 제보)
This commit is contained in:
HeuJung committed 2026-08-28 18:09:27 +09:00
1 parent 46ada4dddb
commit b6c5e1f323
55 files changed
+2861 -38

No files matched your search

@@ -114,6 +114,80 @@ async function assertNetworkFailure(page: Page, url: string): Promise<void> {
expect(attempts).toBe(3);
}
/**
* 혼합 콘텐츠 차단 케이스 본문 — 회선은 멀쩡한데 브라우저가 요청을 거부하는 실패다 (공개 #124).
*
* 문서 HTML 의 코어 스크립트 URL 만 `http://` 로 바꾸면 재현된다 — TLS 종단 프록시도
* 인증서도 필요 없다. 프록시 뒤에서 신뢰 프록시가 지정되지 않았을 때 서버가 만들어 내는
* 것이 바로 이 HTML 이기 때문이다.
*
* 판정은 `location.protocol === 'https:'` 를 보므로, 기대값은 실행 시점 base URL 의
* 스킴에서 파생한다 — http base 에서는 이 실패가 그냥 도달 불가이므로 `network` 가 정답이다.
* 분기 자체의 방출은 스킴과 무관하게 BootstrapFallbackDiagnosisTest 가 단언한다.
*
* @param page Playwright page
* @param url 진입 경로
* @return {Promise<void>}
*/
async function assertMixedContentBlocked(page: Page, url: string): Promise<void> {
const consoleErrors: string[] = [];
page.on('console', (m) => {
if (m.type() === 'error') consoleErrors.push(m.text());
});
// 문서 응답을 가로채 코어 번들 URL 만 절대 http:// 로 바꾼다.
// 서버는 이 URL 을 절대(`https://host/build/core/…`) 또는 상대(`/build/core/…`) 어느
// 형태로도 낼 수 있으므로 두 경우를 모두 정규화해 다룬다 — 한 형태만 가정하면 치환이
// 조용히 0건이 되어 테스트가 아무것도 재현하지 않은 채 실패한다.
let rewritten = 0;
await page.route('**/*', async (route) => {
if (route.request().resourceType() !== 'document') return route.fallback();
const response = await route.fetch();
const body = await response.text();
const origin = new URL(route.request().url()).origin;
const patched = body.replace(
/src="([^"]*\/build\/core\/template-engine\.min\.js[^"]*)"/g,
(whole, src: string) => {
const abs = new URL(src, origin);
if (abs.protocol !== 'https:') return whole;
abs.protocol = 'http:';
rewritten += 1;
return `src="${abs.toString()}"`;
}
);
return route.fulfill({ response, body: patched });
});
await page.goto(url);
await page.waitForLoadState('domcontentloaded', { timeout: 30_000 });
const isHttpsBase = new URL(page.url()).protocol === 'https:';
if (isHttpsBase) {
// 치환이 실제로 일어났는지 확인한다 — 0 건이면 아래 단언은 결함이 아니라
// 재현 실패를 보고하게 된다.
expect(rewritten, '코어 번들 URL 치환이 0 건입니다 — 재현되지 않았습니다').toBeGreaterThan(0);
}
const isHttps = isHttpsBase;
const fallback = await readFallback(page);
expect(fallback.reason).toBe(isHttps ? 'blocked' : 'network');
expect(fallback.title.length).toBeGreaterThan(0);
// 차단은 새로고침으로 낫지 않는다 — 버튼을 두면 그것 자체가 다시 거짓 안내가 된다.
expect(fallback.buttons).toBe(isHttps ? 0 : 1);
if (isHttps) {
// 화면에서 뺀 원인·조치는 콘솔에서 운영자에게 도달해야 한다.
const joined = consoleErrors.join(' | ');
expect(joined).toMatch(/Blocked as mixed content/);
expect(joined).toMatch(/TRUSTED_PROXIES/);
}
}
/**
* 정상 부팅 케이스 본문 — 폴백이 오발동하지 않아야 한다.
*
@@ -175,6 +249,22 @@ test.describe('부팅 실패 사유별 안내 분기 (공개 #121)', () => {
await assertNetworkFailure(page, '/admin');
});
/**
* @scenario entrypoint=user, failure_mode=mixed_content_blocked
* @effects mixed_content_blocked_renders_blocked_notice, blocked_notice_omits_reload_button
*/
test('@smoke [user] 코어 번들이 http 로 차단 → 사이트 설정 안내 + 새로고침 버튼 부재', async ({ page }) => {
await assertMixedContentBlocked(page, '/');
});
/**
* @scenario entrypoint=admin, failure_mode=mixed_content_blocked
* @effects mixed_content_blocked_renders_blocked_notice, blocked_notice_omits_reload_button
*/
test('@smoke [admin] 코어 번들이 http 로 차단 → 사이트 설정 안내 + 새로고침 버튼 부재', async ({ page }) => {
await assertMixedContentBlocked(page, '/admin');
});
/**
* @scenario entrypoint=user, failure_mode=none
* @effects normal_boot_renders_no_fallback