Issues (2)

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/Weew/HttpBlueprint/BlueprintProxy.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 Weew\HttpBlueprint;
4
5
use Weew\Http\HttpRequestMethod;
6
use Weew\Http\IHttpResponse;
7
use Weew\Router\IRoute;
8
use Weew\Router\IRouter;
9
use Weew\Router\Router;
10
use Weew\Url\IUrl;
11
use Weew\Url\Url;
12
13
class BlueprintProxy {
14
    /**
15
     * @var IRouter
16
     */
17
    protected $router;
18
19
    /**
20
     * @var IResponseBuilder
21
     */
22
    protected $responseBuilder;
23
24
    /**
25
     * @var array
26
     */
27
    protected $server;
28
29
    /**
30
     * @param IRouter $router
31
     * @param IResponseBuilder $responseBuilder
32
     * @param array $server
33
     */
34
    public function __construct(
0 ignored issues
show
__construct uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
35
        IRouter $router = null,
36
        IResponseBuilder $responseBuilder = null,
37
        array $server = null
38
    ) {
39
        if ( ! $router instanceof IRouter) {
40
            $router = $this->createRouter();
41
        }
42
43
        if ( ! $responseBuilder instanceof IResponseBuilder) {
44
            $responseBuilder = $this->createResponseBuilder();
45
        }
46
47
        if ($server === null) {
48
            $server = $_SERVER;
49
        }
50
51
        $this->router = $router;
52
        $this->responseBuilder = $responseBuilder;
53
        $this->server = $server;
54
    }
55
56
    /**
57
     * @return IRouter
58
     */
59
    public function getRouter() {
60
        return $this->router;
61
    }
62
63
    /**
64
     * @param IRouter $router
65
     */
66
    public function setRouter(IRouter $router) {
67
        $this->router = $router;
68
    }
69
70
    /**
71
     * @param null $requestMethod
72
     * @param IUrl|null $url
73
     */
74
    public function sendResponse($requestMethod = null, IUrl $url = null) {
75
        $response = $this->createResponse($requestMethod, $url);
0 ignored issues
show
It seems like $url defined by parameter $url on line 74 can also be of type object<Weew\Url\IUrl>; however, Weew\HttpBlueprint\Bluep...Proxy::createResponse() does only seem to accept null, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
76
        $response->send();
77
    }
78
79
    /**
80
     * @param null $requestMethod
81
     * @param null $url
82
     *
83
     * @return IHttpResponse
84
     */
85
    public function createResponse($requestMethod = null, $url = null) {
86
        if ( ! $requestMethod) {
87
            $requestMethod = $this->getRequestMethod();
88
        }
89
90
        if ( ! $url) {
91
            $url = $this->getUrl();
92
        }
93
94
        $route = $this->router->match($requestMethod, $url);
95
96
        if ($route instanceof IRoute) {
97
            return $this->responseBuilder->buildResponseForRoute($route);
98
        }
99
100
        return $this->responseBuilder->buildDefaultErrorResponse();
101
    }
102
103
    /**
104
     * @return string
105
     */
106
    protected function getRequestMethod() {
107
        return array_get($this->server, 'REQUEST_METHOD', HttpRequestMethod::GET);
108
    }
109
110
    /**
111
     * @return IUrl
112
     */
113
    protected function getUrl() {
114
        return new Url(array_get($this->server, 'REQUEST_URI'));
115
    }
116
117
    /**
118
     * @return Router
119
     */
120
    protected function createRouter() {
121
        return new Router();
122
    }
123
124
    /**
125
     * @return ResponseBuilder
126
     */
127
    protected function createResponseBuilder() {
128
        return new ResponseBuilder();
129
    }
130
}
131