From 4f78890576b8d5a9004372f2b8c31cd883d9990b Mon Sep 17 00:00:00 2001 From: DongHyeonka Date: Wed, 4 Nov 2026 21:18:51 +0900 Subject: [PATCH] =?UTF-8?q?fix(browser-files):=20=EC=9C=84=ED=97=98=20?= =?UTF-8?q?=ED=99=95=EC=9E=A5=EC=9E=90=EB=A5=BC=20safe=20extension?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=20=EC=93=B0=EB=8A=94=20=EB=8B=A4=EC=9A=B4?= =?UTF-8?q?=EB=A1=9C=EB=93=9C=20=EC=A0=95=EC=B1=85=EC=9D=84=20=EA=B1=B0?= =?UTF-8?q?=EC=A0=88=ED=95=9C=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 문제: download 정책 registry는 safeExtension의 형식만 본다. 파일명 금지 목록(.exe, .html, .js 등)은 사용자가 준 이름에만 쓴다 (1101/02-02). 그래서 mediaType application/pdf + safeExtension .exe 정책이 조립되고, invoice.pdf가 invoice.exe로 browser handoff된다 (리뷰 E-7). 고른 방법: snapshotDownload가 금지 목록에 있거나 그것으로 끝나는 (.tar.js) safeExtension을 다른 정책 오류와 같이 TypeError로 거절한다. 목록은 file-policy.ts의 DEFAULT_FORBIDDEN_EXTENSIONS 하나를 쓰고, isForbiddenDownloadExtension으로 내보낸다. browser-managed capability는 정책과 같은 safeExtension이어야 하므로 그 경로도 함께 막힌다. 버린 대안: media type과 확장자 짝 표를 두는 것. 표를 누가 소유할지 정해야 하고 범위가 크다. 이번에는 하지 않았다. 위험·한계: 이 확장자를 쓰던 다운스트림 정책은 조립 때 실패한다(보안 강화 방향). media type과 확장자가 서로 맞는지는 여전히 보지 않는다 (설계 문서에 적었다). file-transfer 번들 56,068 → 56,100 / 57,800 gzip B. 검증: - RED: browser-file-policy-registry.test.ts 새 3건(.exe, .HTML, .tar.js)이 throw 없음으로 실패. - GREEN: browser-files 단위 5파일 + tests/recipes 98건 통과. check:types, 바꾼 파일 eslint, check:optional-recipes:source PASS, verify:documentation 통과. Refs: docs/reviews/2026-11-03-maturity-review/02-adapters-browser-files-cache.md 1101/02-02 --- .../browser-file-and-origin-storage.md | 5 +++- .../browser-file-policy-registry.ts | 2 ++ src/adapters/browser-files/file-policy.ts | 11 ++++++++ .../unit/browser-file-policy-registry.test.ts | 28 +++++++++++++++++++ 4 files changed, 45 insertions(+), 1 deletion(-) diff --git a/docs/architecture/browser-file-and-origin-storage.md b/docs/architecture/browser-file-and-origin-storage.md index 0144fdb5..d9762ec6 100644 --- a/docs/architecture/browser-file-and-origin-storage.md +++ b/docs/architecture/browser-file-and-origin-storage.md @@ -447,7 +447,10 @@ stream-to-file에서 integrity를 close 전에 확인해야 하면 writable을 `INTEGRITY_FAILED` 또는 partial-save failure를 반환한다. 전략, media type, safe extension, integrity mode와 최대 bytes는 composition -registry가 소유한다. caller는 composition이 등록한 정확한 +registry가 소유한다. registry는 사용자 파일명에서 지우는 위험 확장자 +(`.exe`, `.html`, `.js` 등)이거나 그것으로 끝나는 safe extension을 조립 때 +거절한다(2026-11-01 02-02). media type과 확장자가 서로 맞는지는 아직 보지 +않는다. caller는 composition이 등록한 정확한 `FilePolicyReference` 객체, 아래 source union의 최소 입력, filename과 limit reduction만 전달한다. `policyKey`/`intention`이 같은 새 객체나 raw 전략을 제출할 수 없다. source는 다음처럼 분리한다. diff --git a/src/adapters/browser-files/browser-file-policy-registry.ts b/src/adapters/browser-files/browser-file-policy-registry.ts index a4f639f0..4b253d41 100644 --- a/src/adapters/browser-files/browser-file-policy-registry.ts +++ b/src/adapters/browser-files/browser-file-policy-registry.ts @@ -15,6 +15,7 @@ import { assertFileInspectionPolicy, assertFileSelectionPolicy, EXACT_MEDIA_TYPE, + isForbiddenDownloadExtension, isPositiveSafeInteger, sanitizeSuggestedFileName, type RegisteredFileInspectionPolicy, @@ -452,6 +453,7 @@ function snapshotDownload( "BOUNDED_OBJECT_URL", ].includes(input.strategy) || !EXACT_MEDIA_TYPE.test(mediaType) || + isForbiddenDownloadExtension(safeExtension) || !isPositiveSafeInteger(input.maxTransferBytes) || !isPositiveSafeInteger(input.maxBufferedBytes) || input.maxTransferBytes > hardLimits.maxTransferBytes || diff --git a/src/adapters/browser-files/file-policy.ts b/src/adapters/browser-files/file-policy.ts index 988fc285..380df048 100644 --- a/src/adapters/browser-files/file-policy.ts +++ b/src/adapters/browser-files/file-policy.ts @@ -96,6 +96,17 @@ const DEFAULT_FORBIDDEN_EXTENSIONS = Object.freeze([ ".xll", ] as const); +/** + * 2026-11-01 02-02. A download policy's own extension may not be one a + * user-supplied file name is stripped of, nor end in one (`.tar.js`). + */ +export function isForbiddenDownloadExtension(extension: string): boolean { + const normalized = extension.normalize("NFC").toLowerCase(); + return DEFAULT_FORBIDDEN_EXTENSIONS.some((forbidden) => + normalized.endsWith(forbidden), + ); +} + export type SuggestedFileNamePolicy = Readonly<{ safeExtension: string; fallbackBaseName?: string; diff --git a/tests/unit/browser-file-policy-registry.test.ts b/tests/unit/browser-file-policy-registry.test.ts index 5249d388..60d8e651 100644 --- a/tests/unit/browser-file-policy-registry.test.ts +++ b/tests/unit/browser-file-policy-registry.test.ts @@ -174,6 +174,34 @@ describe("browser file composition policy registry", () => { }); }); + // 2026-11-01 02-02. The download extension was checked for shape only, so a + // policy could hand `invoice.pdf` to the browser as `invoice.exe`. The + // extensions a user-supplied file name is stripped of are refused here too. + it.each([".exe", ".HTML", ".tar.js"])( + "refuses a download policy whose safe extension is %s", + (safeExtension) => { + expect( + () => + new BrowserFilePolicyRegistry({ + profiles: [ + { + reference: browserFilePolicyReference("downloads", "invoice"), + download: { + strategy: "BOUNDED_OBJECT_URL", + mediaType: "application/pdf", + safeExtension, + maxTransferBytes: 100, + maxBufferedBytes: 50, + integrity: "OPTIONAL", + }, + }, + ], + hardLimits, + }), + ).toThrow(TypeError); + }, + ); + it("binds verification receipts to the exact profile, not a reused policyId", async () => { const profileA = browserFilePolicyReference( "images-a",