don't generate URL previews for blocked domains
This commit is contained in:
parent
4c6cec552e
commit
2a4c432f41
|
@ -17,6 +17,7 @@ import { bindThis } from '@/decorators.js';
|
||||||
import { ApiError } from '@/server/api/error.js';
|
import { ApiError } from '@/server/api/error.js';
|
||||||
import { MiMeta } from '@/models/Meta.js';
|
import { MiMeta } from '@/models/Meta.js';
|
||||||
import { RedisKVCache } from '@/misc/cache.js';
|
import { RedisKVCache } from '@/misc/cache.js';
|
||||||
|
import { UtilityService } from '@/core/UtilityService.js';
|
||||||
import type { FastifyRequest, FastifyReply } from 'fastify';
|
import type { FastifyRequest, FastifyReply } from 'fastify';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
|
@ -36,6 +37,7 @@ export class UrlPreviewService {
|
||||||
|
|
||||||
private httpRequestService: HttpRequestService,
|
private httpRequestService: HttpRequestService,
|
||||||
private loggerService: LoggerService,
|
private loggerService: LoggerService,
|
||||||
|
private utilityService: UtilityService,
|
||||||
) {
|
) {
|
||||||
this.logger = this.loggerService.getLogger('url-preview');
|
this.logger = this.loggerService.getLogger('url-preview');
|
||||||
this.previewCache = new RedisKVCache<SummalyResult>(this.redisClient, 'summaly', {
|
this.previewCache = new RedisKVCache<SummalyResult>(this.redisClient, 'summaly', {
|
||||||
|
@ -87,6 +89,18 @@ export class UrlPreviewService {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const host = new URL(url).host;
|
||||||
|
if (this.utilityService.isBlockedHost(this.meta.blockedHosts, host)) {
|
||||||
|
reply.code(403);
|
||||||
|
return {
|
||||||
|
error: new ApiError({
|
||||||
|
message: 'URL is blocked',
|
||||||
|
code: 'URL_PREVIEW_BLOCKED',
|
||||||
|
id: '50294652-857b-4b13-9700-8e5c7a8deae8',
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
const key = `${url}@${lang}`;
|
const key = `${url}@${lang}`;
|
||||||
const cached = await this.previewCache.get(key);
|
const cached = await this.previewCache.get(key);
|
||||||
if (cached !== undefined) {
|
if (cached !== undefined) {
|
||||||
|
|
Loading…
Reference in New Issue