Add support for hCaptcha
This commit is contained in:
@ -145,6 +145,27 @@ export const meta = {
|
||||
}
|
||||
},
|
||||
|
||||
enableHcaptcha: {
|
||||
validator: $.optional.bool,
|
||||
desc: {
|
||||
'ja-JP': 'hCaptchaを使用するか否か'
|
||||
}
|
||||
},
|
||||
|
||||
hcaptchaSiteKey: {
|
||||
validator: $.optional.nullable.str,
|
||||
desc: {
|
||||
'ja-JP': 'hCaptcha site key'
|
||||
}
|
||||
},
|
||||
|
||||
hcaptchaSecretKey: {
|
||||
validator: $.optional.nullable.str,
|
||||
desc: {
|
||||
'ja-JP': 'hCaptcha secret key'
|
||||
}
|
||||
},
|
||||
|
||||
enableRecaptcha: {
|
||||
validator: $.optional.bool,
|
||||
desc: {
|
||||
@ -472,6 +493,18 @@ export default define(meta, async (ps, me) => {
|
||||
set.proxyRemoteFiles = ps.proxyRemoteFiles;
|
||||
}
|
||||
|
||||
if (ps.enableHcaptcha !== undefined) {
|
||||
set.enableHcaptcha = ps.enableHcaptcha;
|
||||
}
|
||||
|
||||
if (ps.hcaptchaSiteKey !== undefined) {
|
||||
set.hcaptchaSiteKey = ps.hcaptchaSiteKey;
|
||||
}
|
||||
|
||||
if (ps.hcaptchaSecretKey !== undefined) {
|
||||
set.hcaptchaSecretKey = ps.hcaptchaSecretKey;
|
||||
}
|
||||
|
||||
if (ps.enableRecaptcha !== undefined) {
|
||||
set.enableRecaptcha = ps.enableRecaptcha;
|
||||
}
|
||||
|
@ -122,6 +122,8 @@ export default define(meta, async (ps, me) => {
|
||||
driveCapacityPerRemoteUserMb: instance.remoteDriveCapacityMb,
|
||||
cacheRemoteFiles: instance.cacheRemoteFiles,
|
||||
proxyRemoteFiles: instance.proxyRemoteFiles,
|
||||
enableHcaptcha: instance.enableHcaptcha,
|
||||
hcaptchaSiteKey: instance.hcaptchaSiteKey,
|
||||
enableRecaptcha: instance.enableRecaptcha,
|
||||
recaptchaSiteKey: instance.recaptchaSiteKey,
|
||||
swPublickey: instance.swPublicKey,
|
||||
@ -149,6 +151,7 @@ export default define(meta, async (ps, me) => {
|
||||
localTimeLine: !instance.disableLocalTimeline,
|
||||
globalTimeLine: !instance.disableGlobalTimeline,
|
||||
elasticsearch: config.elasticsearch ? true : false,
|
||||
hcaptcha: instance.enableHcaptcha,
|
||||
recaptcha: instance.enableRecaptcha,
|
||||
objectStorage: instance.useObjectStorage,
|
||||
twitter: instance.enableTwitterIntegration,
|
||||
@ -164,6 +167,7 @@ export default define(meta, async (ps, me) => {
|
||||
response.pinnedUsers = instance.pinnedUsers;
|
||||
response.hiddenTags = instance.hiddenTags;
|
||||
response.blockedHosts = instance.blockedHosts;
|
||||
response.hcaptchaSecretKey = instance.hcaptchaSecretKey;
|
||||
response.recaptchaSecretKey = instance.recaptchaSecretKey;
|
||||
response.proxyAccountId = instance.proxyAccountId;
|
||||
response.twitterConsumerKey = instance.twitterConsumerKey;
|
||||
|
@ -1,5 +1,6 @@
|
||||
import * as Koa from 'koa';
|
||||
import { fetchMeta } from '../../../misc/fetch-meta';
|
||||
import { verify } from 'hcaptcha';
|
||||
import * as recaptcha from 'recaptcha-promise';
|
||||
import { Users, RegistrationTickets } from '../../../models';
|
||||
import { signup } from '../common/signup';
|
||||
@ -9,8 +10,18 @@ export default async (ctx: Koa.Context) => {
|
||||
|
||||
const instance = await fetchMeta(true);
|
||||
|
||||
// Verify recaptcha
|
||||
// Verify *Captcha
|
||||
// ただしテスト時はこの機構は障害となるため無効にする
|
||||
if (process.env.NODE_ENV !== 'test' && instance.enableHcaptcha && instance.hcaptchaSecretKey) {
|
||||
const success = await verify(instance.hcaptchaSecretKey, body['hcaptcha-response']).then(
|
||||
({ 'error-codes': x }) => !x || !x.length,
|
||||
() => false,
|
||||
);
|
||||
|
||||
if (!success) {
|
||||
ctx.throw(400, 'hcaptcha-failed');
|
||||
}
|
||||
}
|
||||
if (process.env.NODE_ENV !== 'test' && instance.enableRecaptcha && instance.recaptchaSecretKey) {
|
||||
recaptcha.init({
|
||||
secret_key: instance.recaptchaSecretKey
|
||||
|
@ -65,6 +65,7 @@ const nodeinfo2 = async () => {
|
||||
disableRegistration: meta.disableRegistration,
|
||||
disableLocalTimeline: meta.disableLocalTimeline,
|
||||
disableGlobalTimeline: meta.disableGlobalTimeline,
|
||||
enableHcaptcha: meta.enableHcaptcha,
|
||||
enableRecaptcha: meta.enableRecaptcha,
|
||||
maxNoteTextLength: meta.maxNoteTextLength,
|
||||
enableTwitterIntegration: meta.enableTwitterIntegration,
|
||||
|
@ -106,6 +106,9 @@ html
|
||||
tr
|
||||
th Registration
|
||||
td= !meta.disableRegistration ? 'yes' : 'no'
|
||||
tr
|
||||
th hCaptcha enabled
|
||||
td= meta.enableHcaptcha ? 'enabled' : 'disabled'
|
||||
tr
|
||||
th reCAPTCHA enabled
|
||||
td= meta.enableRecaptcha ? 'enabled' : 'disabled'
|
||||
|
Reference in New Issue
Block a user