Issues (15)

Security Analysis    no request data  

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

Plugin/Model/Authentication.php (1 issue)

parameters are used.

Unused Code Minor

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
declare(strict_types=1);
3
4
/**
5
 * File:Authentication.php
6
 *
7
 * @author Maciej Sławik <[email protected]>
8
 * @copyright Copyright (C) 2018 Lizard Media (http://lizardmedia.pl)
9
 */
10
11
namespace LizardMedia\PasswordMigrator\Plugin\Model;
12
13
use Exception;
14
use LizardMedia\PasswordMigrator\Api\LegacyAuthenticationInterface;
15
use LizardMedia\PasswordMigrator\Api\PasswordManagementInterface;
16
use Magento\Customer\Model\Authentication as AuthenticationModel;
17
use Magento\Customer\Model\CustomerRegistry;
18
use Magento\Customer\Model\Session;
19
use Magento\Framework\Exception\InputException;
20
use Magento\Framework\Url;
21
22
/**
23
 * TODO: Unit test
24
 * Class Authentication
25
 * @package LizardMedia\PasswordMigrator\Plugin\Model
26
 */
27
class Authentication
28
{
29
    /**
30
     * @var LegacyAuthenticationInterface
31
     */
32
    private $legacyAuthentication;
33
34
    /**
35
     * @var PasswordManagementInterface
36
     */
37
    private $passwordManagement;
38
39
    /**
40
     * @var CustomerRegistry
41
     */
42
    private $customerRegistry;
43
44
    /**
45
     * @var Session
46
     */
47
    private $session;
48
49
    /**
50
     * @var Url
51
     */
52
    private $url;
53
54
    /**
55
     * Authentication constructor.
56
     * @param LegacyAuthenticationInterface $legacyAuthentication
57
     * @param PasswordManagementInterface $passwordManagement
58
     * @param CustomerRegistry $customerRegistry
59
     * @param Session $session
60
     * @param Url $url
61
     */
62
    public function __construct(
63
        LegacyAuthenticationInterface $legacyAuthentication,
64
        PasswordManagementInterface $passwordManagement,
65
        CustomerRegistry $customerRegistry,
66
        Session $session,
67
        Url $url
68
    ) {
69
        $this->legacyAuthentication = $legacyAuthentication;
70
        $this->passwordManagement = $passwordManagement;
71
        $this->customerRegistry = $customerRegistry;
72
        $this->session = $session;
73
        $this->url = $url;
74
    }
75
76
    /**
77
     * @param AuthenticationModel $subject
78
     * @param callable $proceed
79
     * @param $customerId
80
     * @param $password
81
     * @return bool
82
     * @throws Exception
83
     */
84
    public function aroundAuthenticate(AuthenticationModel $subject, callable $proceed, $customerId, $password)
0 ignored issues
show
The parameter $subject is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
85
    {
86
        try {
87
            return $proceed($customerId, $password);
88
        } catch (Exception $e) {
89
            if ($this->legacyAuthentication->canLegacyAuthenticate((int)$customerId, $password)) {
90
                $this->updateCustomerPassword((int) $customerId, $password);
91
                return $proceed($customerId, $password);
92
            } else {
93
                throw $e;
94
            }
95
        }
96
    }
97
98
99
    /**
100
     * @param int $customerId
101
     * @param string $password
102
     * @return void
103
     * @throws InputException
104
     */
105
    private function updateCustomerPassword(int $customerId, string $password) : void
106
    {
107
        try {
108
            $this->passwordManagement->updateCustomerPassword($customerId, $password);
109
        } catch (InputException $exception) {
110
            $this->session->setBeforeAuthUrl($this->getResetPasswordUrl($customerId));
111
            throw $exception;
112
        }
113
    }
114
115
116
    /**
117
     * @param int $customerId
118
     * @return string
119
     */
120
    private function getResetPasswordUrl(int $customerId) : string
121
    {
122
        $secureData = $this->customerRegistry->retrieveSecureData($customerId);
123
        return $this->url->getUrl(
124
            'customer/account/createPassword',
125
            [
126
                'id' => $customerId,
127
                'token' => $secureData->getRpToken()
128
            ]
129
        );
130
    }
131
}
132