fix(web): keep desktop annotation screenshots under CSP #12636
Mergedcestercian(GitHub profile, opens in a new tab)merged 1 commit into
main fromrefs/pull/12636/headmerged by juliusmarminge View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
- @@ -30,14 +13,10 @@30-export async function capturePreviewAnnotationScreenshot(13+const PNG_DATA_URL_PREFIX = "data:image/png;base64,";14+15+/** Decode Electron's PNG crop locally; fetching a data URL violates desktop connect-src. */16+export function capturePreviewAnnotationScreenshot(3117 annotation: PreviewAnnotationPayload,32- timeoutMs: number = PREVIEW_ANNOTATION_CAPTURE_TIMEOUT_MS,33-): Promise<PreviewAnnotationCapture> {18+): PreviewAnnotationCapture {3419 if (!annotation.screenshot) return { status: "none" };35- let timer: ReturnType<typeof setTimeout> | undefined;3620 try {37- const file = await Promise.race([38- previewAnnotationScreenshotFile(annotation),39- new Promise<null>((resolve) => {40- timer = setTimeout(() => resolve(null), timeoutMs);41- }),42- ]);43- return file ? { status: "captured", file } : { status: "failed" };21+ const { dataUrl } = annotation.screenshot;22+ if (!dataUrl.startsWith(PNG_DATA_URL_PREFIX)) {
- apps/web/src/lib/previewAnnotation.ts line 25Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -31,13 +15,11 @@15+/** Decode Electron's PNG crop locally; fetching a data URL violates desktop connect-src. */16+export function capturePreviewAnnotationScreenshot(3117 annotation: PreviewAnnotationPayload,32- timeoutMs: number = PREVIEW_ANNOTATION_CAPTURE_TIMEOUT_MS,33-): Promise<PreviewAnnotationCapture> {18+): PreviewAnnotationCapture {3419 if (!annotation.screenshot) return { status: "none" };35- let timer: ReturnType<typeof setTimeout> | undefined;3620 try {37- const file = await Promise.race([38- previewAnnotationScreenshotFile(annotation),39- new Promise<null>((resolve) => {40- timer = setTimeout(() => resolve(null), timeoutMs);41- }),42- ]);43- return file ? { status: "captured", file } : { status: "failed" };21+ const { dataUrl } = annotation.screenshot;22+ if (!dataUrl.startsWith(PNG_DATA_URL_PREFIX)) {23+ return { status: "failed" };24+ }25+ const file = dataUrlToFile(dataUrl, `preview-annotation-${annotation.id}.png`, "image/png");
github-actions[bot](GitHub profile, opens in a new tab) removed labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes
juliusmarminge merged thisdcf8942
juliusmarminge closed this
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed