Issues (11)

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/Routes.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
2
3
declare(strict_types=1);
4
5
namespace Nymfonya\Component\Http;
6
7
use Nymfonya\Component\Http\Interfaces\RoutesInterface;
8
use Nymfonya\Component\Http\Route;
9
10
class Routes implements RoutesInterface
11
{
12
13
    /**
14
     * route list as array
15
     *
16
     * @var array
17
     */
18
    private $routes = [];
19
20
    /**
21
     * __construct
22
     *
23
     * @param array $routesConfig
24
     */
25 5
    public function __construct(array $routesConfig = [])
26
    {
27 5
        if (!empty($routesConfig)) {
28 5
            $this->set($routesConfig);
29
        }
30
    }
31
32
    /**
33
     * set routes as array and stack Route collection
34
     *
35
     * @param array $routesConfig
36
     * @return RoutesInterface
37
     */
38 5
    public function set(array $routesConfig): RoutesInterface
39
    {
40 5
        $this->routes = [];
41 5
        $this->prepare($routesConfig);
42 5
        $this->validate();
43 5
        return $this;
44
    }
45
46
    /**
47
     * returns routes as array
48
     *
49
     * @return array
50
     */
51 1
    public function get(): array
52
    {
53 1
        return $this->routes;
54
    }
55
56
    /**
57
     * returns routes as array
58
     *
59
     * @return array
60
     */
61 2
    public function getExpr(): array
62
    {
63 2
        $patterns = array_map(
64
            function (Route $i) {
65 2
                return $i->getExpr();
66 2
            },
67 2
            $this->routes
68
        );
69 2
        return $patterns;
70
    }
71
72
    /**
73
     * stacks routes as Route object collection from routes config
74
     *
75
     * @param array $routesConfig
76
     * @return RoutesInterface
77
     */
78 1
    protected function prepare(array $routesConfig): RoutesInterface
79
    {
80 1
        $count = count($routesConfig);
81 1
        for ($c = 0; $c < $count; $c++) {
82 1
            $this->routes[] = new Route($routesConfig[$c]);
83
        }
84 1
        return $this;
85
    }
86
87
    /**
88
     * validate routes to be an array of regexp string
89
     *
90
     * @throws Exception
91
     */
92 2
    protected function validate()
93
    {
94 2
        $count = count($this->routes);
95 2
        for ($c = 0; $c < $count; $c++) {
96 2
            $route = $this->routes[$c]->getExpr();
97 2
            if ($this->isInvalidRegexp($route)) {
98 1
                throw new \Exception('Route invalid expr ' . $route);
99
            }
100
        }
101
    }
102
103
     /**
104
      * return true if regexp is invalid
105
      *
106
      * @param string $regExp
107
      * @return boolean
108
      */
109
    protected function isInvalidRegexp(string $regExp): bool
110
    {
111
        @preg_match($regExp, '');
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
112
        return (preg_last_error() != PREG_NO_ERROR);
113
    }
114
}
115