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

[Login] Enable optional reCAPTCHA on Request Account page #6344

Merged
merged 7 commits into from
Apr 21, 2020
Merged

[Login] Enable optional reCAPTCHA on Request Account page #6344

merged 7 commits into from
Apr 21, 2020

Conversation

johnsaigle
Copy link
Contributor

@johnsaigle johnsaigle commented Apr 8, 2020

Brief summary of changes

Adds a reCAPTCHA validation feature to the existing request account page.

reCAPTCHA is only active when a private key has been configured on the server. Otherwise it will be ignored.

This will probably need to be reworked alongside #5828 in the future.

  • Have you updated related documentation?

Screen Shot 2020-04-08 at 16 42 24

Testing instructions (if applicable)

  1. Enable reCAPTCHA by following the Google reCAPTCHA instructions for version 2.
  2. Update the config settings in LORIS as described in the new wiki document
  3. Try requesting an account with and without submitting a reCAPTCHA and make sure it seems to work well.

Link(s) to related issue(s)

@johnsaigle johnsaigle added Feature PR or issue introducing/requiring at least one new feature Documentation PR or issue introducing/requiring modifications to the code documentation (test plans, wikis, docs) Security PR patches a vulnerability, makes resource access changes, or updates dependencies 23.0.0-testing labels Apr 8, 2020
@johnsaigle johnsaigle requested a review from ridz1208 April 8, 2020 20:49
$this->tpl_data['captcha_key'] = \NDB_Factory::singleton()
->config()
->getSetting('reCAPTCHAPublic');
$this->tpl_data['nonce'] = base64_encode(openssl_random_pseudo_bytes(16));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is required as a security measure to avoid making our Content Security Policy weaker. Detailed discussion here. google/recaptcha#107

$_SERVER['REMOTE_ADDR']
);
$success = $resp->isSuccess();
// FIXME This leverages the error handling for the "site" text field.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't figure out how to get an error code to show up under the reCAPTCHA part so this is a bit hack-y but is functioning. I'm open to suggestions

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@johnsaigle maybe $resp returns null if error? I'm wondering what happens when an error is thrown.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh sorry I didn't add the new file to Git. 😅

@@ -211,18 +242,6 @@ class RequestAccount extends \NDB_Form
}
}

// Verify reCAPTCHA
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is moved to _validate instead of _process. It doesn't make sense to insert a user into the DB if they failed the reCAPTCHA.

<b class="text-danger">{$error_message['captcha']}</b>
</span>
</div>
<script src="https://www.google.com/recaptcha/api.js?render={$captcha_key}&onload=onloadCallback nonce={$nonce}"></script>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be refactored in a more generic way so that we can use reCAPTCHA in other places if we want to. That may be out of scope for now, plus I'm not really sure the best approach. Open for suggestions.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing a new react component will be made. 🙂

3. Verify that verification code is enforced (if and only if re-captcha has been activated by the project)
4. Verify that new verification code loads on every refresh of the page
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This refers to a very very old custom captcha that we deleted because it was insecure. #3645

@maltheism
Copy link
Member

maltheism commented Apr 8, 2020

Hey @johnsaigle, I'll be happy to test this PR and I see it's set as work in progress. Let me know when I should manually test it.

@johnsaigle
Copy link
Contributor Author

You can manually test it now. Thanks!

It's in draft mode only because I have a couple of hacks in the code that could be done better.

It's totally functional.

modules/login/php/requestaccount.class.inc Outdated Show resolved Hide resolved
modules/login/php/requestaccount.class.inc Outdated Show resolved Hide resolved
modules/login/php/requestaccount.class.inc Outdated Show resolved Hide resolved
@johnsaigle johnsaigle marked this pull request as ready for review April 8, 2020 21:05
@maltheism
Copy link
Member

@johnsaigle probably good to update somewhere that we're using v3 of reCAPTCHA.

@maltheism
Copy link
Member

@johnsaigle frontend is giving me this output in console:
Refused to frame 'https://www.google.com/' because it violates the following Content Security Policy directive: "default-src 'self'". Note that 'frame-src' was not explicitly set, so 'default-src' is used as a fallback.
The reCAPTCHA window is greyed out because of it. I think the nonce has to be included in the content-security-policy header of the NDB_Client.class.inc? I'm unsure though.

@johnsaigle
Copy link
Contributor Author

johnsaigle commented Apr 14, 2020

@maltheism

Update the config settings in LORIS as described in the new wiki document

Did you do this step?

You need to change the CSP. I described how in the wiki document in this PR.

Also this is using v2, not v3. I couldn't get v3 to work. This is mentioned in that document as well.

@johnsaigle johnsaigle added the Needs Code Formatting PR requires formatting fixes to meet our coding standards (PHPCS, phan, etc.) label Apr 14, 2020
@maltheism
Copy link
Member

@johnsaigle I'm not seeing the wiki readme. I was using a v3 key so I'll need to fix that as well.

corresponding values from your Google reCAPTCHA admin account.
This can also be configured via the Configuration module by modifying the values found in the "API Keys" heading.

* `CSPAdditionalHeaders` should include "frame-src www.google.com;" in order
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maltheism These are the instructions you need. Sorry for the confusion

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@johnsaigle maybe not for this PR but I'm a little confused why the way of going about this is by editing the database to include frame-src www.google.com;. I almost think there should just be a check in the code to see if reCAPTCHAPRIVATE has been added to the config.xml or admin configuration and if so add the frame-src www.google.com; to the content security policy. I would think that would be best for having it be hands free for users.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that would probably be a good enhancement.

@maltheism maltheism added the Passed Manual Tests PR has undergone proper testing by at least one peer label Apr 14, 2020
@maltheism
Copy link
Member

Passed manual testing for me.

@ridz1208 ridz1208 linked an issue Apr 15, 2020 that may be closed by this pull request
@johnsaigle johnsaigle removed the Needs Code Formatting PR requires formatting fixes to meet our coding standards (PHPCS, phan, etc.) label Apr 21, 2020
@johnsaigle johnsaigle requested a review from driusan April 21, 2020 17:19
modules/login/php/requestaccount.class.inc Outdated Show resolved Hide resolved
modules/login/php/requestaccount.class.inc Outdated Show resolved Hide resolved
modules/login/templates/form_requestaccount.tpl Outdated Show resolved Hide resolved
Co-Authored-By: Dave MacFarlane <driusan@gmail.com>
@johnsaigle johnsaigle requested a review from driusan April 21, 2020 18:26
mkdocs.yml Outdated
@@ -32,4 +32,5 @@ nav:
- 'SQL Dictionary': 'wiki/99 - Developers/SQL Dictionary.md'
- 'Automated Testing': 'wiki/99 - Developers/Automated Testing.md'
- 'Style Guide (for help text)': 'HelpStyleGuide.md'
- 'Enabling reCAPTCHA': 'wiki/99 - Developers/reCAPTCHA.md'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this in the developers section? Shouldn't it be in the installation and configuration section? It's more for prod than devs..

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah good point

modules/login/templates/form_requestaccount.tpl Outdated Show resolved Hide resolved
@driusan driusan merged commit cf7a8aa into aces:23.0-release Apr 21, 2020
@ridz1208 ridz1208 added this to the 23.0.0 milestone Apr 27, 2020
HenriRabalais pushed a commit to HenriRabalais/Loris that referenced this pull request May 27, 2020
Adds a reCAPTCHA validation feature to the existing request account page.

reCAPTCHA is only active when a private key has been configured on the server. Otherwise it will be ignored.
spell00 pushed a commit to spell00/Loris that referenced this pull request Jun 2, 2020
Adds a reCAPTCHA validation feature to the existing request account page.

reCAPTCHA is only active when a private key has been configured on the server. Otherwise it will be ignored.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation PR or issue introducing/requiring modifications to the code documentation (test plans, wikis, docs) Feature PR or issue introducing/requiring at least one new feature Passed Manual Tests PR has undergone proper testing by at least one peer Security PR patches a vulnerability, makes resource access changes, or updates dependencies
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[login] Recaptcha not displaying
4 participants