No longer returns 403 if the file is not an image.

This commit is contained in:
tamaina 2023-02-07 13:38:55 +00:00
parent 39908281a1
commit 28ac7a4341
5 changed files with 4 additions and 9 deletions

View File

@ -2,6 +2,8 @@
Misskeyの/proxyが単体で動作しますMisskeyのコードがほぼそのまま移植されています
/proxyは画像ではないと403を返しますが、Media Proxyではそのまま内容を送信します。
**Fastifyプラグインとして動作する気がします。**
`pnpm start`は[fastify-cli](https://github.com/fastify/fastify-cli)が動作します。
@ -52,7 +54,7 @@ export default {
// プライベートネットワークでも許可するIP CIDRdefault.ymlと同じ
allowedPrivateNetworks: [],
// ダウンロードするファイルの最大サイズ
// ダウンロードするファイルの最大サイズ (bytes)
maxSize: 262144000,
// フォワードプロキシ

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';
@ -143,9 +142,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

@ -1,6 +1,6 @@
{
"name": "misskey-media-proxy",
"version": "0.0.3",
"version": "0.0.4",
"description": "The Media Proxy for Misskey",
"main": "built/index.js",
"packageManager": "pnpm@7.26.0",

View File

@ -93,7 +93,6 @@ export async function downloadUrl(url: string, path: string, settings:DownloadCo
if (process.env.NODE_ENV !== 'production') console.log(`Download finished: ${url}`);
}
function isPrivateIp(ip: string, allowedPrivateNetworks: string[]): boolean {
for (const net of allowedPrivateNetworks ?? []) {
const cidr = new IPCIDR(net);

View File

@ -182,8 +182,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) {