-
Notifications
You must be signed in to change notification settings - Fork 1
fix(core): reject ZIP entries not listed in MANIFEST (closes #1) #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -129,6 +129,21 @@ async function sha256Hex(data: Uint8Array): Promise<string> { | |
| .join(""); | ||
| } | ||
|
|
||
| function findUnexpectedFiles( | ||
| manifest: PackageManifest, | ||
| files: Map<string, Uint8Array>, | ||
| ): FileIntegrityResult[] { | ||
| const allowed = new Set(Object.keys(manifest.files)); | ||
| const extras: FileIntegrityResult[] = []; | ||
| for (const path of files.keys()) { | ||
| if (path === "MANIFEST.json") continue; | ||
| if (!allowed.has(path)) { | ||
| extras.push({ path, valid: false, code: VerifyErrorCode.UNEXPECTED_FILE }); | ||
| } | ||
| } | ||
| return extras; | ||
| } | ||
|
|
||
| async function verifyManifestHashes( | ||
| manifest: PackageManifest, | ||
| files: Map<string, Uint8Array>, | ||
|
|
@@ -235,16 +250,15 @@ export async function verifyPackage( | |
| }; | ||
| } | ||
|
|
||
| const fileResults = await verifyManifestHashes(manifest, files); | ||
| const extras = findUnexpectedFiles(manifest, files); | ||
| const fileResults = [...(await verifyManifestHashes(manifest, files)), ...extras]; | ||
| const hasFailedFile = fileResults.some((f) => !f.valid); | ||
| if (hasFailedFile) { | ||
| const firstFailed = fileResults.find((f) => !f.valid)!; | ||
| return { | ||
| valid: false, | ||
| code: firstFailed.code, | ||
| reason: firstFailed.code === VerifyErrorCode.MISSING_FILE | ||
| ? `Missing file: ${firstFailed.path}` | ||
| : `Hash mismatch for file: ${firstFailed.path}`, | ||
| reason: failedFileReason(firstFailed), | ||
| details: { ...docMeta(manifest), signers, files: fileResults }, | ||
| }; | ||
| } | ||
|
|
@@ -255,6 +269,14 @@ export async function verifyPackage( | |
| }; | ||
| } | ||
|
|
||
| function failedFileReason(f: FileIntegrityResult): string { | ||
| switch (f.code) { | ||
| case VerifyErrorCode.MISSING_FILE: return `Missing file: ${f.path}`; | ||
| case VerifyErrorCode.UNEXPECTED_FILE: return `Unexpected file not in manifest: ${f.path}`; | ||
| default: return `Hash mismatch for file: ${f.path}`; | ||
| } | ||
| } | ||
|
|
||
| // -- DNS TXT ------------------------------------------------------------------ | ||
|
|
||
| export function parseDnsTxtRecord(txt: string): DnsTxtKeyRecord | null { | ||
|
|
@@ -709,16 +731,15 @@ async function verifyZipFromAuthor( | |
| files.set(path, data); | ||
| } | ||
|
|
||
| const fileResults = await verifyManifestHashes(manifest, files); | ||
| const extras = findUnexpectedFiles(manifest, files); | ||
| const fileResults = [...(await verifyManifestHashes(manifest, files)), ...extras]; | ||
| const hasFailedFile = fileResults.some((f) => !f.valid); | ||
|
Comment on lines
732
to
736
|
||
| if (hasFailedFile) { | ||
| const firstFailed = fileResults.find((f) => !f.valid)!; | ||
| return { | ||
| valid: false, | ||
| code: firstFailed.code, | ||
| reason: firstFailed.code === VerifyErrorCode.MISSING_FILE | ||
| ? `Missing file: ${firstFailed.path}` | ||
| : `Hash mismatch for file: ${firstFailed.path}`, | ||
| reason: failedFileReason(firstFailed), | ||
| details: { ...docMeta(manifest), signers, files: fileResults }, | ||
| }; | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.