Issues (3098)

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.

tests/KochTest/Http/HttpRequestTest.php (11 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 KochTest\Http;
4
5
use Koch\Http\HttpRequest;
6
7
class HttpRequestTest extends \PHPUnit_Framework_TestCase
8
{
9
    /**
10
     * @var HttpRequest
11
     */
12
    protected $request;
13
14
    /**
15
     * Sets up the fixture, for example, opens a network connection.
16
     * This method is called before a test is executed.
17
     */
18
    public function setUp()
19
    {
20
        $this->request = new HttpRequest();
21
    }
22
23
    /**
24
     * Tears down the fixture, for example, closes a network connection.
25
     * This method is called after a test is executed.
26
     */
27
    public function tearDown()
28
    {
29
        unset($this->request);
30
    }
31
32
    public function testMethodcontructor_unsetsGlobalVars()
0 ignored issues
show
function testMethodcontructor_unsetsGlobalVars() does not seem to conform to the naming convention (^(?:[a-z]|__)[a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
testMethodcontructor_unsetsGlobalVars uses the super-global variable $_REQUEST 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...
33
    {
34
        $this->assertFalse(isset($_REQUEST));
35
36
        //  Undefined variable: GLOBALS
37
        //  it's not possible to unset globals - phpunit side effect?
38
        //$this->assertFalse(isset($GLOBALS));
0 ignored issues
show
Unused Code Comprehensibility introduced by
90% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
39
    }
40
41
    public function testMethodgetRequestMethod()
0 ignored issues
show
testMethodgetRequestMethod 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...
42
    {
43
        $_SERVER['REQUEST_METHOD']              = 'someMethod';
44
        $_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'] = 'OverrideMethodName';
45
        $this->assertEquals('OverrideMethodName', HttpRequest::getRequestMethod());
46
47
        unset($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE']);
48
        $_SERVER['REQUEST_METHOD'] = 'HEAD';
49
        $this->assertEquals('GET', HttpRequest::getRequestMethod());
50
51
        $this->request->setRequestMethod('BEAVIS');
52
        $this->assertEquals('BEAVIS', HttpRequest::getRequestMethod());
53
54
        unset($_SERVER['REQUEST_METHOD']);
55
    }
56
57
    public function testMethodsetRequestMethod()
58
    {
59
        $this->request->setRequestMethod('BUTTHEAD');
60
        $this->assertEquals('BUTTHEAD', HttpRequest::getRequestMethod());
61
    }
62
63
    public function testMethodisGET()
64
    {
65
        $this->request->setRequestMethod('GET');
66
        $this->assertTrue($this->request->isGet());
67
    }
68
69
    public function testMethodisPOST()
70
    {
71
        $this->request->setRequestMethod('POST');
72
        $this->assertTrue($this->request->isPost());
73
    }
74
75
    public function testMethodisPUT()
76
    {
77
        $this->request->setRequestMethod('PUT');
78
        $this->assertTrue($this->request->isPut());
79
    }
80
81
    public function testMethodisDELETE()
82
    {
83
        $this->request->setRequestMethod('DELETE');
84
        $this->assertTrue($this->request->isDelete());
85
    }
86
87
    public function testMethodisAjax()
0 ignored issues
show
testMethodisAjax 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...
88
    {
89
        $isAjax = $this->request->isAjax();
90
        $this->assertFalse($isAjax);
91
92
        $_SERVER['X-Requested-With'] = 'XMLHttpRequest';
93
        $isAjax                      = $this->request->isAjax();
94
        $this->assertTrue($isAjax);
95
96
        $_SERVER['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest';
97
        $isAjax                           = $this->request->isAjax();
98
        $this->assertTrue($isAjax);
99
100
        unset($_SERVER['X-Requested-With']);
101
        unset($_SERVER['HTTP_X_REQUESTED_WITH']);
102
    }
103
104
    /*public function testMethodgetPost()
0 ignored issues
show
Unused Code Comprehensibility introduced by
57% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
105
    {
106
        $_POST['POST-ABC'] = '123';
107
        $result = $this->request->getPost();
108
        $this->assertArrayHasKey('POST-ABC', $result);
109
110
        // ArrayAccess via offsetExists
111
        $this->assertEquals($this->request['POST-ABC'], '123');
112
    }
113
114
    public function testMethodgetGet()
115
    {
116
        $_GET['GET-ABC'] = '123';
117
        $result = $this->request->getGET();
118
        $this->assertArrayHasKey('GETABC', $result);
119
    }*/
120
121
    public function testMethodgetServerProtocol()
0 ignored issues
show
testMethodgetServerProtocol 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...
122
    {
123
        $this->assertEquals($this->request->getServerProtocol(), 'http://');
124
125
        $_SERVER['HTTPS'] = 'on';
126
        $this->assertEquals($this->request->getServerProtocol(), 'https://');
127
    }
128
129
    public function testMethodIsSecure()
0 ignored issues
show
testMethodIsSecure 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...
130
    {
131
        $_SERVER['HTTPS'] = 'NO';
132
        $this->assertFalse($this->request->isSecure());
133
134
        $_SERVER['HTTPS'] = '1';
135
        $this->assertTrue($this->request->isSecure());
136
    }
137
138
    public function testMethodgetBaseURL()
0 ignored issues
show
testMethodgetBaseURL 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...
139
    {
140
        $_SERVER['HTTPS']       = 'off';
141
        $_SERVER['SERVER_NAME'] = 'localhost';
142
        $_SERVER['SERVER_PORT'] = 80;
143
        $this->assertEquals($this->request->getBaseURL(), 'http://localhost');
144
145
        /*$_SERVER['HTTPS'] = 'on';
0 ignored issues
show
Unused Code Comprehensibility introduced by
64% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
146
        $_SERVER['SERVER_NAME'] = 'localhost';
147
        $_SERVER['SERVER_PORT'] = 123;
148
        $this->assertEquals($this->request->getBaseURL(), 'https://localhost:123');
149
150
        $_SERVER['HTTPS'] = 'on';
151
        $_SERVER['SERVER_NAME'] = 'localhost';
152
        $_SERVER['SERVER_PORT'] = 443;
153
        $this->assertEquals($this->request->getBaseURL(), 'https://localhost');*/
154
    }
155
156
    public function testMethodgetServerName()
0 ignored issues
show
testMethodgetServerName 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...
157
    {
158
        $name                   = 'ServerName';
159
        $_SERVER['SERVER_NAME'] = $name;
160
        $this->assertEquals($this->request->getServerName(), $name);
161
    }
162
}
163