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

Password confirmation for some actions #1447

Merged
merged 28 commits into from
Nov 18, 2016

Conversation

nickvergessen
Copy link
Member

@nickvergessen nickvergessen commented Sep 19, 2016

when performing certain actions, we want to make sure, that the user is actually the user.
Therefor we require a password confirmation, e.g. when changing the email address.

ToDo

  • Add a message to the confirmation box
  • Submit confirmation with Enter key
  • Clear the box on sending, so the password is not kept around
  • Use on the personal page:
    • Change email
    • Add app password
    • Generate backup codes (2FA)
  • Use on the user management page:
    • Delete group
    • Add group
    • Delete user
    • Add user
    • Change password
    • Change group memberships
    • Change group subadmin
    • Change displayname
    • Change email
    • Change quota
  • Use on the admin page:
  • Fix changing an user email/password from the user management (error is not shown)

@LukasReschke @MorrisJobke

@nickvergessen nickvergessen added 2. developing Work in progress 3. to review Waiting for reviews security labels Sep 19, 2016
@nickvergessen nickvergessen added this to the Nextcloud 11.0 milestone Sep 19, 2016
@nickvergessen nickvergessen force-pushed the password-confirmation-for-some-actions branch from a8ae639 to 875af94 Compare September 19, 2016 14:37
@MorrisJobke
Copy link
Member

@nickvergessen What state is this? 2 or 3?

@MorrisJobke MorrisJobke removed the 3. to review Waiting for reviews label Sep 19, 2016
@nickvergessen
Copy link
Member Author

Both, because @LukasReschke should already have a look at it, while I develop the rest 😛

@MorrisJobke MorrisJobke mentioned this pull request Oct 24, 2016
47 tasks
@nickvergessen nickvergessen force-pushed the password-confirmation-for-some-actions branch from 55b717f to 616e840 Compare October 25, 2016 11:05
@nickvergessen
Copy link
Member Author

@MorrisJobke can you have a look?

Currently when you open the user management, then the settings section and toggle "show storage location" that doesn't work.

For easier testing set down the confirmation time to 10 seconds instead of 30 minutes:

diff --git a/core/js/js.js b/core/js/js.js
index e423b6e..89426cc 100644
--- a/core/js/js.js
+++ b/core/js/js.js
@@ -1536,6 +1536,7 @@ OC.PasswordConfirmation = {

        requiresPasswordConfirmation: function() {
                var timeSinceLogin = moment.now() - nc_lastLogin * 1000;
+               return timeSinceLogin > 10 * 1000; // 30 minutes
                return timeSinceLogin > 30 * 60 * 1000; // 30 minutes
        },

diff --git a/lib/private/AppFramework/Middleware/Security/SecurityMiddleware.php b/lib/private/AppFramework/Middleware/Security/SecurityMiddleware.php
index 981232f..7e385b9 100644
--- a/lib/private/AppFramework/Middleware/Security/SecurityMiddleware.php
+++ b/lib/private/AppFramework/Middleware/Security/SecurityMiddleware.php
@@ -147,7 +147,8 @@ class SecurityMiddleware extends Middleware {

                if ($this->reflector->hasAnnotation('PasswordConfirmationRequired')) {
                        $lastConfirm = (int) $this->session->get('last-password-confirm');
-                       if ($lastConfirm < (time() - 30 * 60 + 15)) { // allow 15 seconds delay
+                       if ($lastConfirm < (time() - 10)) { // allow 15 seconds delay
+                       //if ($lastConfirm < (time() - 30 * 60 + 15)) { // allow 15 seconds delay
                                throw new NotConfirmedException();
                        }
                }
diff --git a/settings/ajax/togglegroups.php b/settings/ajax/togglegroups.php
index b9958be..35ac36c 100644
--- a/settings/ajax/togglegroups.php
+++ b/settings/ajax/togglegroups.php
@@ -29,7 +29,8 @@ OC_JSON::checkSubAdminUser();
 OCP\JSON::callCheck();

 $lastConfirm = (int) \OC::$server->getSession()->get('last-password-confirm');
-if ($lastConfirm < (time() - 30 * 60 + 15)) { // allow 15 seconds delay
+if ($lastConfirm < (time() - 10)) { // allow 15 seconds delay
+//if ($lastConfirm < (time() - 30 * 60 + 15)) { // allow 15 seconds delay
        $l = \OC::$server->getL10N('core');
        OC_JSON::error(array( 'data' => array( 'message' => $l->t('Password confirmation is required'))));
        exit();
diff --git a/settings/ajax/togglesubadmins.php b/settings/ajax/togglesubadmins.php
index 5658a38..eb79ced 100644
--- a/settings/ajax/togglesubadmins.php
+++ b/settings/ajax/togglesubadmins.php
@@ -25,7 +25,8 @@ OC_JSON::checkAdminUser();
 OCP\JSON::callCheck();

 $lastConfirm = (int) \OC::$server->getSession()->get('last-password-confirm');
-if ($lastConfirm < (time() - 30 * 60 + 15)) { // allow 15 seconds delay
+if ($lastConfirm < (time() - 10)) { // allow 15 seconds delay
+//if ($lastConfirm < (time() - 30 * 60 + 15)) { // allow 15 seconds delay
        $l = \OC::$server->getL10N('core');
        OC_JSON::error(array( 'data' => array( 'message' => $l->t('Password confirmation is required'))));
        exit();

$dataLocation = false;
}

$lastConfirmTimestamp = $user->getLastLogin();
$sessionTime = \OC::$server->getSession()->get('last-password-confirm');
Copy link
Member

Choose a reason for hiding this comment

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

This is kinda often used and seems error-prone. Maybe let's add that to OCP\IUser as new method? isSudoMode() : bool or so?

Copy link
Member

Choose a reason for hiding this comment

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

Would introduce a new dependency on ISession in the User class though. Anyhow, I think we should abstract that away in some other class. Also it's own helper class is fine in the OC\Security namespace.

Copy link
Member Author

Choose a reason for hiding this comment

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

Well it's used 3 times and in legacy code (ajax endpoints which don't use controller).
Once the legacy is gone, only the annotation is used, so I think the 3 appearances are fine.

Copy link
Member

Choose a reason for hiding this comment

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

Fair enough

@nickvergessen nickvergessen force-pushed the password-confirmation-for-some-actions branch from 739cbe1 to 4526f3c Compare November 3, 2016 08:59
@nickvergessen
Copy link
Member Author

@MorrisJobke I fail to get the quota and the email thing covered, can you try it?

@MorrisJobke
Copy link
Member

MorrisJobke commented Nov 3, 2016

  • BUG: as an admin I need to enter my password when changing my email address on the personal page (this is not the case for a non-admin)

@LukasReschke
Copy link
Member

LukasReschke commented Nov 3, 2016

BUG: as an admin I need to enter my password when changing my email address on the personal page (this is not the case for a non-admin)

  • BUG: As an normal user I should also have to enter my password 😉

@nickvergessen nickvergessen force-pushed the password-confirmation-for-some-actions branch from 91ba596 to 00da391 Compare November 10, 2016 16:09
@codecov-io
Copy link

codecov-io commented Nov 10, 2016

Current coverage is 57.97% (diff: 13.00%)

Merging #1447 into master will increase coverage by 0.39%

@@             master      #1447   diff @@
==========================================
  Files          1169       1170      +1   
  Lines         70226      71253   +1027   
  Methods        7178       7374    +196   
  Messages          0          0           
  Branches       1205       1237     +32   
==========================================
+ Hits          40433      41309    +876   
- Misses        29793      29944    +151   
  Partials          0          0           

Powered by Codecov. Last update c241539...3ffd9a7

@nickvergessen
Copy link
Member Author

Should be ready to review now, only thing left is that you can't submit with enter, but @ChristophWurst will take care of that soon.

@nickvergessen nickvergessen added 3. to review Waiting for reviews and removed 2. developing Work in progress labels Nov 11, 2016
@rullzer rullzer force-pushed the password-confirmation-for-some-actions branch from 81fb5b7 to 4118be3 Compare November 16, 2016 08:52
@rullzer
Copy link
Member

rullzer commented Nov 16, 2016

  • Submit on enter now works

@jancborchardt
Copy link
Member

Please use the modal we use everywhere else. This doesn’t work on mobile at all, and we don’t need a second implementation to maintain & style. ;)

@@ -22,7 +22,6 @@
.oc-dialog-buttonrow {
display: block;
background: transparent;
position: absolute;
Copy link
Member Author

Choose a reason for hiding this comment

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

@jancborchardt this was required because the password field was not clickable since the button row was overlaying it. Maybe you can have a look at the design a bit.

Copy link
Member

Choose a reason for hiding this comment

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

Eeeh this will mess with other dialogs like the move dialog. 👎

Will need to check it out

@ChristophWurst ChristophWurst removed their assignment Nov 17, 2016
@MorrisJobke
Copy link
Member

@nickvergessen conflicts 🙈

nickvergessen and others added 16 commits November 18, 2016 12:10
Signed-off-by: Joas Schilling <coding@schilljs.com>
Signed-off-by: Joas Schilling <coding@schilljs.com>
Signed-off-by: Joas Schilling <coding@schilljs.com>
Signed-off-by: Morris Jobke <hey@morrisjobke.de>
Signed-off-by: Joas Schilling <coding@schilljs.com>
Signed-off-by: Joas Schilling <coding@schilljs.com>
Signed-off-by: Joas Schilling <coding@schilljs.com>
Signed-off-by: Joas Schilling <coding@schilljs.com>
Signed-off-by: Joas Schilling <coding@schilljs.com>
Signed-off-by: Joas Schilling <coding@schilljs.com>
Signed-off-by: Joas Schilling <coding@schilljs.com>
Signed-off-by: Joas Schilling <coding@schilljs.com>
Signed-off-by: Joas Schilling <coding@schilljs.com>
Signed-off-by: Joas Schilling <coding@schilljs.com>
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Signed-off-by: Joas Schilling <coding@schilljs.com>
@LukasReschke LukasReschke force-pushed the password-confirmation-for-some-actions branch from 7bcea46 to 8d33d76 Compare November 18, 2016 11:12
Signed-off-by: Morris Jobke <hey@morrisjobke.de>
@MorrisJobke MorrisJobke force-pushed the password-confirmation-for-some-actions branch from e3f99b6 to 8ef356a Compare November 18, 2016 12:50
* properly handle user management actions like display name, email or password field change

Signed-off-by: Morris Jobke <hey@morrisjobke.de>
@MorrisJobke
Copy link
Member

Tested and works 👍

@MorrisJobke MorrisJobke added 4. to release Ready to be released and/or waiting for tests to finish and removed 3. to review Waiting for reviews labels Nov 18, 2016
@MorrisJobke MorrisJobke merged commit 332eaec into master Nov 18, 2016
@MorrisJobke MorrisJobke deleted the password-confirmation-for-some-actions branch November 18, 2016 14:42
},

requiresPasswordConfirmation: function() {
var timeSinceLogin = moment.now() - nc_lastLogin * 1000;
return timeSinceLogin > 10 * 1000; // 30 minutes
Copy link
Member

Choose a reason for hiding this comment

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

liar 🙈

FF reports "unreachable code after return statement" on master

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4. to release Ready to be released and/or waiting for tests to finish security
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

7 participants