require punycode conversion beforehand for admins

This commit is contained in:
Norm 2022-12-01 12:07:43 -05:00
parent a35c98bbd5
commit b3e34795c0
Signed by untrusted user: norm
GPG key ID: 7123E30E441E80DE
2 changed files with 5 additions and 8 deletions

View file

@ -187,7 +187,7 @@ clearCachedFiles: "Clear cache"
clearCachedFilesConfirm: "Are you sure that you want to delete all cached remote files?" clearCachedFilesConfirm: "Are you sure that you want to delete all cached remote files?"
blockedInstances: "Blocked Instances" blockedInstances: "Blocked Instances"
blockedInstancesDescription: "List the hostnames of the instances that you want to\ 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" muteAndBlock: "Mutes and Blocks"
mutedUsers: "Muted users" mutedUsers: "Muted users"
blockedUsers: "Blocked users" blockedUsers: "Blocked users"

View file

@ -1,4 +1,3 @@
import { toASCII } from 'punycode/';
import { db } from '@/db/postgre.js'; import { db } from '@/db/postgre.js';
import { fetchMeta } from '@/misc/fetch-meta.js'; import { fetchMeta } from '@/misc/fetch-meta.js';
import { Instance } from '@/models/entities/instance.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. * Returns whether a given host matches a wildcard pattern.
* @param host instance host * @param host punycoded instance host
* @param pattern wildcard pattern containing an instance host * @param pattern wildcard pattern containing a punycoded instance host
* @returns whether the post matches the pattern * @returns whether the post matches the pattern
*/ */
function matchHost(host: Instance['host'], pattern: string): boolean { function matchHost(host: Instance['host'], pattern: string): boolean {
// Escape all of the regex special characters. Pattern from: // Escape all of the regex special characters. Pattern from:
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#escaping // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#escaping
const escape = (str: string): string => str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); 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 return re.test(host);
const punycoded = toASCII(host);
return re.test(punycoded);
} }
/** /**