Add: メールドメインの自動ブラックリスト追加を追加

This commit is contained in:
鴇峰 朔華 2024-11-25 21:38:32 +09:00
parent 866cd43207
commit a7270735b0
7 changed files with 52 additions and 0 deletions

View file

@ -0,0 +1,16 @@
/*
* SPDX-FileCopyrightText: syuilo and misskey-project
* SPDX-License-Identifier: AGPL-3.0-only
*/
export class AddAutoAddBannedEmailDomain1732535648378 {
name = 'AddAutoAddBannedEmailDomain1732535648378'
async up(queryRunner) {
await queryRunner.query(`ALTER TABLE "meta" ADD "enableAutoAddBannedEmailDomain" boolean NOT NULL DEFAULT false`);
}
async down(queryRunner) {
await queryRunner.query(`ALTER TABLE "meta" DROP COLUMN "enableAutoAddBannedEmailDomain"`);
}
}

View file

@ -16,6 +16,7 @@ import type { MiMeta, UserProfilesRepository } from '@/models/_.js';
import { LoggerService } from '@/core/LoggerService.js'; import { LoggerService } from '@/core/LoggerService.js';
import { bindThis } from '@/decorators.js'; import { bindThis } from '@/decorators.js';
import { HttpRequestService } from '@/core/HttpRequestService.js'; import { HttpRequestService } from '@/core/HttpRequestService.js';
import { MetaService } from '@/core/MetaService.js';
@Injectable() @Injectable()
export class EmailService { export class EmailService {
@ -34,6 +35,7 @@ export class EmailService {
private loggerService: LoggerService, private loggerService: LoggerService,
private utilityService: UtilityService, private utilityService: UtilityService,
private httpRequestService: HttpRequestService, private httpRequestService: HttpRequestService,
private metaService: MetaService,
) { ) {
this.logger = this.loggerService.getLogger('email'); this.logger = this.loggerService.getLogger('email');
} }
@ -227,6 +229,11 @@ export class EmailService {
blacklist: 'blacklist', blacklist: 'blacklist',
}; };
// 自動追加が有効な場合はブラックリストに追加する
if (this.meta.enableAutoAddBannedEmailDomain) {
await this.addBlockedHost(emailDomain);
}
return { return {
available: false, available: false,
reason: validated.reason ? formatReason[validated.reason] ?? null : null, reason: validated.reason ? formatReason[validated.reason] ?? null : null,
@ -372,4 +379,11 @@ export class EmailService {
}; };
} }
} }
private async addBlockedHost(domain: string) {
const set = {} as Partial<MiMeta>;
set.bannedEmailDomains = this.meta.bannedEmailDomains;
set.bannedEmailDomains.push(domain);
await this.metaService.update(set);
}
} }

View file

@ -576,6 +576,11 @@ export class MiMeta {
}) })
public allowedEmailDomains: string[]; public allowedEmailDomains: string[];
@Column('boolean', {
default: false,
})
public enableAutoAddBannedEmailDomain: boolean;
@Column('varchar', { @Column('varchar', {
length: 1024, array: true, default: '{ "admin", "administrator", "root", "system", "maintainer", "host", "mod", "moderator", "owner", "superuser", "staff", "auth", "i", "me", "everyone", "all", "mention", "mentions", "example", "user", "users", "account", "accounts", "official", "help", "helps", "support", "supports", "info", "information", "informations", "announce", "announces", "announcement", "announcements", "notice", "notification", "notifications", "dev", "developer", "developers", "tech", "misskey" }', length: 1024, array: true, default: '{ "admin", "administrator", "root", "system", "maintainer", "host", "mod", "moderator", "owner", "superuser", "staff", "auth", "i", "me", "everyone", "all", "mention", "mentions", "example", "user", "users", "account", "accounts", "official", "help", "helps", "support", "supports", "info", "information", "informations", "announce", "announces", "announcement", "announcements", "notice", "notification", "notifications", "dev", "developer", "developers", "tech", "misskey" }',
}) })

View file

@ -348,6 +348,10 @@ export const meta = {
type: 'string', type: 'string',
optional: false, nullable: true, optional: false, nullable: true,
}, },
enableAutoAddBannedEmailDomain: {
type: 'boolean',
optional: false, nullable: false,
},
enableChartsForRemoteUser: { enableChartsForRemoteUser: {
type: 'boolean', type: 'boolean',
optional: false, nullable: false, optional: false, nullable: false,
@ -645,6 +649,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
enableTruemailApi: instance.enableTruemailApi, enableTruemailApi: instance.enableTruemailApi,
truemailInstance: instance.truemailInstance, truemailInstance: instance.truemailInstance,
truemailAuthKey: instance.truemailAuthKey, truemailAuthKey: instance.truemailAuthKey,
enableAutoAddBannedEmailDomain: instance.enableAutoAddBannedEmailDomain,
enableChartsForRemoteUser: instance.enableChartsForRemoteUser, enableChartsForRemoteUser: instance.enableChartsForRemoteUser,
enableChartsForFederatedInstances: instance.enableChartsForFederatedInstances, enableChartsForFederatedInstances: instance.enableChartsForFederatedInstances,
enableStatsForFederatedInstances: instance.enableStatsForFederatedInstances, enableStatsForFederatedInstances: instance.enableStatsForFederatedInstances,

View file

@ -142,6 +142,7 @@ export const paramDef = {
serverRules: { type: 'array', items: { type: 'string' } }, serverRules: { type: 'array', items: { type: 'string' } },
bannedEmailDomains: { type: 'array', items: { type: 'string' } }, bannedEmailDomains: { type: 'array', items: { type: 'string' } },
allowedEmailDomains: { type: 'array', items: { type: 'string' } }, allowedEmailDomains: { type: 'array', items: { type: 'string' } },
enableAutoAddBannedEmailDomain: { type: 'boolean' },
preservedUsernames: { type: 'array', items: { type: 'string' } }, preservedUsernames: { type: 'array', items: { type: 'string' } },
manifestJsonOverride: { type: 'string' }, manifestJsonOverride: { type: 'string' },
enableFanoutTimeline: { type: 'boolean' }, enableFanoutTimeline: { type: 'boolean' },
@ -644,6 +645,10 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
set.allowedEmailDomains = ps.allowedEmailDomains; set.allowedEmailDomains = ps.allowedEmailDomains;
} }
if (ps.enableAutoAddBannedEmailDomain !== undefined) {
set.enableAutoAddBannedEmailDomain = ps.enableAutoAddBannedEmailDomain;
}
if (ps.urlPreviewEnabled !== undefined) { if (ps.urlPreviewEnabled !== undefined) {
set.urlPreviewEnabled = ps.urlPreviewEnabled; set.urlPreviewEnabled = ps.urlPreviewEnabled;
} }

View file

@ -85,6 +85,9 @@ SPDX-License-Identifier: AGPL-3.0-only
<template #prefix><i class="ti ti-key"></i></template> <template #prefix><i class="ti ti-key"></i></template>
<template #label>TrueMail API Auth Key</template> <template #label>TrueMail API Auth Key</template>
</MkInput> </MkInput>
<MkSwitch v-model="emailValidationForm.state.enableAutoAddBannedEmailDomain">
<template #label>Enable Auto Add Banned Email Domain</template>
</MkSwitch>
</div> </div>
</MkFolder> </MkFolder>
@ -194,6 +197,7 @@ const emailValidationForm = useForm({
enableTruemailApi: meta.enableTruemailApi, enableTruemailApi: meta.enableTruemailApi,
truemailInstance: meta.truemailInstance, truemailInstance: meta.truemailInstance,
truemailAuthKey: meta.truemailAuthKey, truemailAuthKey: meta.truemailAuthKey,
enableAutoAddBannedEmailDomain: meta.enableAutoAddBannedEmailDomain,
}, async (state) => { }, async (state) => {
await os.apiWithDialog('admin/update-meta', { await os.apiWithDialog('admin/update-meta', {
enableActiveEmailValidation: state.enableActiveEmailValidation, enableActiveEmailValidation: state.enableActiveEmailValidation,
@ -202,6 +206,7 @@ const emailValidationForm = useForm({
enableTruemailApi: state.enableTruemailApi, enableTruemailApi: state.enableTruemailApi,
truemailInstance: state.truemailInstance, truemailInstance: state.truemailInstance,
truemailAuthKey: state.truemailAuthKey, truemailAuthKey: state.truemailAuthKey,
enableAutoAddBannedEmailDomain: state.enableAutoAddBannedEmailDomain,
}); });
fetchInstance(true); fetchInstance(true);
}); });

View file

@ -5176,6 +5176,7 @@ export type operations = {
enableTruemailApi: boolean; enableTruemailApi: boolean;
truemailInstance: string | null; truemailInstance: string | null;
truemailAuthKey: string | null; truemailAuthKey: string | null;
enableAutoAddBannedEmailDomain: boolean;
enableChartsForRemoteUser: boolean; enableChartsForRemoteUser: boolean;
enableChartsForFederatedInstances: boolean; enableChartsForFederatedInstances: boolean;
enableStatsForFederatedInstances: boolean; enableStatsForFederatedInstances: boolean;
@ -9580,6 +9581,7 @@ export type operations = {
serverRules?: string[]; serverRules?: string[];
bannedEmailDomains?: string[]; bannedEmailDomains?: string[];
allowedEmailDomains?: string[]; allowedEmailDomains?: string[];
enableAutoAddBannedEmailDomain?: boolean;
preservedUsernames?: string[]; preservedUsernames?: string[];
manifestJsonOverride?: string; manifestJsonOverride?: string;
enableFanoutTimeline?: boolean; enableFanoutTimeline?: boolean;