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.

src/SmsLoginController.php (4 issues)

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
 * This code is part of the Apiary SMS Login Provider project.
4
 *
5
 * (c) Darren Mothersele <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Apiary\SmsLoginProvider;
12
13
use Apiary\SmsLoginProvider\SmsHandler\SmsHandlerInterface;
14
use Silex\Application;
15
use Symfony\Component\HttpFoundation\Request;
16
use Symfony\Component\Security\Core\Exception\AuthenticationException;
0 ignored issues
show
As per PSR2, there should be exactly one blank line after the last USE statement, 2 were found though.
Loading history...
17
18
19
class SmsLoginController
20
{
21
22
    /**
23
     * An array of countries for the select list options.
24
     *
25
     * @var array
26
     */
27
    protected $countries;
28
29
    /**
30
     * SMS Handler used to send validate numbers and send SMS verification
31
     *
32
     * @var \Apiary\SmsLoginProvider\SmsHandler\SmsHandlerInterface
33
     */
34
    protected $handler;
35
36
    /**
37
     * String used to create verification SMS message, must contain `%s` which
38
     * is replaced by the verification code.
39
     *
40
     * @var string
41
     */
42
    protected $messageTemplate;
43
44
    /**
45
     * The name of the view template to use to render the login form.
46
     * Defaults to 'login.twig'
47
     *
48
     * @var string
49
     */
50
    protected $viewName;
51
52
    protected $debug;
53
54
    /**
55
     * SmsLoginController constructor.
56
     * @param \Apiary\SmsLoginProvider\SmsHandler\SmsHandlerInterface $handler
57
     * @param string|NULL $view
58
     * @param string|NULL $message
59
     * @param null $debug
0 ignored issues
show
There is no parameter named $debug. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
60
     */
61 9
    public function __construct(
62
        SmsHandlerInterface $handler,
63
        $view = null,
64
        $message = null
65
    )
66
    {
67 9
        $this->messageTemplate = $message ?: 'Security code: %s';
68 9
        $countryData = file_get_contents(__DIR__ . '/../data/countries.json');
69 9
        $this->countries = json_decode($countryData);
0 ignored issues
show
Documentation Bug introduced by
It seems like json_decode($countryData) of type * is incompatible with the declared type array of property $countries.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
70 9
        $this->handler = $handler;
71 9
        $this->viewName = $view ?: 'login.twig';
72 9
    }
73
74
    /**
75
     * Login controller action
76
     * Step 1: Login shows form to enter mobile phone number.
77
     *
78
     * @param \Silex\Application $app
79
     * @param \Symfony\Component\HttpFoundation\Request $request
80
     * @return string
81
     */
82 3
    public function loginAction(Application $app, Request $request)
83
    {
84 3
        return $app['twig']->render($this->viewName, [
85 3
            'country_list' => $this->countries,
86 3
            'error' => $app['security.last_error']($request),
87 3
            'form_action' => $app['url_generator']->generate('sms.login'),
88 3
        ]);
89
    }
90
91
    /**
92
     * Verify controller action
93
     * Step 2: Send code to number by SMS and show form to verify code
94
     *
95
     * @param \Silex\Application $app
96
     * @param \Symfony\Component\HttpFoundation\Request $request
97
     * @return string
98
     */
99 3
    public function verifyAction(Application $app, Request $request)
100
    {
101 3
        $mobile = $request->get('mobile');
102 3
        $country = $request->get('country');
103
104 3
        if (empty($mobile)) {
105
            throw new AuthenticationException('Mobile number is required');
106
        }
107
108 3
        $code = sprintf("%'.05d", rand(0, 99999));
109 3
        $app['session']->set('code', $code);
110
111 3
        $number = $this->handler->lookupNumber($mobile, $country);
112 3
        $message = sprintf($this->messageTemplate, $code);
113 3
        $this->handler->sendSMS($number, $message);
114
115 3
        return $app['twig']->render($this->viewName, [
116 3
            'mobile' => $number,
117 3
            'form_action' => $app['url_generator']->generate('sms.login') . '/check',
118 3
        ]);
119
    }
120
121
}
0 ignored issues
show
According to PSR2, the closing brace of classes should be placed on the next line directly after the body.

Below you find some examples:

// Incorrect placement according to PSR2
class MyClass
{
    public function foo()
    {

    }
    // This blank line is not allowed.

}

// Correct
class MyClass
{
    public function foo()
    {

    } // No blank lines after this line.
}
Loading history...
122