From 081ba60e6d1225f59c4f606b19fb6599cabbf8d6 Mon Sep 17 00:00:00 2001 From: Musiker15 Date: Thu, 5 Nov 2026 16:15:30 +0100 Subject: [PATCH] Fix the image upload XSS alert and the minimatch advisory The upload preview is drawn into a canvas instead of an img with an object URL. minimatch is overridden to ^11.0.1 for the eslint packages that still ask for ^10. --- .../tools/images/upload/UploadClient.tsx | 31 ++++++++++++------- package-lock.json | 18 ++++++++--- package.json | 11 ++++++- 3 files changed, 42 insertions(+), 18 deletions(-) diff --git a/app/[lang]/(site)/tools/images/upload/UploadClient.tsx b/app/[lang]/(site)/tools/images/upload/UploadClient.tsx index a25ae41..b0a9fac 100644 --- a/app/[lang]/(site)/tools/images/upload/UploadClient.tsx +++ b/app/[lang]/(site)/tools/images/upload/UploadClient.tsx @@ -66,22 +66,33 @@ export default function UploadClient({ lang, initialError }: { lang: Lang; initi ) const formRef = useRef(null) - const [preview, setPreview] = useState(null) + const previewRef = useRef(null) + const [preview, setPreview] = useState(null) const [busy, setBusy] = useState(false) const [failure, setFailure] = useState( initialError ? messageFor(t, initialError) : null, ) const [done, setDone] = useState(false) - // Cleanup only, no setState: otherwise the object URL keeps the file in - // memory for as long as the tab is open. - useEffect(() => () => { if (preview) URL.revokeObjectURL(preview) }, [preview]) + // The preview is drawn into a canvas instead of an with an object + // URL, so nothing derived from the picked file ends up in a DOM attribute. + // No setState here, drawing only. + useEffect(() => { + const canvas = previewRef.current + if (!preview || !canvas) return + canvas.width = preview.width + canvas.height = preview.height + canvas.getContext('2d')?.drawImage(preview, 0, 0) + }, [preview]) const pickFile = (e: React.ChangeEvent) => { const file = e.target.files?.[0] - if (preview) URL.revokeObjectURL(preview) - setPreview(file ? URL.createObjectURL(file) : null) + preview?.close() + setPreview(null) setFailure(null) + // A file the browser cannot decode simply gets no preview; the server + // checks the format again anyway. + if (file) createImageBitmap(file).then(setPreview, () => setPreview(null)) } const submit = async (e: React.FormEvent) => { @@ -101,7 +112,7 @@ export default function UploadClient({ lang, initialError }: { lang: Lang; initi const d = await r.json().catch(() => ({})) if (!r.ok) throw new Error(typeof d.error === 'string' ? d.error : 'generic') formRef.current.reset() - if (preview) URL.revokeObjectURL(preview) + preview?.close() setPreview(null) setDone(true) await reload() @@ -232,11 +243,7 @@ export default function UploadClient({ lang, initialError }: { lang: Lang; initi

{t.form_file_hint}

{preview && (
- {/* eslint-disable-next-line @next/next/no-img-element -- - A blob: URL from the local file picker. next/image - cannot optimize it and is not supposed to: the - file has not even left the computer yet. */} - +
)} diff --git a/package-lock.json b/package-lock.json index f84d3a6..209238d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1112,6 +1112,13 @@ "url": "https://opencollective.com/libvips" } }, + "node_modules/@isaacs/nonrecursive-glob-match": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/@isaacs/nonrecursive-glob-match/-/nonrecursive-glob-match-1.0.3.tgz", + "integrity": "sha512-SI7kyKHq4XXDRozw+r9GlRZkia1ZkFrpLW98r2IC2Bpr8YkFGE3fvjzmxCG0x78A++69HmDNrDvSMYBZmHGpKA==", + "dev": true, + "license": "BlueOak-1.0.0" + }, "node_modules/@jridgewell/gen-mapping": { "version": "0.3.13", "resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.13.tgz", @@ -6056,16 +6063,17 @@ } }, "node_modules/minimatch": { - "version": "10.2.6", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-10.2.6.tgz", - "integrity": "sha512-vpLQEs+VLCr1nU0BXS07maYoFwlDAH0gngQuuttxIwutDFEMHq2blX+8vpgxDdK3J1PwjCJiep77OitTZ4Ll1A==", + "version": "11.0.4", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-11.0.4.tgz", + "integrity": "sha512-/UJ1dEoVQTjPNDh6SGlUo+ueLMmoHTas4q+8yaAR/5t6nLAIiBDJtoYUh20IYleix7ehiQkgczb84PE3uzHkxg==", "dev": true, "license": "BlueOak-1.0.0", "dependencies": { - "brace-expansion": "^5.0.8" + "@isaacs/nonrecursive-glob-match": "^1.0.3", + "brace-expansion": "^5.0.12" }, "engines": { - "node": "18 || 20 || >=22" + "node": "20 || >=22" }, "funding": { "url": "https://github.com/sponsors/isaacs" diff --git a/package.json b/package.json index c6557ce..53dcceb 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,16 @@ }, "overrides": { "postcss": "$postcss", - "eslint": "$eslint", + "eslint": { + ".": "$eslint", + "minimatch": "^11.0.1" + }, + "@eslint/config-array": { + "minimatch": "^11.0.1" + }, + "@typescript-eslint/typescript-estree": { + "minimatch": "^11.0.1" + }, "js-yaml": "^4.2.0", "sharp": "$sharp" }