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
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
d75e35b
Introduce the UI for password confirmation
nickvergessen Sep 19, 2016
827b6a6
Introduce PasswordConfirmRequired annotation
nickvergessen Sep 19, 2016
28ddf3a
Require password confirmation for changing the email
nickvergessen Sep 19, 2016
a0d6c65
Allow to check it via the API
nickvergessen Sep 19, 2016
86aa619
Require confirmation when generating backup codes
nickvergessen Sep 19, 2016
68fa1e5
Require password confirmation for app password
nickvergessen Sep 19, 2016
6c3f0fd
Fix error message displaying
nickvergessen Sep 19, 2016
cc33f86
Make sure it is a function
nickvergessen Sep 19, 2016
62855c0
Require confirmation when changing the email settings
nickvergessen Sep 19, 2016
145da71
Require confirmation for app config changes
nickvergessen Oct 25, 2016
410e0fc
Require password confirmation when changing workflow rules
nickvergessen Oct 25, 2016
2fd2e45
Require password confirmation for user management
nickvergessen Oct 25, 2016
47f9574
Hide and show after updating
nickvergessen Oct 25, 2016
71c4edf
use proper method call for _.bind()
MorrisJobke Oct 25, 2016
3dc3887
More fixes
nickvergessen Oct 25, 2016
922f51e
Update class map
nickvergessen Nov 2, 2016
b2d9c20
Fix unit tests
nickvergessen Nov 2, 2016
a7feb91
Confirm on create/delete group
nickvergessen Nov 3, 2016
309b21f
Require confirmation to change the displayname
nickvergessen Nov 3, 2016
05df523
Empty the password field on submission of the form
nickvergessen Nov 10, 2016
a53c313
Require password confirmation to change the Quota
nickvergessen Nov 10, 2016
02ea134
Fix error displaying on email and add confirmation
nickvergessen Nov 11, 2016
bb7787a
Add the 15 seconds to the window, instead of removing
nickvergessen Nov 11, 2016
80abb69
Show a little explanation above the input field
nickvergessen Nov 11, 2016
e80d3c2
Submit on enter
rullzer Nov 16, 2016
8d33d76
Use the existing prompt
nickvergessen Nov 17, 2016
8ef356a
fix displayname
MorrisJobke Nov 18, 2016
3ffd9a7
Fix user management callbacks
MorrisJobke Nov 18, 2016
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
5 changes: 5 additions & 0 deletions apps/twofactor_backupcodes/js/settingsview.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@
}.bind(this));
},
_onGenerateBackupCodes: function () {
if (OC.PasswordConfirmation.requiresPasswordConfirmation()) {
OC.PasswordConfirmation.requirePasswordConfirmation(_.bind(this._onGenerateBackupCodes, this));
return;
}

// Hide old codes
this._enabled = false;
this.render();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,17 @@ public function state() {

/**
* @NoAdminRequired
* @PasswordConfirmationRequired
*
* @return JSONResponse
*/
public function createCodes() {
$user = $this->userSession->getUser();
$codes = $this->storage->createCodes($user);
return [
'codes' => $codes,
'state' => $this->storage->getBackupCodesState($user),
];
return new JSONResponse([
'codes' => $codes,
'state' => $this->storage->getBackupCodesState($user),
]);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

use OCA\TwoFactorBackupCodes\Controller\SettingsController;
use OCA\TwoFactorBackupCodes\Service\BackupCodeStorage;
use OCP\AppFramework\Http\JSONResponse;
use OCP\IRequest;
use OCP\IUser;
use OCP\IUserSession;
Expand Down Expand Up @@ -89,7 +90,9 @@ public function testCreateCodes() {
'codes' => $codes,
'state' => 'state',
];
$this->assertEquals($expected, $this->controller->createCodes());
$response = $this->controller->createCodes();
$this->assertInstanceOf(JSONResponse::class, $response);
$this->assertEquals($expected, $response->getData());
}

}
10 changes: 10 additions & 0 deletions apps/workflowengine/js/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,11 @@
}
},
delete: function() {
if (OC.PasswordConfirmation.requiresPasswordConfirmation()) {
OC.PasswordConfirmation.requirePasswordConfirmation(_.bind(this.delete, this));
return;
}

this.model.destroy();
this.remove();
},
Expand All @@ -173,6 +178,11 @@
this.render();
},
save: function() {
if (OC.PasswordConfirmation.requiresPasswordConfirmation()) {
OC.PasswordConfirmation.requirePasswordConfirmation(_.bind(this.save, this));
return;
}

var success = function(model, response, options) {
this.saving = false;
this.originalModel = JSON.parse(JSON.stringify(this.model));
Expand Down
6 changes: 6 additions & 0 deletions apps/workflowengine/lib/Controller/FlowOperations.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ public function getOperations($class) {
}

/**
* @PasswordConfirmationRequired
*
* @param string $class
* @param string $name
* @param array[] $checks
Expand All @@ -75,6 +77,8 @@ public function addOperation($class, $name, $checks, $operation) {
}

/**
* @PasswordConfirmationRequired
*
* @param int $id
* @param string $name
* @param array[] $checks
Expand All @@ -92,6 +96,8 @@ public function updateOperation($id, $name, $checks, $operation) {
}

/**
* @PasswordConfirmationRequired
*
* @param int $id
* @return JSONResponse
*/
Expand Down
37 changes: 37 additions & 0 deletions core/Controller/LoginController.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php
/**
* @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com>
* @copyright Copyright (c) 2016, ownCloud, Inc.
*
* @author Christoph Wurst <christoph@owncloud.com>
Expand Down Expand Up @@ -31,6 +32,8 @@
use OC_App;
use OC_Util;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\Http\RedirectResponse;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\Authentication\TwoFactorAuth\IProvider;
Expand Down Expand Up @@ -242,6 +245,8 @@ public function tryLogin($user, $password, $redirect_url, $remember_login = fals
// User has successfully logged in, now remove the password reset link, when it is available
$this->config->deleteUserValue($loginResult->getUID(), 'core', 'lostpassword');

$this->session->set('last-password-confirm', $loginResult->getLastLogin());

if ($this->twoFactorManager->isTwoFactorAuthenticated($loginResult)) {
$this->twoFactorManager->prepareTwoFactorLogin($loginResult, $remember_login);

Expand Down Expand Up @@ -273,4 +278,36 @@ public function tryLogin($user, $password, $redirect_url, $remember_login = fals
return $this->generateRedirect($redirect_url);
}

/**
* @NoAdminRequired
* @UseSession
*
* @license GNU AGPL version 3 or any later version
*
* @param string $password
* @return DataResponse
*/
public function confirmPassword($password) {
$currentDelay = $this->throttler->getDelay($this->request->getRemoteAddress());
$this->throttler->sleepDelay($this->request->getRemoteAddress());

$user = $this->userSession->getUser();
if (!$user instanceof IUser) {
return new DataResponse([], Http::STATUS_UNAUTHORIZED);
}

$loginResult = $this->userManager->checkPassword($user->getUID(), $password);
if ($loginResult === false) {
$this->throttler->registerAttempt('sudo', $this->request->getRemoteAddress(), ['user' => $user->getUID()]);
if ($currentDelay === 0) {
$this->throttler->sleepDelay($this->request->getRemoteAddress());
}

return new DataResponse([], Http::STATUS_FORBIDDEN);
}

$confirmTimestamp = time();
$this->session->set('last-password-confirm', $confirmTimestamp);
return new DataResponse(['lastLogin' => $confirmTimestamp], Http::STATUS_OK);
}
}
10 changes: 7 additions & 3 deletions core/Controller/OCJSController.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
use OCP\IGroupManager;
use OCP\IL10N;
use OCP\IRequest;
use OCP\ISession;
use OCP\IURLGenerator;
use OCP\IUserSession;

Expand All @@ -48,7 +49,8 @@ class OCJSController extends Controller {
* @param IL10N $l
* @param \OC_Defaults $defaults
* @param IAppManager $appManager
* @param IUserSession $session
* @param ISession $session
* @param IUserSession $userSession
* @param IConfig $config
* @param IGroupManager $groupManager
* @param IniGetWrapper $iniWrapper
Expand All @@ -59,7 +61,8 @@ public function __construct($appName,
IL10N $l,
\OC_Defaults $defaults,
IAppManager $appManager,
IUserSession $session,
ISession $session,
IUserSession $userSession,
IConfig $config,
IGroupManager $groupManager,
IniGetWrapper $iniWrapper,
Expand All @@ -70,7 +73,8 @@ public function __construct($appName,
$l,
$defaults,
$appManager,
$session->getUser(),
$session,
$userSession->getUser(),
$config,
$groupManager,
$iniWrapper,
Expand Down
1 change: 0 additions & 1 deletion core/css/jquery.ocdialog.css
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
.oc-dialog-buttonrow {
display: block;
background: transparent;
position: absolute;
right: 0;
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

bottom: 0;
padding: 10px;
Expand Down
72 changes: 72 additions & 0 deletions core/js/js.js
Original file line number Diff line number Diff line change
Expand Up @@ -1512,8 +1512,80 @@ function initCore() {
$(this).text(OC.Util.relativeModifiedDate(parseInt($(this).attr('data-timestamp'), 10)));
});
}, 30 * 1000);

OC.PasswordConfirmation.init();
}

OC.PasswordConfirmation = {
callback: null,

init: function() {
$('.password-confirm-required').on('click', _.bind(this.requirePasswordConfirmation, this));
},

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

return timeSinceLogin > 30 * 60 * 1000; // 30 minutes
},

/**
* @param {function} callback
*/
requirePasswordConfirmation: function(callback) {
var self = this;

if (this.requiresPasswordConfirmation()) {
OC.dialogs.prompt(
t(
'core',
'This action requires you to confirm your password'
),
t('core','Authentication required'),
function (result, password) {
if (result && password !== '') {
self._confirmPassword(password);
}
},
true,
t('core','Password'),
true
).then(function() {
var $dialog = $('.oc-dialog:visible');
$dialog.find('.ui-icon').remove();

var $buttons = $dialog.find('button');
$buttons.eq(0).text(t('core', 'Cancel'));
$buttons.eq(1).text(t('core', 'Confirm'));
});
}

this.callback = callback;
},

_confirmPassword: function(password) {
var self = this;

$.ajax({
url: OC.generateUrl('/login/confirm'),
data: {
password: password
},
type: 'POST',
success: function(response) {
nc_lastLogin = response.lastLogin;

if (_.isFunction(self.callback)) {
self.callback();
}
},
error: function() {
OC.Notification.showTemporary(t('core', 'Failed to authenticate, try again'));
}
});
}
};

$(document).ready(initCore);

/**
Expand Down
4 changes: 4 additions & 0 deletions core/js/public/appconfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ OCP.AppConfig = {
* @internal
*/
_call: function(method, endpoint, options) {
if ((method === 'post' || method === 'delete') && OC.PasswordConfirmation.requiresPasswordConfirmation()) {
OC.PasswordConfirmation.requirePasswordConfirmation(_.bind(this._call, this, method, endpoint, options));
return;
}

$.ajax({
type: method.toUpperCase(),
Expand Down
1 change: 1 addition & 0 deletions core/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
['name' => 'avatar#getTmpAvatar', 'url' => '/avatar/tmp', 'verb' => 'GET'],
['name' => 'avatar#postAvatar', 'url' => '/avatar/', 'verb' => 'POST'],
['name' => 'login#tryLogin', 'url' => '/login', 'verb' => 'POST'],
['name' => 'login#confirmPassword', 'url' => '/login/confirm', 'verb' => 'POST'],
['name' => 'login#showLoginForm', 'url' => '/login', 'verb' => 'GET'],
['name' => 'login#logout', 'url' => '/logout', 'verb' => 'GET'],
['name' => 'TwoFactorChallenge#selectChallenge', 'url' => '/login/selectchallenge', 'verb' => 'GET'],
Expand Down
8 changes: 8 additions & 0 deletions core/templates/layout.user.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,14 @@
</div>
</div></nav>

<div id="sudo-login-background" class="hidden"></div>
<div id="sudo-login-form" class="hidden">
<?php p($l->t('This action requires you to confirm your password:')); ?><br>
<input type="password" class="question" autocomplete="off" name="question" value=" <?php /* Hack against firefox ignoring autocomplete="off" */ ?>"
placeholder="<?php p($l->t('Confirm your password')); ?>" />
<input class="confirm icon-confirm" title="<?php p($l->t('Confirm')); ?>" value="" type="submit">
</div>

<div id="content-wrapper">
<div id="content" class="app-<?php p($_['appid']) ?>" role="main">
<?php print_unescaped($_['content']); ?>
Expand Down
1 change: 1 addition & 0 deletions lib/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@
'OC\\AppFramework\\Middleware\\Security\\Exceptions\\AppNotEnabledException' => $baseDir . '/lib/private/AppFramework/Middleware/Security/Exceptions/AppNotEnabledException.php',
'OC\\AppFramework\\Middleware\\Security\\Exceptions\\CrossSiteRequestForgeryException' => $baseDir . '/lib/private/AppFramework/Middleware/Security/Exceptions/CrossSiteRequestForgeryException.php',
'OC\\AppFramework\\Middleware\\Security\\Exceptions\\NotAdminException' => $baseDir . '/lib/private/AppFramework/Middleware/Security/Exceptions/NotAdminException.php',
'OC\\AppFramework\\Middleware\\Security\\Exceptions\\NotConfirmedException' => $baseDir . '/lib/private/AppFramework/Middleware/Security/Exceptions/NotConfirmedException.php',
'OC\\AppFramework\\Middleware\\Security\\Exceptions\\NotLoggedInException' => $baseDir . '/lib/private/AppFramework/Middleware/Security/Exceptions/NotLoggedInException.php',
'OC\\AppFramework\\Middleware\\Security\\Exceptions\\SecurityException' => $baseDir . '/lib/private/AppFramework/Middleware/Security/Exceptions/SecurityException.php',
'OC\\AppFramework\\Middleware\\Security\\Exceptions\\StrictCookieMissingException' => $baseDir . '/lib/private/AppFramework/Middleware/Security/Exceptions/StrictCookieMissingException.php',
Expand Down
1 change: 1 addition & 0 deletions lib/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
'OC\\AppFramework\\Middleware\\Security\\Exceptions\\AppNotEnabledException' => __DIR__ . '/../../..' . '/lib/private/AppFramework/Middleware/Security/Exceptions/AppNotEnabledException.php',
'OC\\AppFramework\\Middleware\\Security\\Exceptions\\CrossSiteRequestForgeryException' => __DIR__ . '/../../..' . '/lib/private/AppFramework/Middleware/Security/Exceptions/CrossSiteRequestForgeryException.php',
'OC\\AppFramework\\Middleware\\Security\\Exceptions\\NotAdminException' => __DIR__ . '/../../..' . '/lib/private/AppFramework/Middleware/Security/Exceptions/NotAdminException.php',
'OC\\AppFramework\\Middleware\\Security\\Exceptions\\NotConfirmedException' => __DIR__ . '/../../..' . '/lib/private/AppFramework/Middleware/Security/Exceptions/NotConfirmedException.php',
'OC\\AppFramework\\Middleware\\Security\\Exceptions\\NotLoggedInException' => __DIR__ . '/../../..' . '/lib/private/AppFramework/Middleware/Security/Exceptions/NotLoggedInException.php',
'OC\\AppFramework\\Middleware\\Security\\Exceptions\\SecurityException' => __DIR__ . '/../../..' . '/lib/private/AppFramework/Middleware/Security/Exceptions/SecurityException.php',
'OC\\AppFramework\\Middleware\\Security\\Exceptions\\StrictCookieMissingException' => __DIR__ . '/../../..' . '/lib/private/AppFramework/Middleware/Security/Exceptions/StrictCookieMissingException.php',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ public function __construct($appName, $urlParams = array()){
$app->getServer()->getNavigationManager(),
$app->getServer()->getURLGenerator(),
$app->getServer()->getLogger(),
$app->getServer()->getSession(),
$c['AppName'],
$app->isLoggedIn(),
$app->isAdminUser(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

/**
* @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

namespace OC\AppFramework\Middleware\Security\Exceptions;

use OCP\AppFramework\Http;

/**
* Class NotConfirmedException is thrown when a resource has been requested by a
* user that has not confirmed their password in the last 30 minutes.
*
* @package OC\AppFramework\Middleware\Security\Exceptions
*/
class NotConfirmedException extends SecurityException {
public function __construct() {
parent::__construct('Password confirmation is required', Http::STATUS_FORBIDDEN);
}
}
Loading