Issues (20)

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.

RequestParameter/ExtractCSRFParameterTest.php (1 issue)

Labels
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
declare(strict_types=1);
4
5
namespace PSR7CsrfTest\RequestParameter;
6
7
use PHPUnit\Framework\TestCase;
8
use Psr\Http\Message\ServerRequestInterface;
9
use PSR7Csrf\Exception\InvalidRequestParameterNameException;
10
use PSR7Csrf\RequestParameter\ExtractCSRFParameter;
11
12
/**
13
 * @covers \PSR7Csrf\RequestParameter\ExtractCSRFParameter
14
 */
15
final class ExtractCSRFParameterTest extends TestCase
16
{
17
    public function testRejectsEmptyRequestParameterName()
18
    {
19
        $this->expectException(InvalidRequestParameterNameException::class);
20
21
        new ExtractCSRFParameter('');
22
    }
23
24
    /**
25
     * @dataProvider requestBodyProvider
26
     *
27
     * @param string            $requestParameter
28
     * @param null|object|array $body
29
     * @param string            $expectedExtractedValue
30
     *
31
     * @return void
32
     */
33
    public function testExtraction(string $requestParameter, $body, string $expectedExtractedValue)
34
    {
35
        /* @var $request ServerRequestInterface|\PHPUnit_Framework_MockObject_MockObject */
36
        $request = $this->createMock(ServerRequestInterface::class);
37
38
        $request->expects(self::any())->method('getParsedBody')->willReturn($body);
39
40
        self::assertSame($expectedExtractedValue, (new ExtractCSRFParameter($requestParameter))->__invoke($request));
0 ignored issues
show
It seems like $request defined by $this->createMock(\Psr\H...equestInterface::class) on line 36 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, PSR7Csrf\RequestParamete...RFParameter::__invoke() does only seem to accept object<Psr\Http\Message\ServerRequestInterface>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
41
    }
42
43
    public function requestBodyProvider()
44
    {
45
        /** @noinspection PhpUnusedPrivateFieldInspection */
46
        return [
47
            'null body' => [
48
                'request parameter name',
49
                null,
50
                '',
51
            ],
52
            'empty array' => [
53
                'request parameter name',
54
                [],
55
                '',
56
            ],
57
            'empty object' => [
58
                'request parameter name',
59
                (object) [],
60
                '',
61
            ],
62
            'array with matching parameter' => [
63
                'request parameter name',
64
                ['request parameter name' => 'foo'],
65
                'foo',
66
            ],
67
            'array with matching non-string parameter' => [
68
                'request parameter name',
69
                ['request parameter name' => 123],
70
                '',
71
            ],
72
            'object with matching parameter' => [
73
                'request parameter name',
74
                (object) ['request parameter name' => 'foo'],
75
                'foo',
76
            ],
77
            'object with matching non-string parameter' => [
78
                'request parameter name',
79
                (object) ['request parameter name' => 123],
80
                '',
81
            ],
82
            'class with private matching property' => [
83
                'field',
84
                new class {
85
                    private $field = 'bar';
86
                },
87
                '',
88
            ],
89
            'class with protected matching property' => [
90
                'field',
91
                new class {
92
                    protected $field = 'bar';
93
                },
94
                '',
95
            ],
96
            'class with public matching property' => [
97
                'field',
98
                new class {
99
                    public $field = 'bar';
100
                },
101
                'bar',
102
            ],
103
            'class with public matching non-string property' => [
104
                'field',
105
                new class {
106
                    public $field = 123;
107
                },
108
                '',
109
            ],
110
        ];
111
    }
112
}
113