Skip to content

Commit 883a62e

Browse files
committed
Switch to hCaptcha.
1 parent 7efdf4d commit 883a62e

File tree

4 files changed

+18
-12
lines changed

4 files changed

+18
-12
lines changed

dev/u-wave-dev-server

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const explain = require('explain-error');
88
const announce = require('u-wave-announce');
99
const ytSource = require('u-wave-source-youtube');
1010
const scSource = require('u-wave-source-soundcloud');
11-
const recaptchaTestKeys = require('recaptcha-test-keys');
11+
const hcaptchaTestKeys = require('hcaptcha-test-keys');
1212
const debug = require('debug')('uwave:dev-server');
1313
const dotenv = require('dotenv');
1414

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@
6767
"eslint": "^7.2.0",
6868
"eslint-config-airbnb-base": "^14.2.0",
6969
"eslint-plugin-import": "^2.20.0",
70+
"hcaptcha-test-keys": "^1.0.0",
7071
"mocha": "^8.0.1",
7172
"nodemon": "^2.0.2",
72-
"recaptcha-test-keys": "^1.0.0",
7373
"sinon": "^9.0.0",
7474
"u-wave-announce": "^0.4.0"
7575
},

src/HttpApi.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,17 @@ class UwaveHttpApi extends Router {
104104
}
105105

106106
if (options.recaptcha && !options.recaptcha.secret) {
107-
throw new TypeError('ReCaptcha validation is enabled, but "options.recaptcha.secret" is '
108-
+ 'not set. Please set "options.recaptcha.secret" to your ReCaptcha '
109-
+ 'secret, or disable ReCaptcha validation by setting "options.recaptcha" '
107+
throw new TypeError('hCaptcha validation is enabled, but "options.recaptcha.secret" is '
108+
+ 'not set. Please set "options.recaptcha.secret" to your hCaptcha '
109+
+ 'secret, or disable hCaptcha validation by setting "options.recaptcha" '
110110
+ 'to "false".');
111111
}
112+
if (options.recaptcha && options.recaptcha.secret &&
113+
!options.recaptcha.secret.startsWith('0x')) {
114+
throw new Error('hCaptcha validation is enabled, but "options.recaptcha.secret" does not '
115+
+ 'look like an hCaptcha secret key. Please use the secret listed on '
116+
+ 'https://dashboard.hcaptcha.com/welcome.');
117+
}
112118

113119
if (options.onError != null && typeof options.onError !== 'function') {
114120
throw new TypeError('"options.onError" must be a function.');

src/controllers/authenticate.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -215,15 +215,15 @@ async function getSocketToken(req) {
215215

216216
async function verifyCaptcha(responseString, options) {
217217
if (!options.recaptcha) {
218-
debug('ReCaptcha validation is disabled');
218+
debug('hCaptcha validation is disabled');
219219
return null;
220220
}
221221
if (!responseString) {
222-
throw new Error('ReCaptcha validation failed. Please try again.');
222+
throw new Error('hCaptcha validation failed. Please try again.');
223223
}
224224

225-
debug('recaptcha: sending siteverify request');
226-
const response = await fetch('https://www.google.com/recaptcha/api/siteverify', {
225+
debug('hcaptcha: sending siteverify request');
226+
const response = await fetch('https://www.hcaptcha.com/siteverify', {
227227
method: 'post',
228228
headers: {
229229
'content-type': 'application/x-www-form-urlencoded',
@@ -237,10 +237,10 @@ async function verifyCaptcha(responseString, options) {
237237
const body = await response.json();
238238

239239
if (!body.success) {
240-
debug('recaptcha: validation failure', body);
241-
throw new Error('ReCaptcha validation failed. Please try again.');
240+
debug('hcaptcha: validation failure', body);
241+
throw new Error('hCaptcha validation failed. Please try again.');
242242
} else {
243-
debug('recaptcha: ok');
243+
debug('hcaptcha: ok');
244244
}
245245

246246
return null;

0 commit comments

Comments
 (0)