Issues (387)

Branch: develop

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.

Parser/Middleware/CacheMiddlewareTest.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 declare(strict_types=1);
2
/**
3
 * This file is part of phpDocumentor.
4
 *
5
 *  For the full copyright and license information, please view the LICENSE
6
 *  file that was distributed with this source code.
7
 *
8
 *  @copyright 2010-2018 Mike van Riel<[email protected]>
9
 *  @license   http://www.opensource.org/licenses/mit-license.php MIT
10
 *  @link      http://phpdoc.org
11
 */
12
13
namespace phpDocumentor\Parser\Middleware;
14
15
use Mockery as m;
16
use phpDocumentor\Parser\Parser;
17
use phpDocumentor\Reflection\File as SourceFile;
18
use phpDocumentor\Reflection\Php\Factory\File\CreateCommand;
19
use phpDocumentor\Reflection\Php\File;
20
use phpDocumentor\Reflection\Php\ProjectFactoryStrategies;
21
use phpDocumentor\Reflection\Php\StrategyContainer;
22
use Stash\Item;
23
use Stash\Pool;
24
25
/**
26
 * @coversDefaultClass \phpDocumentor\Parser\Middleware\CacheMiddleware
27
 * @covers ::<private>
28
 * @covers ::__construct
29
 */
30
final class CacheMiddlewareTest extends \Mockery\Adapter\Phpunit\MockeryTestCase
31
{
32
    /**
33
     * @covers ::execute
34
     * @uses \phpDocumentor\Reflection\Php\Factory\File\CreateCommand
35
     * @uses \phpDocumentor\Reflection\Php\File
36
     */
37
    public function testCachedFileIsReturnedWhenValid()
38
    {
39
        $commandFile = new SourceFile\LocalFile(__FILE__);
40
        $file = new File($commandFile->md5(), __FILE__);
41
42
        $poolMock = m::mock(Pool::class);
43
        $poolMock->shouldReceive('getItem')->andReturnSelf();
44
        $poolMock->shouldReceive('getItem->isMiss')->andReturn(false);
45
        $poolMock->shouldReceive('getItem->get')->andReturn($file);
46
        $poolMock->shouldReceive('getItem->lock')->never();
47
        $poolMock->shouldReceive('getItem->set')->never();
48
        $poolMock->shouldReceive('save')->never();
49
50
        $command = new CreateCommand($commandFile, new ProjectFactoryStrategies([]));
51
        $parserMock = m::mock(Parser::class);
52
        $parserMock->shouldReceive('isForced')->andReturn(false);
53
54
        $fixture = new CacheMiddleware($poolMock, $parserMock);
55
56
        $result = $fixture->execute($command, function () {
57
            $this->fail('Parsing should not be done, the cached item should be returned');
58
        });
59
60
        $this->assertSame($file, $result);
61
    }
62
63
    /**
64
     * @covers ::execute
65
     * @uses \phpDocumentor\Reflection\Php\Factory\File\CreateCommand
66
     * @uses \phpDocumentor\Reflection\Php\File
67
     */
68
    public function testCachedFileIsUpdatedWhenForced()
69
    {
70
        $commandFile = new SourceFile\LocalFile(__FILE__);
71
        $file = new File($commandFile->md5(), __FILE__);
72
        $item = new Item();
73
74
        $poolMock = m::mock(Pool::class);
75
        $poolMock->shouldReceive('getItem')->andReturnSelf();
76
        $poolMock->shouldReceive('getItem->isMiss')->andReturn(false);
77
        $poolMock->shouldReceive('getItem->get')->andReturn($file);
78
        $poolMock->shouldReceive('getItem->lock')->once();
79
        $poolMock->shouldReceive('getItem->set')->andReturn($item)->with($file);
80
        $poolMock->shouldReceive('save')->with($item);
81
82
        $command = new CreateCommand($commandFile, new ProjectFactoryStrategies([]));
83
        $parserMock = m::mock(Parser::class);
84
        $parserMock->shouldReceive('isForced')->andReturn(true);
85
86
        $fixture = new CacheMiddleware($poolMock, $parserMock);
87
88
        $result = $fixture->execute($command, function () use ($file) {
89
            return $file;
90
        });
91
92
        $this->assertSame($file, $result);
93
    }
94
95
    /**
96
     * @covers ::execute
97
     * @uses \phpDocumentor\Reflection\Php\Factory\File\CreateCommand
98
     * @uses \phpDocumentor\Reflection\Php\File
99
     */
100
    public function testCacheIsUpdatedOnAMiss()
101
    {
102
        $file = new File('hash', 'myFile.php');
103
        $item = new Item();
104
        $poolMock = m::mock(Pool::class);
105
        $poolMock->shouldReceive('getItem')->andReturnSelf();
106
        $poolMock->shouldReceive('getItem->isMiss')->andReturn(true);
107
        $poolMock->shouldReceive('getItem->lock')->once();
108
        $poolMock->shouldReceive('getItem->set')->andReturn($item)->with($file);
109
        $poolMock->shouldReceive('getItem->get')->never();
110
        $poolMock->shouldReceive('save')->with($item);
111
112
        $sourceFile = m::mock(SourceFile::class);
113
        $sourceFile->shouldReceive('path')->andReturn('myFile.php');
114
        $stategies = m::mock(StrategyContainer::class);
115
        $command = new CreateCommand($sourceFile, $stategies);
116
        $fixture = new CacheMiddleware($poolMock, m::mock(Parser::class));
117
118
        $result = $fixture->execute($command, function () use ($file) {
119
            return $file;
120
        });
121
122
        $this->assertSame($file, $result);
123
    }
124
125
    /**
126
     * @covers ::execute
127
     * @uses \phpDocumentor\Reflection\Php\Factory\File\CreateCommand
128
     * @uses \phpDocumentor\Reflection\Php\File
129
     */
130
    public function testCacheFileIfItIsNotInThePool()
131
    {
132
        $freshFile = new File('NewHash', 'myFile.php');
133
134
        $item = new Item();
135
        $poolMock = m::mock(Pool::class);
136
        $poolMock->shouldReceive('getItem')
137
            ->andReturnSelf();
138
139
        $poolMock->shouldReceive('getItem->isMiss')
140
            ->once()
141
            ->andReturn(false);
142
143
        $poolMock->shouldReceive('getItem->lock')
144
            ->once();
145
146
        $poolMock->shouldReceive('getItem->set')
147
            ->once()
148
            ->with($freshFile)
149
            ->andReturn($item);
150
151
        $poolMock->shouldReceive('getItem->get')
152
            ->once()
153
            ->andReturn(null);
154
155
        $poolMock->shouldReceive('save')->with($item);
156
157
        $sourceFile = m::mock(SourceFile::class);
158
        $sourceFile->shouldReceive('path')->andReturn('myFile.php');
0 ignored issues
show
The method andReturn does only exist in Mockery\ExpectationInterface, but not in Mockery\HigherOrderMessage.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
159
        $sourceFile->shouldReceive('md5')
160
            ->andReturn('NewHash');
161
        $stategies = m::mock(StrategyContainer::class);
162
        $parser = m::mock(Parser::class);
163
        $parser->shouldReceive('isForced')->andReturn(false);
164
165
        $command = new CreateCommand($sourceFile, $stategies);
166
        $fixture = new CacheMiddleware($poolMock, $parser);
167
168
        $result = $fixture->execute($command, function () use ($freshFile) {
169
            return $freshFile;
170
        });
171
172
        $this->assertSame($freshFile, $result);
173
    }
174
175
    /**
176
     * @covers ::execute
177
     * @uses \phpDocumentor\Reflection\Php\Factory\File\CreateCommand
178
     * @uses \phpDocumentor\Reflection\Php\File
179
     */
180
    public function testCacheNewFileIfHashMismatches()
181
    {
182
        $cachedFile = new File('OldHash', 'myFile.php');
183
        $freshFile = new File('NewHash', 'myFile.php');
184
        $item = new Item();
185
        $poolMock = m::mock(Pool::class);
186
        $poolMock->shouldReceive('getItem')
187
            ->andReturnSelf();
188
189
        $poolMock->shouldReceive('getItem->isMiss')
190
            ->once()
191
            ->andReturn(false);
192
193
        $poolMock->shouldReceive('getItem->lock')
194
            ->once();
195
196
        $poolMock->shouldReceive('getItem->set')
197
            ->once()
198
            ->with($freshFile)
199
            ->andReturn($item);
200
201
        $poolMock->shouldReceive('getItem->get')
202
            ->once()
203
            ->andReturn($cachedFile);
204
205
        $poolMock->shouldReceive('save')->with($item);
206
207
        $sourceFile = m::mock(SourceFile::class);
208
        $sourceFile->shouldReceive('path')->andReturn('myFile.php');
0 ignored issues
show
The method andReturn does only exist in Mockery\ExpectationInterface, but not in Mockery\HigherOrderMessage.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
209
        $sourceFile->shouldReceive('md5')
210
            ->andReturn('NewHash');
211
        $stategies = m::mock(StrategyContainer::class);
212
        $parser = m::mock(Parser::class);
213
        $parser->shouldReceive('isForced')->andReturn(false);
214
215
        $command = new CreateCommand($sourceFile, $stategies);
216
        $fixture = new CacheMiddleware($poolMock, $parser);
217
218
        $result = $fixture->execute($command, function () use ($freshFile) {
219
            return $freshFile;
220
        });
221
222
        $this->assertSame($freshFile, $result);
223
    }
224
}
225