From b3e34795c0964faca8296d297251b3af5b681950 Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Thu, 1 Dec 2022 12:07:43 -0500 Subject: [PATCH] require punycode conversion beforehand for admins --- locales/en-US.yml | 2 +- packages/backend/src/misc/skipped-instances.ts | 11 ++++------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/locales/en-US.yml b/locales/en-US.yml index 3ccdc7586..a6a8a2110 100644 --- a/locales/en-US.yml +++ b/locales/en-US.yml @@ -187,7 +187,7 @@ clearCachedFiles: "Clear cache" clearCachedFilesConfirm: "Are you sure that you want to delete all cached remote files?" blockedInstances: "Blocked Instances" blockedInstancesDescription: "List the hostnames of the instances that you want to\ - \ block. Listed instances will no longer be able to communicate with this instance. You can use an asterisk (*) as a placeholder for zero or more character(s)." + \ block. Listed instances will no longer be able to communicate with this instance. Non-ASCII domain names must be encoded in punycode. You can use an asterisk (*) as a placeholder for zero or more character(s)." muteAndBlock: "Mutes and Blocks" mutedUsers: "Muted users" blockedUsers: "Blocked users" diff --git a/packages/backend/src/misc/skipped-instances.ts b/packages/backend/src/misc/skipped-instances.ts index ebedb50d3..de42e14d2 100644 --- a/packages/backend/src/misc/skipped-instances.ts +++ b/packages/backend/src/misc/skipped-instances.ts @@ -1,4 +1,3 @@ -import { toASCII } from 'punycode/'; import { db } from '@/db/postgre.js'; import { fetchMeta } from '@/misc/fetch-meta.js'; import { Instance } from '@/models/entities/instance.js'; @@ -10,19 +9,17 @@ const deadThreshold = 7 * DAY; /** * Returns whether a given host matches a wildcard pattern. - * @param host instance host - * @param pattern wildcard pattern containing an instance host + * @param host punycoded instance host + * @param pattern wildcard pattern containing a punycoded instance host * @returns whether the post matches the pattern */ function matchHost(host: Instance['host'], pattern: string): boolean { // Escape all of the regex special characters. Pattern from: // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#escaping const escape = (str: string): string => str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); - const re = new RegExp('^' + pattern.split('*').map(toASCII).map(escape).join('.*') + '$'); + const re = new RegExp('^' + pattern.split('*').map(escape).join('.*') + '$'); - // Encode the domain in punycode in case it uses non-ascii - const punycoded = toASCII(host); - return re.test(punycoded); + return re.test(host); } /**