diff --git a/built/file-info.js b/built/file-info.js index a04c39b..8708b59 100644 --- a/built/file-info.js +++ b/built/file-info.js @@ -26,6 +26,9 @@ export async function detectType(path) { if (type.mime === 'application/xml' && await checkSvg(path)) { return TYPE_SVG; } + if (isMimeImage(type.mime, 'safe-file')) { + return TYPE_OCTET_STREAM; + } return { mime: type.mime, ext: type.ext, diff --git a/built/index.js b/built/index.js index cdfdf03..84b8227 100644 --- a/built/index.js +++ b/built/index.js @@ -3,7 +3,6 @@ import { fileURLToPath } from 'node:url'; import { dirname } from 'node:path'; import fastifyStatic from '@fastify/static'; import { createTemp } from './create-temp.js'; -import { FILE_TYPE_BROWSERSAFE } from './const.js'; import { convertToWebpStream, webpDefault } from './image-processor.js'; import { detectType, isMimeImage } from './file-info.js'; import sharp from 'sharp'; @@ -149,9 +148,6 @@ async function proxyHandler(request, reply) { else if (file.mime === 'image/svg+xml') { image = convertToWebpStream(file.path, 2048, 2048); } - else if (!file.mime.startsWith('image/') || !FILE_TYPE_BROWSERSAFE.includes(file.mime)) { - throw new StatusError('Rejected type', 403, 'Rejected type'); - } if (!image) { image = { data: fs.createReadStream(file.path), diff --git a/src/file-info.ts b/src/file-info.ts index 44907d6..73631d7 100644 --- a/src/file-info.ts +++ b/src/file-info.ts @@ -34,6 +34,10 @@ export async function detectType(path: string): Promise<{ return TYPE_SVG; } + if (isMimeImage(type.mime, 'safe-file')) { + return TYPE_OCTET_STREAM; + } + return { mime: type.mime, ext: type.ext, diff --git a/src/index.ts b/src/index.ts index aa92f22..09ef82c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -191,8 +191,6 @@ async function proxyHandler(request: FastifyRequest<{ Params: { url: string; }; }; } else if (file.mime === 'image/svg+xml') { image = convertToWebpStream(file.path, 2048, 2048); - } else if (!file.mime.startsWith('image/') || !FILE_TYPE_BROWSERSAFE.includes(file.mime)) { - throw new StatusError('Rejected type', 403, 'Rejected type'); } if (!image) {