Issues (29)

Security Analysis    not enabled

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.

Model/Urls/Checker.php (1 issue)

Severity

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
/**
3
 * A two factor authentication module that protects both the admin and customer logins
4
 * Copyright (C) 2017  Ross Mitchell
5
 *
6
 * This file is part of Rossmitchell/Twofactor.
7
 *
8
 * Rossmitchell/Twofactor is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU General Public License as published by
10
 * the Free Software Foundation, either version 3 of the License, or
11
 * (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20
 */
21
22
namespace Rossmitchell\Twofactor\Model\Urls;
23
24
use Magento\Framework\UrlInterface;
25
26
/**
27
 * Class Checker
28
 *
29
 * This is used as a way to check is a user is on a certain page. It provides semantic names for this and the ability
30
 * to check either customer or admin users
31
 */
32
class Checker
33
{
34
    /**
35
     * @var Fetcher
36
     */
37
    private $fetcher;
38
    /**
39
     * @var UrlInterface
40
     */
41
    private $url;
42
43
    /**
44
     * Checker constructor.
45
     * @param Fetcher $fetcher
46
     * @param UrlInterface $url
47
     */
48 45
    public function __construct(Fetcher $fetcher, UrlInterface $url)
49
    {
50 45
        $this->fetcher = $fetcher;
51 45
        $this->url = $url;
52 45
    }
53
54
    /**
55
     * Checks if the user is currently on the two factor authentication page. Can be used to check both customers and
56
     * admin users.
57
     *
58
     * @param bool $forAdmin - true to check for admin users, false to check for customers
59
     * @return bool
60
     */
61 22
    public function areWeOnTheAuthenticationPage($forAdmin = false)
62
    {
63 22
        $authenticationUrl = $this->fetcher->getAuthenticationUrl($forAdmin);
64
65 22
        return $this->compareUrls($this->getCurrentUrl(), $authenticationUrl);
66
    }
67
68
    /**
69
     * Checks if the user is currently on the two factor verification page. Can be used to check both customers and
70
     * admin users.
71
     *
72
     * @param bool $forAdmin - true to check for admin users, false to check for customers
73
     * @return bool
74
     */
75 19
    public function areWeOnTheVerificationPage($forAdmin = false)
76
    {
77 19
        $verificationUrl = $this->fetcher->getVerificationUrl($forAdmin);
78
79 19
        return $this->compareUrls($this->getCurrentUrl(), $verificationUrl);
80
    }
81
82
    /**
83
     * Returns the current URL
84
     *
85
     * @return string
86
     */
87 22
    private function getCurrentUrl()
88
    {
89 22
        return $this->url->getCurrentUrl();
90
    }
91
92
    /**
93
     * Compares two URLs.
94
     *
95
     * @param $firstUrl
96
     * @param $secondUrl
97
     * @return bool
98
     */
99 22
    private function compareUrls($firstUrl, $secondUrl)
100
    {
101 22
        return ($this->cleanUrl($firstUrl) === $this->cleanUrl($secondUrl));
102
    }
103
104
    /**
105
     * This is used normalise the URLs to a known structure and remove any trailing characters that could prevent them
106
     * from getting checked correctly.
107
     *
108
     * For these checks I'm not that conceded if the customer is using http or https so we strip that out. Equally I'm
109
     * not worried about ports, or query params so they are removed as well
110
     *
111
     * @param $url
112
     * @return string
113
     */
114 22
    private function cleanUrl($url)
115
    {
116 22
        $parts = parse_url($url);
0 ignored issues
show
The use of function parse_url() is discouraged
Loading history...
117 22
        $cleanUrl = $parts['host'] . '/' . $parts['path'];
118 22
        $noRewriteUrl = str_replace('/index.php', '', $cleanUrl);
119
120 22
        return trim($noRewriteUrl, '\t\n\r/');
121
    }
122
}