Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to hCaptcha. #379

Draft
wants to merge 2 commits into
base: default
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dev/u-wave-dev-server
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const explain = require('explain-error');
const announce = require('u-wave-announce');
const ytSource = require('u-wave-source-youtube');
const scSource = require('u-wave-source-soundcloud');
const recaptchaTestKeys = require('recaptcha-test-keys');
const hcaptchaTestKeys = require('hcaptcha-test-keys');
const debug = require('debug')('uwave:dev-server');
const dotenv = require('dotenv');

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@
"eslint": "^7.2.0",
"eslint-config-airbnb-base": "^14.2.0",
"eslint-plugin-import": "^2.20.0",
"hcaptcha-test-keys": "^1.0.0",
"mocha": "^8.0.1",
"nodemon": "^2.0.2",
"recaptcha-test-keys": "^1.0.0",
"sinon": "^9.0.0",
"u-wave-announce": "^0.4.0"
},
Expand Down
12 changes: 9 additions & 3 deletions src/HttpApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,17 @@ class UwaveHttpApi extends Router {
}

if (options.recaptcha && !options.recaptcha.secret) {
throw new TypeError('ReCaptcha validation is enabled, but "options.recaptcha.secret" is '
+ 'not set. Please set "options.recaptcha.secret" to your ReCaptcha '
+ 'secret, or disable ReCaptcha validation by setting "options.recaptcha" '
throw new TypeError('hCaptcha validation is enabled, but "options.recaptcha.secret" is '
+ 'not set. Please set "options.recaptcha.secret" to your hCaptcha '
+ 'secret, or disable hCaptcha validation by setting "options.recaptcha" '
+ 'to "false".');
}
if (options.recaptcha && options.recaptcha.secret
&& !options.recaptcha.secret.startsWith('0x')) {
throw new Error('hCaptcha validation is enabled, but "options.recaptcha.secret" does not '
+ 'look like an hCaptcha secret key. Please use the secret listed on '
+ 'https://dashboard.hcaptcha.com/welcome.');
}

if (options.onError != null && typeof options.onError !== 'function') {
throw new TypeError('"options.onError" must be a function.');
Expand Down
14 changes: 7 additions & 7 deletions src/controllers/authenticate.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,15 +215,15 @@ async function getSocketToken(req) {

async function verifyCaptcha(responseString, options) {
if (!options.recaptcha) {
debug('ReCaptcha validation is disabled');
debug('hCaptcha validation is disabled');
return null;
}
if (!responseString) {
throw new Error('ReCaptcha validation failed. Please try again.');
throw new Error('hCaptcha validation failed. Please try again.');
}

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

if (!body.success) {
debug('recaptcha: validation failure', body);
throw new Error('ReCaptcha validation failed. Please try again.');
debug('hcaptcha: validation failure', body);
throw new Error('hCaptcha validation failed. Please try again.');
} else {
debug('recaptcha: ok');
debug('hcaptcha: ok');
}

return null;
Expand Down