Issues (6)

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/MtRand.php (2 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
namespace Savvot\Random;
4
5
/**
6
 * Pure PHP implementation of Mersenne twister PRNG (builtin mt_rand() function)
7
 * This generator is fully compatible with mt_rand() so can be used as replacement
8
 * Random sequences from both methods with same int seed will match perfectly
9
 *
10
 * WARNING: This generator is compatible with mt_rand ONLY when int seed is specified
11
 * In case of string seed (even if it is numeric) or empty (default) seed, results will be different
12
 *
13
 * Based on PHP source code from https://github.com/php/php-src/blob/master/ext/standard/rand.c
14
 *
15
 * @package Savvot\Random
16
 * @author  SavvoT <[email protected]>
17
 */
18
class MtRand extends AbstractRand
19
{
20
    // PHP builtin mt_rand returns 31bit integers
21
    const INT_MAX = 0x7fffffff;
22
23
    const N = 624;
24
    const M = 397;
25
26
    /**
27
     * @inheritdoc
28
     */
29
    public function randomInt()
30
    {
31
        if ($this->state['left'] === 0) {
32
            $this->reload();
33
        }
34
        $this->state['left']--;
35
36
        $s1 = $this->state['mt'][$this->state['next']];
37
        $this->state['next'] = (++$this->state['next']) % self::N;
38
39
        $s1 ^= ($s1 >> 11);
40
        $s1 ^= ($s1 << 7) & 0x9d2c5680;
41
        $s1 ^= ($s1 << 15) & 0xefc60000;
42
43
        return ($s1 ^ ($s1 >> 18)) >> 1;
44
    }
45
46
    /**
47
     * @inheritdoc
48
     */
49
    protected function init()
50
    {
51
        $state = [];
52
        if (is_int($this->seed)) {
53
            // For int seed we must repeat mt_rand initialization
54
            $state[0] = $this->seed & 0xffffffff;
55
        } else {
56
            $st = unpack('V*', $this->hashedSeed);
57
            $state[0] = $st[1] ^ $st[2] ^ $st[3] ^ $st[4];
58
        }
59
60
        for ($i = 1; $i < self::N; $i++) {
61
            $r = $state[$i - 1];
62
            $state[$i] = (1812433253 * ($r ^ ($r >> 30)) + $i) & 0xffffffff;
63
        }
64
        $this->state = ['mt' => $state];
65
        $this->reload();
66
    }
67
68
    /**
69
     * "Twist" stage of algorithm
70
     */
71
    private function reload()
72
    {
73
        $p = 0;
74 View Code Duplication
        for ($i = self::N - self::M; $i--; ++$p) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
75
            $m = $this->state['mt'][$p + self::M];
76
            $u = $this->state['mt'][$p];
77
            $v = $this->state['mt'][$p + 1];
78
            $this->state['mt'][$p] = ($m ^ ((($u & 0x80000000) | ($v & 0x7fffffff)) >> 1) ^ (-($u & 0x00000001) & 0x9908b0df));
79
        }
80 View Code Duplication
        for ($i = self::M; --$i; ++$p) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
81
            $m = $this->state['mt'][$p + self::M - self::N];
82
            $u = $this->state['mt'][$p];
83
            $v = $this->state['mt'][$p + 1];
84
            $this->state['mt'][$p] = ($m ^ ((($u & 0x80000000) | ($v & 0x7fffffff)) >> 1) ^ (-($u & 0x00000001) & 0x9908b0df));
85
        }
86
        $m = $this->state['mt'][$p + self::M - self::N];
87
        $u = $this->state['mt'][$p];
88
        $v = $this->state['mt'][0];
89
        $this->state['mt'][$p] = ($m ^ ((($u & 0x80000000) | ($v & 0x7fffffff)) >> 1) ^ (-($u & 0x00000001) & 0x9908b0df));
90
91
        $this->state['left'] = self::N;
92
        $this->state['next'] = 0;
93
    }
94
}
95