fix(browser-files): 위험 확장자를 safe extension으로 쓰는 다운로드 정책을 거절한다

문제: 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
This commit is contained in:
DongHyeonka
2026-11-04 21:18:51 +09:00
parent 3f72ae7df9
commit 4f78890576
4 changed files with 45 additions and 1 deletions
@@ -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는 다음처럼 분리한다.
@@ -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 ||
+11
View File
@@ -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;
@@ -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",