Skip to content

Commit

Permalink
Merge pull request #353 from creative-commoners/pulls/3.0/subsites-mi…
Browse files Browse the repository at this point in the history
…n-version

FIX Prevent incompatible versions of Subsites from installing alongside MFA 3.0
  • Loading branch information
NightJar authored Sep 11, 2019
2 parents 92db931 + c767721 commit 19bbfef
Show file tree
Hide file tree
Showing 39 changed files with 134 additions and 46 deletions.
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
"silverstripe/reports": "^3.7",
"squizlabs/php_codesniffer": "^3.0"
},
"conflict": {
"silverstripe/subsites": "<1.4.2"
},
"suggest": {
"silverstripe/totp-authenticator": "Adds a method to authenticate with you phone using a time-based one-time password.",
"silverstripe/webauthn-authenticator": "Adds a method to authenticate with security keys or built-in platform authenticators."
Expand Down
26 changes: 19 additions & 7 deletions src/Authenticator/LoginForm.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);

namespace SilverStripe\MFA\Authenticator;

Expand Down Expand Up @@ -179,7 +181,9 @@ public function startRegistration(): HTTPResponse
$sessionMember = $store ? $store->getMember() : null;
$loggedInMember = Member::currentUser();

if (($loggedInMember === null && $sessionMember === null)
if (
($loggedInMember === null
&& $sessionMember === null)
|| !$this->getSudoModeService()->check($this->controller->getSession())
) {
return $this->jsonResponse(
Expand Down Expand Up @@ -242,7 +246,9 @@ public function finishRegistration(): HTTPResponse
$sessionMember = $store ? $store->getMember() : null;
$loggedInMember = Member::currentUser();

if (($loggedInMember === null && $sessionMember === null)
if (
($loggedInMember === null
&& $sessionMember === null)
|| !$this->getSudoModeService()->check($this->controller->getSession() ?: new Session([]))
) {
return $this->jsonResponse(
Expand Down Expand Up @@ -275,7 +281,9 @@ public function finishRegistration(): HTTPResponse
// required to log in though. The "mustLogin" flag is set at the beginning of the MFA process if they have at
// least one method registered. They should always do that first. In that case we should assert
// "isLoginComplete"
if ((!$mustLogin || $this->isVerificationComplete($store))
if (
(!$mustLogin
|| $this->isVerificationComplete($store))
&& $enforcementManager->hasCompletedRegistration($sessionMember)
) {
$this->doPerformLogin($sessionMember);
Expand Down Expand Up @@ -323,8 +331,11 @@ public function startVerification(): HTTPResponse
$request = $this->getRequest();
$store = $this->getStore();
// If we don't have a valid member we shouldn't be here, or if sudo mode is not active yet.
if (!$store || !$store->getMember() ||
!$this->getSudoModeService()->check($this->controller->getSession() ?: new Session([]))) {
if (
!$store
|| !$store->getMember()
|| !$this->getSudoModeService()->check($this->controller->getSession() ?: new Session([]))
) {
return $this->jsonResponse(['message' => 'Forbidden'], 403);
}

Expand Down Expand Up @@ -428,7 +439,8 @@ public function redirectAfterSuccessfulLogin()
// This is potentially redundant logic as the member should only be logged in if they've fully registered.
// They're allowed to login if they can skip - so only do assertions if they're not allowed to skip
// We'll also check that they've registered the required MFA details
if (!$enforcementManager->canSkipMFA($member)
if (
!$enforcementManager->canSkipMFA($member)
&& !$enforcementManager->hasCompletedRegistration($member)
) {
$member->logOut();
Expand Down
1 change: 1 addition & 0 deletions src/Authenticator/MemberAuthenticator.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace SilverStripe\MFA\Authenticator;

use Controller;
Expand Down
4 changes: 3 additions & 1 deletion src/BackupCode/Method.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);

namespace SilverStripe\MFA\BackupCode;

Expand Down
4 changes: 3 additions & 1 deletion src/BackupCode/RegisterHandler.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);

namespace SilverStripe\MFA\BackupCode;

Expand Down
4 changes: 3 additions & 1 deletion src/BackupCode/VerifyHandler.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);

namespace SilverStripe\MFA\BackupCode;

Expand Down
7 changes: 5 additions & 2 deletions src/Controller/AdminRegistrationController.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);

namespace SilverStripe\MFA\Controller;

Expand Down Expand Up @@ -185,7 +187,8 @@ public function setDefaultRegisteredMethod(): HTTPResponse
{
$request = $this->getRequest();
// Ensure CSRF and sudo-mode protection
if (!SecurityToken::inst()->checkRequest($request)
if (
!SecurityToken::inst()->checkRequest($request)
|| !$this->getSudoModeService()->check($this->getSession())
) {
return $this->jsonResponse(
Expand Down
1 change: 1 addition & 0 deletions src/Exception/InvalidMethodException.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace SilverStripe\MFA\Exception;

use LogicException;
Expand Down
1 change: 0 additions & 1 deletion src/Extension/AccountReset/AccountResetHandler.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php


namespace SilverStripe\MFA\Extension\AccountReset;

use Member;
Expand Down
4 changes: 3 additions & 1 deletion src/Extension/AccountReset/MFAResetExtension.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);

namespace SilverStripe\MFA\Extension\AccountReset;

Expand Down
10 changes: 7 additions & 3 deletions src/Extension/AccountReset/MemberExtension.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);

namespace SilverStripe\MFA\Extension\AccountReset;

Expand Down Expand Up @@ -45,9 +47,11 @@ public function generateAccountResetTokenAndStoreHash(): string
do {
$token = $generator->randomToken();
$hash = $this->owner->encryptWithUserSettings($token);
} while (DataObject::get_one(Member::class, [
} while (
DataObject::get_one(Member::class, [
'"Member"."AccountResetHash"' => $hash,
]));
])
);

$expiry = DBDatetime::create();
$expiry->setValue(
Expand Down
4 changes: 3 additions & 1 deletion src/Extension/AccountReset/SecurityAdminExtension.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);

namespace SilverStripe\MFA\Extension\AccountReset;

Expand Down
4 changes: 3 additions & 1 deletion src/Extension/AccountReset/SecurityExtension.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);

namespace SilverStripe\MFA\Extension\AccountReset;

Expand Down
7 changes: 5 additions & 2 deletions src/Extension/ChangePasswordExtension.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);

namespace SilverStripe\MFA\Extension;

Expand Down Expand Up @@ -189,7 +191,8 @@ public function handleChangePassword()
/** @var Member&MemberExtension $member */
$member = Member::member_from_autologinhash($hash);

if ($hash
if (
$hash
&& $member
&& $member->RegisteredMFAMethods()->exists()
&& !$session->get(self::MFA_VERIFIED_ON_CHANGE_PASSWORD)
Expand Down
4 changes: 3 additions & 1 deletion src/Extension/MemberExtension.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);

namespace SilverStripe\MFA\Extension;

Expand Down
4 changes: 3 additions & 1 deletion src/JSONResponse.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);

namespace SilverStripe\MFA;

Expand Down
4 changes: 3 additions & 1 deletion src/Method/Handler/RegisterHandlerInterface.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);

namespace SilverStripe\MFA\Method\Handler;

Expand Down
4 changes: 3 additions & 1 deletion src/Method/Handler/VerifyHandlerInterface.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);

namespace SilverStripe\MFA\Method\Handler;

Expand Down
4 changes: 3 additions & 1 deletion src/Method/MethodInterface.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);

namespace SilverStripe\MFA\Method;

Expand Down
4 changes: 3 additions & 1 deletion src/Model/MFARegisteredMethod.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);

use SilverStripe\MFA\Method\Handler\RegisterHandlerInterface;
use SilverStripe\MFA\Method\Handler\VerifyHandlerInterface;
Expand Down
4 changes: 3 additions & 1 deletion src/Report/EnabledMembers.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);

use SilverStripe\MFA\Extension\MemberExtension;
use SilverStripe\MFA\Service\MethodRegistry;
Expand Down
4 changes: 3 additions & 1 deletion src/Service/BackupCodeGenerator.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);

namespace SilverStripe\MFA\Service;

Expand Down
4 changes: 3 additions & 1 deletion src/Service/BackupCodeGeneratorInterface.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);

namespace SilverStripe\MFA\Service;

Expand Down
4 changes: 3 additions & 1 deletion src/Service/EncryptionAdapterInterface.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);

namespace SilverStripe\MFA\Service;

Expand Down
7 changes: 5 additions & 2 deletions src/Service/EnforcementManager.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);

namespace SilverStripe\MFA\Service;

Expand Down Expand Up @@ -225,7 +227,8 @@ protected function hasAdminAccess(Member $member): bool
// Look through all LeftAndMain subclasses to find if one permits the member to view
$menu = $leftAndMain->MainMenu();
foreach ($menu as $candidate) {
if ($candidate->Link
if (
$candidate->Link
&& $candidate->Link !== $leftAndMain->Link()
&& $candidate->MenuItem->controller
&& singleton($candidate->MenuItem->controller)->canView($member)
Expand Down
4 changes: 3 additions & 1 deletion src/Service/MethodRegistry.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);

namespace SilverStripe\MFA\Service;

Expand Down
4 changes: 3 additions & 1 deletion src/Service/Notification.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);

namespace SilverStripe\MFA\Service;

Expand Down
4 changes: 3 additions & 1 deletion src/Service/RegisteredMethodManager.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);

namespace SilverStripe\MFA\Service;

Expand Down
4 changes: 3 additions & 1 deletion src/State/AvailableMethodDetails.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);

namespace SilverStripe\MFA\State;

Expand Down
4 changes: 3 additions & 1 deletion src/State/BackupCode.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);

namespace SilverStripe\MFA\State;

Expand Down
4 changes: 3 additions & 1 deletion src/State/RegisteredMethodDetails.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);

namespace SilverStripe\MFA\State;

Expand Down
4 changes: 3 additions & 1 deletion src/State/Result.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);

namespace SilverStripe\MFA\State;

Expand Down
4 changes: 3 additions & 1 deletion src/Store/SessionStore.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);

namespace SilverStripe\MFA\Store;

Expand Down
4 changes: 3 additions & 1 deletion src/Store/StoreInterface.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);

namespace SilverStripe\MFA\Store;

Expand Down
4 changes: 3 additions & 1 deletion tests/Behat/Context/LoginContext.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);

namespace SilverStripe\MFA\Tests\Behat\Context;

Expand Down
4 changes: 3 additions & 1 deletion tests/php/Service/BackupCodeGeneratorTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);

namespace SilverStripe\MFA\Service;

Expand Down
1 change: 1 addition & 0 deletions tests/php/Stub/BasicMath/Method.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace SilverStripe\MFA\Tests\Stub\BasicMath;

use Director;
Expand Down
4 changes: 3 additions & 1 deletion tests/php/Stub/BasicMath/MethodRegisterHandler.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);

namespace SilverStripe\MFA\Tests\Stub\BasicMath;

Expand Down
Loading

0 comments on commit 19bbfef

Please sign in to comment.