Skip to content

Commit

Permalink
Merge pull request #31 from lqvp/shahu
Browse files Browse the repository at this point in the history
  • Loading branch information
chan-mai authored Nov 4, 2024
2 parents 2e7f9ec + 62f043c commit cd41e5a
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 10 deletions.
18 changes: 18 additions & 0 deletions packages/backend/migration/1653288122820-emailWhitelist.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* SPDX-FileCopyrightText: lqvp
* SPDX-License-Identifier: AGPL-3.0-only
*/

export class emailWhitelist1653288122820 {
constructor() {
this.name = 'emailWhitelist1653288122820';
}

async up(queryRunner) {
await queryRunner.query(`ALTER TABLE "meta" ADD "emailWhitelist" boolean NOT NULL DEFAULT false`);
}

async down(queryRunner) {
await queryRunner.query(`ALTER TABLE "meta" DROP COLUMN "emailWhitelist"`);
}
}
29 changes: 21 additions & 8 deletions packages/backend/src/core/EmailService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,14 +215,27 @@ export class EmailService {
}

const emailDomain: string = emailAddress.split('@')[1];
const isBanned = this.utilityService.isBlockedHost(this.meta.bannedEmailDomains, emailDomain);

if (isBanned) {
return {
available: false,
reason: 'banned',
};
}
// emailWhitelistがtrueの場合、bannedEmailDomainsをホワイトリストとして扱う
if (this.meta.emailWhitelist) {
const isWhitelisted = this.utilityService.isBlockedHost(this.meta.bannedEmailDomains, emailDomain);

if (!isWhitelisted) {
return {
available: false,
reason: 'banned',
};
}
} else {
// 従来のブラックリストとしての動作
const isBanned = this.utilityService.isBlockedHost(this.meta.bannedEmailDomains, emailDomain);

if (isBanned) {
return {
available: false,
reason: 'banned',
};
}
}

return {
available: true,
Expand Down
6 changes: 6 additions & 0 deletions packages/backend/src/models/Meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,12 @@ export class MiMeta {
})
public bannedEmailDomains: string[];

@Column('boolean', {
default: false,
})
public emailWhitelist: boolean;


Check failure on line 577 in packages/backend/src/models/Meta.ts

View workflow job for this annotation

GitHub Actions / lint (backend)

More than 1 blank line not allowed
@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" }',
})
Expand Down
5 changes: 5 additions & 0 deletions packages/backend/src/server/api/endpoints/admin/meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,10 @@ export const meta = {
optional: false, nullable: false,
},
},
emailWhitelist: {
type: 'string',
optional: false, nullable: true,
},
preservedUsernames: {
type: 'array',
optional: false, nullable: false,
Expand Down Expand Up @@ -643,6 +647,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
enableServerMachineStats: instance.enableServerMachineStats,
enableIdenticonGeneration: instance.enableIdenticonGeneration,
bannedEmailDomains: instance.bannedEmailDomains,
emailWhitelist: instance.emailWhitelist,
policies: { ...DEFAULT_POLICIES, ...instance.policies },
manifestJsonOverride: instance.manifestJsonOverride,
enableFanoutTimeline: instance.enableFanoutTimeline,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ export const paramDef = {
enableIdenticonGeneration: { type: 'boolean' },
serverRules: { type: 'array', items: { type: 'string' } },
bannedEmailDomains: { type: 'array', items: { type: 'string' } },
emailWhitelist: { type: 'boolean'},

Check failure on line 144 in packages/backend/src/server/api/endpoints/admin/update-meta.ts

View workflow job for this annotation

GitHub Actions / lint (backend)

A space is required before '}'
preservedUsernames: { type: 'array', items: { type: 'string' } },
manifestJsonOverride: { type: 'string' },
enableFanoutTimeline: { type: 'boolean' },
Expand Down Expand Up @@ -639,6 +640,10 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
set.bannedEmailDomains = ps.bannedEmailDomains;
}

if (ps.emailWhitelist !== undefined) {
set.emailWhitelist = ps.emailWhitelist;
}

if (ps.urlPreviewEnabled !== undefined) {
set.urlPreviewEnabled = ps.urlPreviewEnabled;
}
Expand Down
34 changes: 32 additions & 2 deletions packages/frontend/src/pages/admin/security.vue
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,35 @@ SPDX-License-Identifier: AGPL-3.0-only
</MkFolder>

<MkFolder>
<template #label>Banned Email Domains</template>
<template #label>Email WhiteList</template>
<template v-if="emailWhitelistForm.savedState.emailWhitelist" #suffix>Enabled</template>
<template v-else #suffix>Disabled</template>
<template v-if="emailWhitelistForm.modified.value" #footer>
<MkFormFooter :form="emailWhitelistForm"/>
</template>

<div class="_gaps_m">
<MkSwitch v-model="emailWhitelistForm.state.emailWhitelist">
<template #label>Enable</template>
</MkSwitch>
</div>
</MkFolder>

<MkFolder>
<template #label>
<span v-if="emailWhitelistForm.state.emailWhitelist">Whitelist Email Domains</span>
<span v-else>Banned Email Domains</span>
</template>
<template v-if="bannedEmailDomainsForm.modified.value" #footer>
<MkFormFooter :form="bannedEmailDomainsForm"/>
</template>

<div class="_gaps_m">
<MkTextarea v-model="bannedEmailDomainsForm.state.bannedEmailDomains">
<template #label>Banned Email Domains List</template>
<template #label>
<span v-if="emailWhitelistForm.state.emailWhitelist">Whitelist Email Domains List</span>
<span v-else>Banned Email Domains List</span>
</template>
</MkTextarea>
</div>
</MkFolder>
Expand Down Expand Up @@ -174,6 +195,15 @@ const ipLoggingForm = useForm({
fetchInstance(true);
});
const emailWhitelistForm = useForm({
emailWhitelist: meta.emailWhitelist,
}, async (state) => {
await os.apiWithDialog('admin/update-meta', {
emailWhitelist: state.emailWhitelist,
});
fetchInstance(true);
});
const emailValidationForm = useForm({
enableActiveEmailValidation: meta.enableActiveEmailValidation,
enableVerifymailApi: meta.enableVerifymailApi,
Expand Down
2 changes: 2 additions & 0 deletions packages/misskey-js/src/autogen/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5130,6 +5130,7 @@ export type operations = {
prohibitedWords: string[];
prohibitedWordsForNameOfUser: string[];
bannedEmailDomains?: string[];
emailWhitelist?: boolean;
preservedUsernames: string[];
hcaptchaSecretKey: string | null;
mcaptchaSecretKey: string | null;
Expand Down Expand Up @@ -9569,6 +9570,7 @@ export type operations = {
enableIdenticonGeneration?: boolean;
serverRules?: string[];
bannedEmailDomains?: string[];
emailWhitelist?: boolean;
preservedUsernames?: string[];
manifestJsonOverride?: string;
enableFanoutTimeline?: boolean;
Expand Down

0 comments on commit cd41e5a

Please sign in to comment.