Issues (27)

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.

src/Validation/Phone.php (1 issue)

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 namespace Propaganistas\LaravelPhone\Validation;
2
3
use Illuminate\Support\Arr;
4
use Illuminate\Support\Collection;
5
use libphonenumber\PhoneNumberUtil;
6
use Propaganistas\LaravelPhone\Exceptions\InvalidParameterException;
7
use libphonenumber\NumberParseException;
8
use Propaganistas\LaravelPhone\PhoneNumber;
9
use Propaganistas\LaravelPhone\Traits\ParsesCountries;
10
use Propaganistas\LaravelPhone\Traits\ParsesTypes;
11
12
class Phone
13
{
14
    use ParsesCountries,
15
        ParsesTypes;
16
17
    /**
18
     * @var \libphonenumber\PhoneNumberUtil
19
     */
20
    protected $lib;
21
22
    /**
23
     * Phone constructor.
24
     */
25 51
    public function __construct()
26
    {
27 51
        $this->lib = PhoneNumberUtil::getInstance();
28 51
    }
29
30
    /**
31
     * Validates a phone number.
32
     *
33
     * @param  string $attribute
34
     * @param  mixed  $value
35
     * @param  array  $parameters
36
     * @param  object $validator
37
     * @return bool
38
     */
39 51
    public function validate($attribute, $value, array $parameters, $validator)
40
    {
41 51
        $data = $validator->getData();
42
43
        list(
44
            $countries,
45
            $types,
46
            $detect,
47 51
            $lenient) = $this->extractParameters($attribute, $parameters, $data);
48
49
        // A "null" country is prepended:
50
        // 1. In case of auto-detection to have the validation run first without supplying a country.
51
        // 2. In case of lenient validation without provided countries; we still might have some luck...
52 48
        if ($detect || ($lenient && empty($countries))) {
53 12
            array_unshift($countries, null);
54
        }
55
56 48
        foreach ($countries as $country) {
57
            try {
58
                // Parsing the phone number also validates the country, so no need to do this explicitly.
59
                // It'll throw a PhoneCountryException upon failure.
60 42
                $phoneNumber = PhoneNumber::make($value, $country);
61
62
                // Type validation.
63 42
                if (! empty($types) && ! $phoneNumber->isOfType($types)) {
64 18
                    continue;
65
                }
66
67 39
                $lenientPhoneNumber = $phoneNumber->lenient()->getPhoneNumberInstance();
68
69
                // Lenient validation.
70 39
                if ($lenient && $this->lib->isPossibleNumber($lenientPhoneNumber, $country)) {
71 3
                    return true;
72
                }
73
74 39
                $phoneNumberInstance = $phoneNumber->getPhoneNumberInstance();
75
76
                // Country detection.
77 39
                if ($detect && $this->lib->isValidNumber($phoneNumberInstance)) {
78 9
                    return true;
79
                }
80
81
                // Default number+country validation.
82 39
                if ($this->lib->isValidNumberForRegion($phoneNumberInstance, $country)) {
83 39
                    return true;
84
                }
85 24
            } catch (NumberParseException $e) {
86 24
                continue;
87
            }
88
        }
89
90 45
        return false;
91
    }
92
93
    /**
94
     * Parse and extract parameters in the appropriate validation arguments.
95
     *
96
     * @param string $attribute
97
     * @param array  $parameters
98
     * @param array  $data
99
     * @return array
100
     * @throws \Propaganistas\LaravelPhone\Exceptions\InvalidParameterException
101
     */
102 51
    protected function extractParameters($attribute, array $parameters, array $data)
103
    {
104
        // Discover if an input field was provided. If not, guess the field's name.
105 51
        $inputField = Collection::make($parameters)
106 51
                                ->intersect(array_keys(Arr::dot($data)))
0 ignored issues
show
$data is of type array, but the function expects a object<Illuminate\Support\iterable>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
107 51
                                ->first() ?: "${attribute}_country";
108
109
        // Attempt to retrieve the field's value.
110 51
        if ($inputCountry = Arr::get($data, $inputField)) {
111
112 30
            if (static::isValidType($inputField)) {
113 3
                throw InvalidParameterException::ambiguous($inputField);
114
            }
115
116
            // Invalid country field values should just validate to false.
117
            // This will also prevent parameter hijacking through the country field.
118 27
            if (static::isValidCountryCode($inputCountry)) {
119 21
                $parameters[] = $inputCountry;
120
            }
121
        }
122
        
123 48
        $parameters = array_map('strtolower', $parameters);
124
125
        return [
126 48
            static::parseCountries($parameters),
127 48
            static::parseTypes($parameters),
128 48
            in_array('auto', $parameters),
129 48
            in_array('lenient', $parameters)
130
        ];
131
    }
132
}
133