mirror of
https://activitypub.software/TransFem-org/Sharkey
synced 2024-11-27 16:33:02 +00:00
don't generate URL previews for blocked domains
This commit is contained in:
parent
4c6cec552e
commit
2a4c432f41
1 changed files with 14 additions and 0 deletions
|
@ -17,6 +17,7 @@ import { bindThis } from '@/decorators.js';
|
|||
import { ApiError } from '@/server/api/error.js';
|
||||
import { MiMeta } from '@/models/Meta.js';
|
||||
import { RedisKVCache } from '@/misc/cache.js';
|
||||
import { UtilityService } from '@/core/UtilityService.js';
|
||||
import type { FastifyRequest, FastifyReply } from 'fastify';
|
||||
|
||||
@Injectable()
|
||||
|
@ -36,6 +37,7 @@ export class UrlPreviewService {
|
|||
|
||||
private httpRequestService: HttpRequestService,
|
||||
private loggerService: LoggerService,
|
||||
private utilityService: UtilityService,
|
||||
) {
|
||||
this.logger = this.loggerService.getLogger('url-preview');
|
||||
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 cached = await this.previewCache.get(key);
|
||||
if (cached !== undefined) {
|
||||
|
|
Loading…
Reference in a new issue