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

[VYMCA-64] CSV Security Enhancement #68

Merged
merged 9 commits into from
Jul 28, 2020
Merged

[VYMCA-64] CSV Security Enhancement #68

merged 9 commits into from
Jul 28, 2020

Conversation

hamrant
Copy link

@hamrant hamrant commented Jul 24, 2020

User story:

As a Virtual Y site owner, I want users to validate their email address before accessing Virtual Y, so that I can ensure only my real members are visiting my module/website.

Steps fo review:

  • Login as admin
  • Go to /admin/openy/virtual-ymca/gc-auth-settings
  • Set Custom provider as active
  • Edit Custom provider
  • Check that you can see new section in settings "Email verification"

Screenshot from 2020-07-24 18-04-59

  • Enable Email verification and save settings
  • Improvements in new commits - users list

screenshot-rose openy docksal-2020 07 27-16_23_14

  • Click on the button and check that you can see existing virtual Y users with basic information and filters

Screenshot from 2020-07-27 16-24-12

  • Go to the front page and try to login to the application with johndoe@test.com email
  • Check that you see a message from settings "We have sent a verification link to the email address you provided. Please open this link and activate your account. If you do not receive an email, please try again or contact us at XXX-XXX-XXXX to ensure we have the correct email on file for your membership."

Screenshot from 2020-07-24 18-07-38

Screenshot from 2020-07-24 17-49-32

  • Click on this link
  • You should see the loading animation and be authenticated after this
  • Logout
  • Try to login with the same email - johndoe@test.com
  • Check that now you can do this without email verification
  • Copy the link from an email and change user id or hash - check that you will see an error

Screenshot from 2020-07-24 18-17-47

  • Go to /admin/openy/virtual-ymca/gc-auth-settings/provider/custom
  • Change text in settings and test this on new user email - adamk@verizon.net
  • Set link life time 1h, test on new email and check link after 1h
  • Disable Email verification in settings and check that you can log in without email verification (you can test this on nelson@gmail.com)

Created test users emails:

@fivejars fivejars deleted a comment from fjbot Jul 27, 2020
@fivejars fivejars deleted a comment from fjbot Jul 27, 2020
@fivejars fivejars deleted a comment from fjbot Jul 27, 2020
@fivejars fivejars deleted a comment from fjbot Jul 27, 2020
@@ -1,2 +1,7 @@
enable_recaptcha: 1
enable_recaptcha: 0
Copy link

Choose a reason for hiding this comment

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

are we going to disable captcha for current sites via hood_update_N?

Copy link
Author

Choose a reason for hiding this comment

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

In this case ReCaptcha disabled for builds, without sitekey it not works

Copy link

Choose a reason for hiding this comment

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

So users would need to enable it manually after installation, right?
I guess instead of changing defaults to 'no captcha' it's better to tune build system to disable captcha via config set . Defaults should be production ready, not build ready

Copy link
Author

Choose a reason for hiding this comment

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

I agree, reverted this to the previous state. By default on builds we have dummy plugin, so I think no need to tune the build system now.

AndreyMaximov
AndreyMaximov previously approved these changes Jul 27, 2020
Copy link

@podarok podarok left a comment

Choose a reason for hiding this comment

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

Hopefully small things


// Set proper permissions to access the new endpoint.
openy_gc_auth_custom_install();
Copy link

Choose a reason for hiding this comment

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

let's avoid of using hook_install
Imaging we'd be changing hook install in the future and somebody does upgrade of his site by running this hook_update_N
This could cause unexpected upgrade path issues
Let's just use some custom function or duplicate a code, which is fine in hook_update_N

Copy link
Author

Choose a reason for hiding this comment

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

Fixed

@@ -24,6 +24,11 @@ public function defaultConfiguration():array {
return [
'enable_recaptcha' => TRUE,
'api_endpoint' => '/openy-gc-auth/provider/custom/login',
'enable_email_verification' => TRUE,
'email_verification_api_endpoint' => '/openy-gc-auth/provider/custom/login-by-link',
'email_verification_link_life_time' => 14400,
Copy link

Choose a reason for hiding this comment

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

class const? - a must
config value with a form? - an option for future

Copy link
Author

Choose a reason for hiding this comment

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

Fixed

$this->configuration['enable_email_verification'] = $form_state->getValue('enable_email_verification');
$this->configuration['email_verification_api_endpoint'] = $form_state->getValue('email_verification_api_endpoint');
$this->configuration['email_verification_link_life_time'] = $form_state->getValue('email_verification_link_life_time');
// TODO: check that text_format works on submit.
Copy link

Choose a reason for hiding this comment

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

checked?
Is Paige aware and is it in project backlog?

Copy link
Author

Choose a reason for hiding this comment

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

Fixed

if (!$resp->isSuccess()) {
return $this->errorResponse($this->t('ReCaptcha token invalid.'), 400);
$validation_result = $this->validateRecaptcha($content, $request);
if ($validation_result instanceof ModifiedResourceResponse) {
Copy link

Choose a reason for hiding this comment

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

what happens if not?
Any error handling in UI?

Copy link
Author

Choose a reason for hiding this comment

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

validation_result is instanceof ModifiedResourceResponse only in case of error, so we return error response here.

if ($provider_config->get('enable_email_verification')) {
if (!$user->isActive()) {
$verification_result = $this->sendEmailVerification($user, $content, $request, $provider_config);
if ($verification_result instanceof ModifiedResourceResponse) {
Copy link

Choose a reason for hiding this comment

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

same

Copy link
Author

Choose a reason for hiding this comment

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

See answer above


$config = $this->configFactory->get('recaptcha.settings');
$recaptcha_secret_key = $config->get('secret_key');
$recaptcha = new ReCaptcha($recaptcha_secret_key, new Drupal8Post());
Copy link

Choose a reason for hiding this comment

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

looks like DI opportunity, can we?

Copy link
Author

Choose a reason for hiding this comment

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

there no any services in reCaptcha module, this code was reused from recaptcha_captcha_validation

/**
 * CAPTCHA Callback; Validates the reCAPTCHA code.
 */
function recaptcha_captcha_validation($solution, $response, $element, $form_state) {
  $config = \Drupal::config('recaptcha.settings');
  $recaptcha_secret_key = $config->get('secret_key');
  if (empty($_POST['g-recaptcha-response']) || empty($recaptcha_secret_key)) {
    return FALSE;
  }
  $recaptcha = new ReCaptcha($recaptcha_secret_key, new Drupal8Post());
  if ($config->get('verify_hostname')) {
    $recaptcha->setExpectedHostname($_SERVER['SERVER_NAME']);
  }

Maybe we can improve this later, I would prefer to leave it as is if it's not very urgent.

@anpolimus
Copy link

Code is ok.
Functionality test.
We are able to merge.

anpolimus
anpolimus previously approved these changes Jul 27, 2020
@hamrant hamrant requested a review from AndreyMaximov July 28, 2020 07:45
@anpolimus anpolimus merged commit fb89a18 into master Jul 28, 2020
@hamrant hamrant deleted the VYMCA-64 branch July 28, 2020 09:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants