fix(core,board,ecommerce,payments,basic): KVE-2026 보안 게이트 6묶음 + 자격증명 전송로 정합
KISA 제보 취약점(KVE-2026-1914/1919/2019/2029/2041/2042/2043/2044)과 그 수정 과정에서 드러난 자격증명 전송로 결함을 함께 해소한다. globalHeaders 는 데이터소스와 apiCall 핸들러에만 적용되는데, 코어 ApiClient 를 직접 부르는 경로들이 그 사실을 모른 채 게이트된 엔드포인트를 호출하고 있었다. 서버는 정당한 사용자를 거부하고 화면은 이미 버튼을 내준 뒤라, 예외도 로그도 없이 그 자리만 비는 형태로만 드러났다. 전송로 10축을 전수 열거해 6건을 고치고, 같은 실수가 반복되지 않도록 규정과 coverage 에 등재했다. 아웃바운드 프록시가 사이트 자기 자신으로 가는 내부 요청까지 가로채 저장이 수십 초씩 걸리던 문제도 함께 고쳤다. 실패가 폴백으로 삼켜져 화면에는 지연으로만 나타났다.
This commit is contained in:
1 parent
8f072895ff
commit
9cf9c3ff8c
104 files changed
+4522
-412
No files matched your search
+4
@@ -10,6 +10,7 @@ import React, { useState, useEffect } from 'react';
|
||||
import { useSortable } from '@dnd-kit/sortable';
|
||||
import { CSS } from '@dnd-kit/utilities';
|
||||
|
||||
import { secretContentHeaders } from '../../../support/secretContentHeaders';
|
||||
import { Div } from '../../basic/Div';
|
||||
import { Button } from '../../basic/Button';
|
||||
import { Span } from '../../basic/Span';
|
||||
@@ -92,8 +93,11 @@ export const SortableThumbnailItem: React.FC<SortableThumbnailItemProps> = ({
|
||||
|
||||
const loadAuthenticatedImage = async () => {
|
||||
try {
|
||||
// 비밀글 첨부는 서버가 열람 권한을 재확인한다. globalHeaders 는 이 경로에
|
||||
// 적용되지 않으므로 열람 확인 토큰을 직접 싣는다 (없으면 빈 객체라 영향 없음).
|
||||
const blob = await G7Core.api.get(downloadUrl, {
|
||||
responseType: 'blob',
|
||||
headers: secretContentHeaders(),
|
||||
});
|
||||
if (isMounted && blob) {
|
||||
objectUrl = URL.createObjectURL(blob);
|
||||
|
||||
+4
@@ -16,6 +16,7 @@ import imageCompression from 'browser-image-compression';
|
||||
import type { Attachment, PendingFile, FileUploaderProps, ApiEndpoints } from './types';
|
||||
import { formatFileSize, extractErrorMessage, t } from './utils';
|
||||
import { isCrossOriginAssetUrl } from '../assetOrigin';
|
||||
import { secretContentHeaders } from '../../../support/secretContentHeaders';
|
||||
|
||||
/** 동봉한 browser-image-compression 버전 */
|
||||
const IMAGE_COMPRESSION_VERSION = '2.0.2';
|
||||
@@ -744,8 +745,11 @@ export function useFileUploader(options: UseFileUploaderOptions): UseFileUploade
|
||||
}
|
||||
|
||||
try {
|
||||
// 비밀글 첨부는 서버가 열람 권한을 재확인한다. globalHeaders 는 이 경로에
|
||||
// 적용되지 않으므로 열람 확인 토큰을 직접 싣는다 (없으면 빈 객체라 영향 없음).
|
||||
const blob = await G7Core.api.get(file.download_url, {
|
||||
responseType: 'blob',
|
||||
headers: secretContentHeaders(),
|
||||
});
|
||||
if (!cancelled && blob) {
|
||||
const objectUrl = URL.createObjectURL(blob);
|
||||
|
||||
@@ -18,6 +18,7 @@ import 'yet-another-react-lightbox/styles.css';
|
||||
import 'yet-another-react-lightbox/plugins/counter.css';
|
||||
import 'yet-another-react-lightbox/plugins/thumbnails.css';
|
||||
|
||||
import { secretContentHeaders } from '../../support/secretContentHeaders';
|
||||
import { Button } from '../basic/Button';
|
||||
import { I } from '../basic/I';
|
||||
import { isCrossOriginAssetUrl } from './assetOrigin';
|
||||
@@ -95,8 +96,11 @@ export interface ImageGalleryProps {
|
||||
*/
|
||||
const downloadAuthenticatedFile = async (url: string, filename: string): Promise<void> => {
|
||||
try {
|
||||
// 비밀글 첨부는 서버가 열람 권한을 재확인한다. globalHeaders 는 이 경로에 적용되지
|
||||
// 않으므로 열람 확인 토큰을 여기서 직접 싣는다 (없으면 빈 객체라 영향 없음).
|
||||
const blob = await G7Core.api.get(url, {
|
||||
responseType: 'blob',
|
||||
headers: secretContentHeaders(),
|
||||
});
|
||||
|
||||
if (blob) {
|
||||
|
||||
+89
@@ -0,0 +1,89 @@
|
||||
/**
|
||||
* ImageGallery 인증 다운로드의 비밀글 열람 토큰 동반 회귀 테스트
|
||||
*
|
||||
* 레이아웃의 globalHeaders 는 데이터소스와 apiCall 핸들러에만 적용되고, 코어
|
||||
* ApiClient(G7Core.api)를 직접 호출하는 이 경로는 그 배선을 타지 않는다. 그래서
|
||||
* 비밀번호로 비밀글을 연 사용자에게 화면은 다운로드 버튼을 내주는데(서버가
|
||||
* can_download=true 를 돌려준다) 실제 요청은 열람 사실을 증명하지 못해 403 이 된다.
|
||||
* 예외도 콘솔 오류도 남지 않고 다운로드만 조용히 실패한다.
|
||||
*
|
||||
* @scenario surface=image_gallery, transport=direct_api_client
|
||||
*
|
||||
* @effects gallery_download_carries_secret_view_token
|
||||
*/
|
||||
|
||||
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
||||
|
||||
/**
|
||||
* ImageGallery 는 모듈 최상단에서 `const G7Core = window.G7Core` 로 참조를 캡처한다.
|
||||
* 그래서 전역을 세운 뒤 동적 import 해야 그 캡처가 테스트 mock 을 가리킨다 —
|
||||
* 정적 import 는 캡처가 undefined 로 굳어 요청 자체가 일어나지 않는다.
|
||||
*/
|
||||
async function loadDownload() {
|
||||
vi.resetModules();
|
||||
const mod = await import('../ImageGallery');
|
||||
|
||||
return mod.executeImageDownload;
|
||||
}
|
||||
|
||||
describe('executeImageDownload — 비밀글 열람 확인 토큰 동반', () => {
|
||||
let apiGetSpy: ReturnType<typeof vi.fn>;
|
||||
|
||||
beforeEach(() => {
|
||||
apiGetSpy = vi.fn().mockResolvedValue(new Blob(['x']));
|
||||
(window as any).G7Core = {
|
||||
t: (key: string) => key,
|
||||
api: { get: apiGetSpy },
|
||||
toast: { error: vi.fn() },
|
||||
};
|
||||
(URL as any).createObjectURL = vi.fn().mockReturnValue('blob:mock');
|
||||
(URL as any).revokeObjectURL = vi.fn();
|
||||
vi.spyOn(HTMLAnchorElement.prototype, 'click').mockImplementation(vi.fn());
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
delete (window as any).G7Core;
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
it('토큰이 있으면 인증 다운로드 요청 헤더에 실어 보낸다', async () => {
|
||||
(window as any).G7Core.state = {
|
||||
get: (key: string) => (key === '_global' ? { secretViewToken: 'tok-gallery-view' } : undefined),
|
||||
};
|
||||
|
||||
const executeImageDownload = await loadDownload();
|
||||
|
||||
await executeImageDownload({
|
||||
src: '/api/modules/sirsoft-board/boards/free/attachment/aaaaaaaaaaaa/preview',
|
||||
downloadUrl: '/api/modules/sirsoft-board/boards/free/attachment/aaaaaaaaaaaa',
|
||||
filename: 'a.jpg',
|
||||
downloadRequiresAuth: true,
|
||||
} as any);
|
||||
|
||||
expect(apiGetSpy).toHaveBeenCalledWith(
|
||||
'/api/modules/sirsoft-board/boards/free/attachment/aaaaaaaaaaaa',
|
||||
{
|
||||
responseType: 'blob',
|
||||
headers: { 'X-Board-Secret-View-Token': 'tok-gallery-view' },
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
it('토큰이 없으면 헤더를 만들지 않는다 (빈 값 전송 금지)', async () => {
|
||||
(window as any).G7Core.state = { get: () => ({}) };
|
||||
|
||||
const executeImageDownload = await loadDownload();
|
||||
|
||||
await executeImageDownload({
|
||||
src: '/x',
|
||||
downloadUrl: '/api/modules/sirsoft-board/boards/free/attachment/bbbbbbbbbbbb',
|
||||
filename: 'b.jpg',
|
||||
downloadRequiresAuth: true,
|
||||
} as any);
|
||||
|
||||
expect(apiGetSpy).toHaveBeenCalledWith(
|
||||
'/api/modules/sirsoft-board/boards/free/attachment/bbbbbbbbbbbb',
|
||||
{ responseType: 'blob', headers: {} },
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -12,7 +12,7 @@
|
||||
* 실제 호출 인자를 단언한다(거짓 통과 방지).
|
||||
*
|
||||
* @scenario card=user_post
|
||||
* @effects download_via_api_client_with_token,filename_preserved,download_failure_shows_error_toast
|
||||
* @effects download_via_api_client_with_token,filename_preserved,download_failure_shows_error_toast,download_carries_secret_view_token
|
||||
*/
|
||||
|
||||
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
||||
@@ -58,10 +58,36 @@ describe('downloadAttachmentHandler — 토큰 동반 첨부 다운로드 (이
|
||||
expect(apiGetSpy).toHaveBeenCalledTimes(1);
|
||||
expect(apiGetSpy).toHaveBeenCalledWith(
|
||||
'/api/modules/sirsoft-board/boards/notice/attachment/abc123',
|
||||
{ responseType: 'blob' },
|
||||
{ responseType: 'blob', headers: {} },
|
||||
);
|
||||
});
|
||||
|
||||
it('비밀글 열람 확인 토큰이 있으면 요청 헤더에 실어 보낸다', async () => {
|
||||
(window as any).G7Core.state = {
|
||||
get: (key: string) => (key === '_global' ? { secretViewToken: 'tok-secret-view-40' } : undefined),
|
||||
};
|
||||
|
||||
await downloadAttachmentHandler({
|
||||
params: { url: '/api/modules/sirsoft-board/boards/notice/attachment/abc123', filename: 'a.pdf' },
|
||||
});
|
||||
|
||||
expect(apiGetSpy).toHaveBeenCalledWith(
|
||||
'/api/modules/sirsoft-board/boards/notice/attachment/abc123',
|
||||
{
|
||||
responseType: 'blob',
|
||||
headers: { 'X-Board-Secret-View-Token': 'tok-secret-view-40' },
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
it('토큰이 없으면 헤더를 만들지 않는다 (빈 값 전송 금지)', async () => {
|
||||
(window as any).G7Core.state = { get: () => ({}) };
|
||||
|
||||
await downloadAttachmentHandler({ params: { url: '/d/x', filename: 'a.pdf' } });
|
||||
|
||||
expect(apiGetSpy).toHaveBeenCalledWith('/d/x', { responseType: 'blob', headers: {} });
|
||||
});
|
||||
|
||||
it('받은 blob 을 objectURL 로 변환해 filename 으로 다운로드하고 revoke 한다', async () => {
|
||||
await downloadAttachmentHandler({
|
||||
params: { url: '/d/x', filename: '보고서.pdf' },
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
* 비회원: 토큰이 없으므로 종전과 동일하게 user_id 가 NULL 로 남는다(현행 정책 유지).
|
||||
*/
|
||||
|
||||
import { secretContentHeaders } from '../support/secretContentHeaders';
|
||||
|
||||
// Logger 설정 (G7Core 초기화 전에도 동작하도록 폴백 포함)
|
||||
const logger = (window as any).G7Core?.createLogger?.('Handler:DownloadAttachment') ?? {
|
||||
log: (...args: unknown[]) => console.log('[Handler:DownloadAttachment]', ...args),
|
||||
@@ -49,7 +51,12 @@ export async function downloadAttachmentHandler(action?: any, _context?: any): P
|
||||
|
||||
try {
|
||||
// 코어 ApiClient 경로 → Authorization(Bearer) 헤더 자동 첨부 → 회원 토큰이 실린다.
|
||||
const blob = await G7Core.api.get(url, { responseType: 'blob' });
|
||||
// 비밀글 첨부는 서버가 열람 권한을 재확인한다. globalHeaders 는 이 경로에 적용되지
|
||||
// 않으므로 열람 확인 토큰을 여기서 직접 싣는다 (없으면 빈 객체라 영향 없음).
|
||||
const blob = await G7Core.api.get(url, {
|
||||
responseType: 'blob',
|
||||
headers: secretContentHeaders(),
|
||||
});
|
||||
|
||||
if (blob) {
|
||||
const objectUrl = URL.createObjectURL(blob);
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
/**
|
||||
* 비밀글 열람 확인 토큰 헤더 헬퍼 + 직접 호출 경로 배선 검증
|
||||
*
|
||||
* globalHeaders 는 데이터소스와 apiCall 핸들러에만 적용된다. 코어 ApiClient
|
||||
* (G7Core.api)를 직접 호출하는 경로는 그 배선을 타지 않아, 비밀번호로 원문을 연
|
||||
* 사용자에게 화면이 버튼·썸네일을 내주고도 서버가 403 으로 거부한다. 예외도 콘솔
|
||||
* 오류도 남지 않고 그 자리만 조용히 비는 결함이라 구조로 잠근다.
|
||||
*
|
||||
* @scenario surface=direct_api_client
|
||||
*
|
||||
* @effects secret_view_token_header_helper,direct_api_call_sites_carry_secret_header
|
||||
*/
|
||||
|
||||
import { describe, it, expect, afterEach } from 'vitest';
|
||||
import { readFileSync } from 'node:fs';
|
||||
import { resolve } from 'node:path';
|
||||
|
||||
import { secretContentHeaders, SECRET_VIEW_TOKEN_HEADER } from '../secretContentHeaders';
|
||||
|
||||
const SRC = resolve(__dirname, '../..');
|
||||
|
||||
afterEach(() => {
|
||||
delete (window as any).G7Core;
|
||||
});
|
||||
|
||||
describe('secretContentHeaders', () => {
|
||||
it('전역 상태에 토큰이 있으면 헤더 객체를 만든다', () => {
|
||||
(window as any).G7Core = {
|
||||
state: { get: (k: string) => (k === '_global' ? { secretViewToken: 'tok-40' } : undefined) },
|
||||
};
|
||||
|
||||
expect(secretContentHeaders()).toEqual({ [SECRET_VIEW_TOKEN_HEADER]: 'tok-40' });
|
||||
});
|
||||
|
||||
it('토큰이 없거나 빈 문자열이면 빈 객체를 돌려준다 (빈 헤더 전송 금지)', () => {
|
||||
(window as any).G7Core = { state: { get: () => ({ secretViewToken: '' }) } };
|
||||
expect(secretContentHeaders()).toEqual({});
|
||||
|
||||
(window as any).G7Core = { state: { get: () => ({}) } };
|
||||
expect(secretContentHeaders()).toEqual({});
|
||||
});
|
||||
|
||||
it('G7Core 가 아직 없어도 예외를 던지지 않는다', () => {
|
||||
expect(secretContentHeaders()).toEqual({});
|
||||
});
|
||||
});
|
||||
|
||||
describe('직접 호출 경로 배선', () => {
|
||||
const CALL_SITES = [
|
||||
'handlers/downloadAttachment.ts',
|
||||
'components/composite/ImageGallery.tsx',
|
||||
'components/composite/FileUploader/SortableThumbnailItem.tsx',
|
||||
'components/composite/FileUploader/useFileUploader.ts',
|
||||
];
|
||||
|
||||
it.each(CALL_SITES)('%s 가 blob 요청에 열람 토큰 헤더를 싣는다', (relative) => {
|
||||
const source = readFileSync(resolve(SRC, relative), 'utf-8');
|
||||
|
||||
expect(
|
||||
source.includes('secretContentHeaders'),
|
||||
`${relative} 가 열람 토큰 헤더를 싣지 않습니다 — 비밀글 첨부에서 서버가 403 으로 거부하는데 화면에는 오류가 남지 않습니다.`
|
||||
).toBe(true);
|
||||
|
||||
const blobCalls = source.split("responseType: 'blob'");
|
||||
expect(
|
||||
blobCalls.length - 1,
|
||||
`${relative} 에 blob 요청이 없습니다 — 테스트가 실제 경로를 보고 있는지 확인이 필요합니다.`
|
||||
).toBeGreaterThan(0);
|
||||
|
||||
blobCalls.slice(1).forEach((chunk, index) => {
|
||||
expect(
|
||||
chunk.slice(0, 200).includes('secretContentHeaders()'),
|
||||
`${relative} 의 ${index + 1}번째 blob 요청에 열람 토큰 헤더가 빠졌습니다.`
|
||||
).toBe(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,35 @@
|
||||
/**
|
||||
* 비밀글 열람 확인 토큰 요청 헤더 (sirsoft-basic 공용)
|
||||
*
|
||||
* 레이아웃의 globalHeaders 배선은 데이터소스(DataSourceManager)와 apiCall 핸들러
|
||||
* (ActionDispatcher)에만 적용된다. 코어 ApiClient(G7Core.api)를 직접 호출하는 경로는
|
||||
* 그 배선을 타지 않아 Authorization·Accept-Language 만 실린다.
|
||||
*
|
||||
* 그래서 비밀번호로 원문을 연 사용자가 첨부파일을 받으려 하면, 화면은 다운로드 버튼을
|
||||
* 내주는데(서버가 can_download=true 를 돌려준다) 실제 요청은 열람 사실을 증명하지 못해
|
||||
* 403 으로 거부된다. 예외도 콘솔 오류도 남지 않고 다운로드만 조용히 실패한다.
|
||||
*
|
||||
* 직접 호출 경로가 늘어날 때 같은 결함이 재발하지 않도록, 그런 호출부는 이 한 곳을 통해
|
||||
* 헤더를 만든다.
|
||||
*/
|
||||
|
||||
/**
|
||||
* 서버(SecretContentGate)가 읽는 열람 확인 토큰 헤더 이름.
|
||||
*/
|
||||
export const SECRET_VIEW_TOKEN_HEADER = 'X-Board-Secret-View-Token';
|
||||
|
||||
/**
|
||||
* 현재 전역 상태에 열람 확인 토큰이 있으면 요청 헤더 객체로 만들어 돌려줍니다.
|
||||
*
|
||||
* 토큰은 비밀번호 검증 응답으로만 발급되고 게시글 단위로 결속되므로, 무관한 요청에
|
||||
* 실려도 서버 판정에 영향을 주지 않습니다.
|
||||
*
|
||||
* @return 토큰이 있으면 헤더 1개짜리 객체, 없으면 빈 객체
|
||||
*/
|
||||
export function secretContentHeaders(): Record<string, string> {
|
||||
const token = (window as any).G7Core?.state?.get?.('_global')?.secretViewToken;
|
||||
|
||||
return typeof token === 'string' && token !== ''
|
||||
? { [SECRET_VIEW_TOKEN_HEADER]: token }
|
||||
: {};
|
||||
}
|
||||
Reference in new issue
Block a user