From cd71d4263366ace3c6ebb4eebe8a10e2c834acaa Mon Sep 17 00:00:00 2001 From: liugaowei Date: Mon, 26 Oct 2026 13:59:58 +0800 Subject: [PATCH] =?UTF-8?q?fix(protocol):=20=E5=90=8C=E6=AD=A5=E5=85=AC?= =?UTF-8?q?=E5=BC=80=E6=8F=92=E4=BB=B6=E5=88=86=E4=BA=AB=E7=9A=84=E5=9B=BE?= =?UTF-8?q?=E6=A0=87=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liugaowei --- .../src/__tests__/publicPresentation.test.ts | 13 +++++++++++++ packages/plugin-protocol/src/publicPresentation.ts | 8 ++++++++ 2 files changed, 21 insertions(+) diff --git a/packages/plugin-protocol/src/__tests__/publicPresentation.test.ts b/packages/plugin-protocol/src/__tests__/publicPresentation.test.ts index 55f55f1527..5ebd3e7d13 100644 --- a/packages/plugin-protocol/src/__tests__/publicPresentation.test.ts +++ b/packages/plugin-protocol/src/__tests__/publicPresentation.test.ts @@ -26,6 +26,19 @@ describe("public plugin presentation boundary", () => { }), ).toEqual(publicView); }); + it("preserves an embedded current plugin icon without exposing its storage location", () => { + const icon = "data:image/png;base64,iVBORw0KGgo="; + expect(parsePublicPluginPresentation({ ...publicView, icon })).toEqual({ ...publicView, icon }); + expect(parsePublicPluginPresentation({ ...publicView, icon: null }).icon).toBeNull(); + }); + it.each([ + "https://example.test/icon.png", + "data:image/svg+xml;base64,PHN2Zz48L3N2Zz4=", + "data:image/png;base64,invalid!", + `data:image/png;base64,${"A".repeat(700_000)}`, + ])("uses the missing-icon state for an unsafe or oversized image", (icon) => { + expect(parsePublicPluginPresentation({ ...publicView, icon }).icon).toBeNull(); + }); it.each([ { schemaVersion: 2 }, { pluginId: "../../private" }, diff --git a/packages/plugin-protocol/src/publicPresentation.ts b/packages/plugin-protocol/src/publicPresentation.ts index 071f21811b..f0fa0d27b3 100644 --- a/packages/plugin-protocol/src/publicPresentation.ts +++ b/packages/plugin-protocol/src/publicPresentation.ts @@ -15,6 +15,8 @@ export interface PublicPluginPresentation { author: string | null; version: string; publishedAt: string; + /** Current verified raster icon, embedded without a storage URL; absent on older servers. */ + icon?: string | null; } export function parsePublicPluginPresentation( @@ -26,6 +28,11 @@ export function parsePublicPluginPresentation( } const nullableText = (value: unknown, path: string, max: number) => value === null || value === "" ? null : string(value, path, max); + const image = typeof row.icon === "string" && row.icon.length <= Math.ceil(512 * 1024 / 3) * 4 + 32 + ? /^data:image\/(png|jpeg|webp|gif);base64,([A-Za-z0-9+/]+={0,2})$/.exec(row.icon) : null; + const base64 = image?.[2] ?? ""; + const size = base64.length / 4 * 3 - (base64.endsWith("==") ? 2 : base64.endsWith("=") ? 1 : 0); + const icon = image && base64.length % 4 === 0 && size <= 512 * 1024 ? row.icon as string : null; return { schemaVersion: 1, pluginId: row.pluginId, @@ -34,5 +41,6 @@ export function parsePublicPluginPresentation( author: nullableText(row.author, "author", 256), version: string(row.version, "version", 128), publishedAt: isoDate(row.publishedAt, "publishedAt"), + ...(row.icon === undefined ? {} : { icon }), }; }