GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Issues (1)

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/Iban.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
namespace IbanGenerator;
4
5
use IbanGenerator\Bban;
6
use InvalidArgumentException;
7
8
class Iban
9
{
10
    /**
11
     * @var Bban\BbanInterface
12
     */
13
    private $bban;
14
15
    /**
16
     * @var string
17
     */
18
    private $countryCode;
19
20
    /**
21
     * @var string
22
     */
23
    private $checkDigits;
24
25
    /**
26
     * @var array
27
     */
28
    private static $countriesSupported = [
29
        'ES' => Bban\SpainBban::class,
30
        'AD' => Bban\AndorraBban::class,
31
    ];
32
33
    /**
34
     * Iban constructor.
35
     *
36
     * @param string $countryCode
37
     * @param string $checkDigits
38
     * @param Bban\BbanInterface $bban
39
     *
40
     * @throws InvalidArgumentException
41
     */
42 46
    public function __construct($countryCode, $checkDigits, Bban\BbanInterface $bban)
43
    {
44 46
        $countryCode = strtoupper($countryCode);
45 46
        self::validateCountryCodeFormat($countryCode);
46 42
        self::validateCheckDigitsFormat($checkDigits);
47 38
        self::validateControlDigit($countryCode, $checkDigits, $bban);
48 36
        $this->countryCode = $countryCode;
49 36
        $this->checkDigits = $checkDigits;
50 36
        $this->bban = $bban;
51 36
    }
52
53
    /**
54
     * @param string $iban
55
     *
56
     * @throws InvalidArgumentException
57
     *
58
     * @return static
59
     */
60 16
    public static function fromString($iban)
61
    {
62 16
        $iban = preg_replace('/[^0-9a-zA-Z]+/', '', $iban);
63
64 16
        if (! preg_match('/^[0-9a-zA-Z]{16,34}$/', $iban)) {
65 3
            throw new InvalidArgumentException('Iban should be between 16 and 34 characters');
66
        }
67
68 13
        $countryCode = strtoupper(substr($iban, 0, 2));
69 13
        $checkDigits = strtoupper(substr($iban, 2, 2));
70 13
        $bbanString = strtoupper(substr($iban, 4));
71
72 13
        self::validateSupportedCountry($countryCode);
73 12
        $bbanClass = self::$countriesSupported[$countryCode];
74
75
        /**
76
         * @var Bban\BbanInterface
77
         */
78 12
        $bban = $bbanClass::fromString($bbanString);
79
80 12
        return new static($countryCode, $checkDigits, $bban);
81
    }
82
83
    /**
84
     * @param Bban\BbanInterface $bban
85
     * @param string $countryCode
86
     *
87
     * @throws InvalidArgumentException
88
     *
89
     * @return static
90
     */
91 12
    public static function fromBbanAndCountry(Bban\BbanInterface $bban, $countryCode)
92
    {
93 12
        self::validateCountryCodeFormat($countryCode);
94 12
        self::validateCountryCodeFormat($countryCode);
95 12
        self::validateSupportedCountry($countryCode);
96
97 12
        $checksum = self::validateChecksum($countryCode, '00', $bban);
98 12
        $checkDigit = 98 - (int) $checksum;
99 12
        $checkDigit = str_pad($checkDigit, 2, 0, STR_PAD_LEFT);
100
101 12
        return new static($countryCode, $checkDigit, $bban);
102
    }
103
104
    /**
105
     * @return string
106
     */
107 12
    public function countryCode()
108
    {
109 12
        return $this->countryCode;
110
    }
111
112
    /**
113
     * @return string
114
     */
115 24
    public function ibanCheckDigits()
116
    {
117 24
        return $this->checkDigits;
118
    }
119
120
    /**
121
     * @return string
122
     */
123 12
    public function bankCode()
124
    {
125 12
        return $this->bban->bankCode();
126
    }
127
128
    /**
129
     * @return string
130
     */
131 12
    public function branchCode()
132
    {
133 12
        return $this->bban->branchCode();
134
    }
135
136
    /**
137
     * @return string
138
     */
139 12
    public function countryCheckDigits()
140
    {
141 12
        return $this->bban->checkDigits();
142
    }
143
144
    /**
145
     * @return string
146
     */
147 12
    public function accountNumber()
148
    {
149 12
        return $this->bban->accountNumber();
150
    }
151
152
    /**
153
     * @return string
154
     */
155 12
    public function __toString()
156
    {
157 12
        $bbanString = $this->bban;
158
159 12
        return $this->countryCode . $this->checkDigits . $bbanString;
160
    }
161
162
    /**
163
     * @param $countryCode
164
     *
165
     * @throws InvalidArgumentException
166
     */
167 46
    private static function validateCountryCodeFormat($countryCode)
168
    {
169 46
        if (! preg_match('/^[A-Z]{2}$/', $countryCode)) {
170 4
            throw new InvalidArgumentException('The country code should be 2 letters');
171
        }
172 42
    }
173
174
    /**
175
     * @param $checkDigits
176
     *
177
     * @throws InvalidArgumentException
178
     */
179 42
    private static function validateCheckDigitsFormat($checkDigits)
180
    {
181 42
        if (! preg_match('/^[\d]{2}$/', $checkDigits)) {
182 4
            throw new InvalidArgumentException('The IBAN checksum must be 2 numeric characters');
183
        }
184 38
    }
185
186
    /**
187
     * @param string $countryCode
188
     * @param string $checkDigits
189
     * @param Bban\BbanInterface $bban
190
     *
191
     * @throws InvalidArgumentException
192
     */
193 38
    private static function validateControlDigit(
194
        $countryCode,
195
        $checkDigits,
196
        Bban\BbanInterface $bban
197
    ) {
198 38
        $checksum = self::validateChecksum($countryCode, $checkDigits, $bban);
199
200 38
        if ($checksum !== '01') {
201 2
            throw new InvalidArgumentException('The IBAN checksum digits are not valid');
202
        }
203 36
    }
204
205
    /**
206
     * @param $countryCode
207
     *
208
     * @throws InvalidArgumentException
209
     */
210 25
    private static function validateSupportedCountry($countryCode)
211
    {
212 25
        if (!array_key_exists($countryCode, self::$countriesSupported)) {
213 1
            throw new InvalidArgumentException(
214 1
                sprintf(
215 1
                    'The country code %s is not supported',
216 1
                    $countryCode
217
                )
218
            );
219
        }
220 24
    }
221
222
    /**
223
     * @param $countryCode
224
     * @param $checkDigits
225
     * @param Bban\BbanInterface $bban
226
     *
227
     * @return string
228
     */
229 38
    private static function validateChecksum($countryCode, $checkDigits, Bban\BbanInterface $bban)
230
    {
231 38
        $rearranged = (string) $bban . $countryCode . $checkDigits;
232 38
        $digitsList = str_split($rearranged);
233
234 38
        $digitsList = array_map(['self', 'digitToInt'], $digitsList);
235 38
        $stringToCompute = implode('', $digitsList);
236
237 38
        $checksum = bcmod($stringToCompute, '97');
238
239 38
        return str_pad($checksum, 2, 0, STR_PAD_LEFT);
240
    }
241
242
    /**
243
     * @param string $value
244
     *
245
     * @return int
246
     */
247 38
    private static function digitToInt($value)
0 ignored issues
show
This method is not used, and could be removed.
Loading history...
248
    {
249 38
        if (is_numeric($value)) {
250 38
            return (int) $value;
251
        }
252
253 38
        return ord($value) - 55;
254
    }
255
}
256