revert FILE_TYPE_BROWSERSAFE規制を復活

BROWSERSAFEではないならTYPE_OCTET_STREAMにする
This commit is contained in:
tamaina 2023-02-09 13:11:17 +00:00
parent b415f59b72
commit ddc778d208
4 changed files with 7 additions and 6 deletions

View File

@ -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,

View File

@ -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),

View File

@ -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,

View File

@ -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) {