From c05aedb1b22dc335087579dfc49b8da21baebfe7 Mon Sep 17 00:00:00 2001 From: adzukimame <88547072+adzuki02@users.noreply.github.com> Date: Wed, 11 Dec 2024 10:25:35 +0900 Subject: [PATCH 1/5] =?UTF-8?q?production=E7=92=B0=E5=A2=83=E3=81=A7?= =?UTF-8?q?=E3=81=AF=E6=9C=AC=E4=BD=93=E3=83=A1=E3=83=87=E3=82=A3=E3=82=A2?= =?UTF-8?q?=E3=83=97=E3=83=AD=E3=82=AD=E3=82=B7=E3=82=92=E8=B5=B7=E5=8B=95?= =?UTF-8?q?=E3=81=97=E3=81=AA=E3=81=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/backend/src/server/FileServerService.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/packages/backend/src/server/FileServerService.ts b/packages/backend/src/server/FileServerService.ts index 228b36a7d521..cc35dfad679f 100644 --- a/packages/backend/src/server/FileServerService.ts +++ b/packages/backend/src/server/FileServerService.ts @@ -86,13 +86,15 @@ export class FileServerService { done(); }); - fastify.get<{ - Params: { url: string; }; - Querystring: { url?: string; }; - }>('/proxy/:url*', async (request, reply) => { - return await this.proxyHandler(request, reply) - .catch(err => this.errorHandler(request, reply, err)); - }); + if (process.env.NODE_ENV !== 'production') { + fastify.get<{ + Params: { url: string; }; + Querystring: { url?: string; }; + }>('/proxy/:url*', async (request, reply) => { + return await this.proxyHandler(request, reply) + .catch(err => this.errorHandler(request, reply, err)); + }); + } done(); } From aa261d2d76c3041a4669c51a42ae309b757ba743 Mon Sep 17 00:00:00 2001 From: adzukimame <88547072+adzuki02@users.noreply.github.com> Date: Wed, 11 Dec 2024 10:25:50 +0900 Subject: [PATCH 2/5] =?UTF-8?q?=E6=9C=AC=E4=BD=93=E3=82=B5=E3=83=9E?= =?UTF-8?q?=E3=83=AA=E3=83=BC=E3=83=97=E3=83=AD=E3=82=AD=E3=82=B7=E3=82=92?= =?UTF-8?q?=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/backend/package.json | 2 +- .../src/server/web/UrlPreviewService.ts | 28 ++----------------- pnpm-lock.yaml | 6 ++-- 3 files changed, 7 insertions(+), 29 deletions(-) diff --git a/packages/backend/package.json b/packages/backend/package.json index a7a7df8c28d5..fee473c2b46a 100644 --- a/packages/backend/package.json +++ b/packages/backend/package.json @@ -53,7 +53,6 @@ "@fastify/static": "8.0.1", "@fastify/view": "10.0.1", "@misskey-dev/sharp-read-bmp": "1.2.0", - "@misskey-dev/summaly": "5.1.0", "@nestjs/common": "10.4.4", "@nestjs/core": "10.4.4", "@nestjs/testing": "10.4.4", @@ -141,6 +140,7 @@ }, "devDependencies": { "@jest/globals": "29.7.0", + "@misskey-dev/summaly": "5.1.0", "@nestjs/platform-express": "10.4.4", "@simplewebauthn/types": "10.0.0", "@swc/cli": "0.3.12", diff --git a/packages/backend/src/server/web/UrlPreviewService.ts b/packages/backend/src/server/web/UrlPreviewService.ts index 53c6e7c0feb3..0e36f9b1a095 100644 --- a/packages/backend/src/server/web/UrlPreviewService.ts +++ b/packages/backend/src/server/web/UrlPreviewService.ts @@ -4,8 +4,6 @@ */ import { Inject, Injectable } from '@nestjs/common'; -import { summaly } from '@misskey-dev/summaly'; -import { SummalyResult } from '@misskey-dev/summaly/built/summary.js'; import { DI } from '@/di-symbols.js'; import type { Config } from '@/config.js'; import { HttpRequestService } from '@/core/HttpRequestService.js'; @@ -15,6 +13,7 @@ import { LoggerService } from '@/core/LoggerService.js'; import { bindThis } from '@/decorators.js'; import { ApiError } from '@/server/api/error.js'; import { MiMeta } from '@/models/Meta.js'; +import type { SummalyResult } from '@misskey-dev/summaly/built/summary.js'; import type { FastifyRequest, FastifyReply } from 'fastify'; @Injectable() @@ -63,7 +62,7 @@ export class UrlPreviewService { return; } - if (!this.meta.urlPreviewEnabled) { + if (!this.meta.urlPreviewEnabled || this.meta.urlPreviewSummaryProxyUrl === null) { reply.code(403); return { error: new ApiError({ @@ -79,9 +78,7 @@ export class UrlPreviewService { : `Getting preview of ${url}@${lang} ...`); try { - const summary = this.meta.urlPreviewSummaryProxyUrl - ? await this.fetchSummaryFromProxy(url, this.meta, lang) - : await this.fetchSummary(url, this.meta, lang); + const summary = await this.fetchSummaryFromProxy(url, this.meta, lang); this.logger.succ(`Got preview of ${url}: ${summary.title}`); @@ -115,25 +112,6 @@ export class UrlPreviewService { } } - private fetchSummary(url: string, meta: MiMeta, lang?: string): Promise { - const agent = this.config.proxy - ? { - http: this.httpRequestService.httpAgent, - https: this.httpRequestService.httpsAgent, - } - : undefined; - - return summaly(url, { - followRedirects: false, - lang: lang ?? 'ja-JP', - agent: agent, - userAgent: meta.urlPreviewUserAgent ?? undefined, - operationTimeout: meta.urlPreviewTimeout, - contentLengthLimit: meta.urlPreviewMaximumContentLength, - contentLengthRequired: meta.urlPreviewRequireContentLength, - }); - } - private fetchSummaryFromProxy(url: string, meta: MiMeta, lang?: string): Promise { const proxy = meta.urlPreviewSummaryProxyUrl!; const queryStr = query({ diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c6e1240cba08..f20a202c9d0c 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -120,9 +120,6 @@ importers: '@misskey-dev/sharp-read-bmp': specifier: 1.2.0 version: 1.2.0 - '@misskey-dev/summaly': - specifier: 5.1.0 - version: 5.1.0 '@nestjs/common': specifier: 10.4.4 version: 10.4.4(reflect-metadata@0.2.2)(rxjs@7.8.1) @@ -383,6 +380,9 @@ importers: '@jest/globals': specifier: 29.7.0 version: 29.7.0 + '@misskey-dev/summaly': + specifier: 5.1.0 + version: 5.1.0 '@nestjs/platform-express': specifier: 10.4.4 version: 10.4.4(@nestjs/common@10.4.4(reflect-metadata@0.2.2)(rxjs@7.8.1))(@nestjs/core@10.4.4) From 707196ef7f393835ddf19cb7099790a2bf9ac77a Mon Sep 17 00:00:00 2001 From: adzukimame <88547072+adzuki02@users.noreply.github.com> Date: Wed, 11 Dec 2024 16:54:32 +0900 Subject: [PATCH 3/5] =?UTF-8?q?=E3=83=A1=E3=83=87=E3=82=A3=E3=82=A2?= =?UTF-8?q?=E3=83=97=E3=83=AD=E3=82=AD=E3=82=B7=E3=81=AEorigin=E3=83=91?= =?UTF-8?q?=E3=83=A9=E3=83=A1=E3=83=BC=E3=82=BF=E3=82=92=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/backend/src/server/FileServerService.ts | 5 +---- packages/frontend/src/components/global/MkCustomEmoji.vue | 1 - packages/frontend/src/scripts/media-proxy.ts | 5 ++--- 3 files changed, 3 insertions(+), 8 deletions(-) diff --git a/packages/backend/src/server/FileServerService.ts b/packages/backend/src/server/FileServerService.ts index cc35dfad679f..d0b9305c5800 100644 --- a/packages/backend/src/server/FileServerService.ts +++ b/packages/backend/src/server/FileServerService.ts @@ -300,10 +300,7 @@ export class FileServerService { return; } - // アバタークロップなど、どうしてもオリジンである必要がある場合 - const mustOrigin = 'origin' in request.query; - - if (this.config.externalMediaProxyEnabled && !mustOrigin) { + if (this.config.externalMediaProxyEnabled) { // 外部のメディアプロキシが有効なら、そちらにリダイレクト reply.header('Cache-Control', 'public, max-age=259200'); // 3 days diff --git a/packages/frontend/src/components/global/MkCustomEmoji.vue b/packages/frontend/src/components/global/MkCustomEmoji.vue index ee64c8e8b5a4..1ab94915bf6f 100644 --- a/packages/frontend/src/components/global/MkCustomEmoji.vue +++ b/packages/frontend/src/components/global/MkCustomEmoji.vue @@ -72,7 +72,6 @@ const url = computed(() => { : getProxiedImageUrl( rawUrl.value, props.useOriginalSize ? undefined : 'emoji', - false, true, ); return defaultStore.reactiveState.disableShowingAnimatedImages.value && !props.forceShowingAnimatedImages diff --git a/packages/frontend/src/scripts/media-proxy.ts b/packages/frontend/src/scripts/media-proxy.ts index 099a22163af4..e9048867cfe8 100644 --- a/packages/frontend/src/scripts/media-proxy.ts +++ b/packages/frontend/src/scripts/media-proxy.ts @@ -7,7 +7,7 @@ import { query } from '@/scripts/url.js'; import { url } from '@/config.js'; import { instance } from '@/instance.js'; -export function getProxiedImageUrl(imageUrl: string, type?: 'preview' | 'emoji' | 'avatar', mustOrigin = false, noFallback = false): string { +export function getProxiedImageUrl(imageUrl: string, type?: 'preview' | 'emoji' | 'avatar', noFallback = false): string { const localProxy = `${url}/proxy`; if (imageUrl.startsWith(instance.mediaProxy + '/') || imageUrl.startsWith('/proxy/') || imageUrl.startsWith(localProxy + '/')) { @@ -15,14 +15,13 @@ export function getProxiedImageUrl(imageUrl: string, type?: 'preview' | 'emoji' imageUrl = (new URL(imageUrl)).searchParams.get('url') ?? imageUrl; } - return `${mustOrigin ? localProxy : instance.mediaProxy}/${ + return `${instance.mediaProxy}/${ type === 'preview' ? 'preview.webp' : 'image.webp' }?${query({ url: imageUrl, ...(!noFallback ? { 'fallback': '1' } : {}), ...(type ? { [type]: '1' } : {}), - ...(mustOrigin ? { origin: '1' } : {}), })}`; } From e3ff3113fa57fefb8b58b11d46cd793a5dc1e5d7 Mon Sep 17 00:00:00 2001 From: adzukimame <88547072+adzuki02@users.noreply.github.com> Date: Wed, 11 Dec 2024 17:10:15 +0900 Subject: [PATCH 4/5] =?UTF-8?q?production=E7=92=B0=E5=A2=83=E3=81=A7?= =?UTF-8?q?=E3=81=AF/proxy=E4=BB=A5=E4=B8=8B=E3=81=B8=E3=81=AE=E3=83=AA?= =?UTF-8?q?=E3=82=AF=E3=82=A8=E3=82=B9=E3=83=88=E3=81=AB404=E3=82=92?= =?UTF-8?q?=E8=BF=94=E3=81=99=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/backend/src/server/FileServerService.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/backend/src/server/FileServerService.ts b/packages/backend/src/server/FileServerService.ts index d0b9305c5800..20d16978abbf 100644 --- a/packages/backend/src/server/FileServerService.ts +++ b/packages/backend/src/server/FileServerService.ts @@ -86,7 +86,11 @@ export class FileServerService { done(); }); - if (process.env.NODE_ENV !== 'production') { + if (process.env.NODE_ENV === 'production') { + fastify.get('/proxy/*', async (request, reply) => { + return reply.status(404).send(); + }); + } else { fastify.get<{ Params: { url: string; }; Querystring: { url?: string; }; From 3c2ec2fed2b15e96f05e34003c06fc6f1db4393c Mon Sep 17 00:00:00 2001 From: adzukimame <88547072+adzuki02@users.noreply.github.com> Date: Wed, 11 Dec 2024 17:35:58 +0900 Subject: [PATCH 5/5] remove summaly error test --- packages/backend/test/e2e/endpoints.ts | 8 -------- 1 file changed, 8 deletions(-) diff --git a/packages/backend/test/e2e/endpoints.ts b/packages/backend/test/e2e/endpoints.ts index b91d77c398c8..01f23c750e4f 100644 --- a/packages/backend/test/e2e/endpoints.ts +++ b/packages/backend/test/e2e/endpoints.ts @@ -1043,14 +1043,6 @@ describe('Endpoints', () => { }); }); - describe('URL preview', () => { - test('Error from summaly becomes HTTP 422', async () => { - const res = await simpleGet('/url?url=https://e:xample.com'); - assert.strictEqual(res.status, 422); - assert.strictEqual(res.body.error.code, 'URL_PREVIEW_FAILED'); - }); - }); - describe('パーソナルメモ機能のテスト', () => { test('他者に関するメモを更新できる', async () => { const memo = '10月まで低浮上とのこと。';