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",