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/CacheMiddleware.php (7 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
declare(strict_types=1);
3
4
/**
5
 * This file is part of phpDocumentor.
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @author    Mike van Riel <[email protected]>
11
 * @copyright 2010-2018 Mike van Riel / Naenius (http://www.naenius.com)
12
 * @license   http://www.opensource.org/licenses/mit-license.php MIT
13
 * @link      http://phpdoc.org
14
 */
15
16
namespace phpDocumentor\Parser\Middleware;
17
18
use phpDocumentor\Parser\Parser;
19
use phpDocumentor\Reflection\Middleware\Command;
20
use phpDocumentor\Reflection\Middleware\Middleware;
21
use phpDocumentor\Reflection\Php\Factory\File\CreateCommand;
22
use phpDocumentor\Reflection\Php\File;
23
use Stash\Interfaces\PoolInterface;
24
use Stash\Item;
25
use Stash\Pool;
26
27
final class CacheMiddleware implements Middleware
28
{
29
    /**
30
     * Cache namespace used for this repository.
31
     */
32
    const CACHE_NAMESPACE = 'Documentation\\Api\\Php';
33
34
    /**
35
     * Cache pool used to store files.
36
     *
37
     * @var Pool
38
     */
39
    private $dataStore;
40
41
    /**
42
     * @var Parser
43
     */
44
    private $parser;
45
46 5
    public function __construct(PoolInterface $dataStore, Parser $parser)
47
    {
48 5
        $this->dataStore = $dataStore;
0 ignored issues
show
Documentation Bug introduced by
$dataStore is of type object<Stash\Interfaces\PoolInterface>, but the property $dataStore was declared to be of type object<Stash\Pool>. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
49 5
        $this->parser = $parser;
50 5
    }
51
52
    /**
53
     * Executes this middle ware class.
54
     * A middle ware class MUST return a File object or call the $next callable.
55
     *
56
     * @param CreateCommand $command
57
     * @param callable $next
58
     *
59
     * @return File
60
     */
61 5
    public function execute(Command $command, callable $next)
62
    {
63 5
        $itemName = $this->getItemName($command->getFile()->path());
64 5
        $item = $this->dataStore->getItem($itemName);
65 5
        if ($item->isMiss() || $this->parser->isForced()) {
66 2
            return $this->updateCache($command, $next, $item);
0 ignored issues
show
$command of type object<phpDocumentor\Ref...ion\Middleware\Command> is not a sub-type of object<phpDocumentor\Ref...ory\File\CreateCommand>. It seems like you assume a concrete implementation of the interface phpDocumentor\Reflection\Middleware\Command to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
$item of type object<Stash\Interfaces\ItemInterface> is not a sub-type of object<Stash\Item>. It seems like you assume a concrete implementation of the interface Stash\Interfaces\ItemInterface to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
67
        }
68
69
        /** @var File $cachedFile */
70 3
        $cachedFile = $item->get();
71
72 3
        if ($cachedFile === null) {
73 1
            return $this->updateCache($command, $next, $item);
0 ignored issues
show
$command of type object<phpDocumentor\Ref...ion\Middleware\Command> is not a sub-type of object<phpDocumentor\Ref...ory\File\CreateCommand>. It seems like you assume a concrete implementation of the interface phpDocumentor\Reflection\Middleware\Command to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
$item of type object<Stash\Interfaces\ItemInterface> is not a sub-type of object<Stash\Item>. It seems like you assume a concrete implementation of the interface Stash\Interfaces\ItemInterface to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
74
        }
75
76 2
        if ($cachedFile->getHash() !== $command->getFile()->md5()) {
77 1
            return $this->updateCache($command, $next, $item);
0 ignored issues
show
$command of type object<phpDocumentor\Ref...ion\Middleware\Command> is not a sub-type of object<phpDocumentor\Ref...ory\File\CreateCommand>. It seems like you assume a concrete implementation of the interface phpDocumentor\Reflection\Middleware\Command to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
$item of type object<Stash\Interfaces\ItemInterface> is not a sub-type of object<Stash\Item>. It seems like you assume a concrete implementation of the interface Stash\Interfaces\ItemInterface to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
78
        }
79
80 1
        return $cachedFile;
81
    }
82
83
    /**
84
     * @param callable $next
85
     * @param Item $item
86
     * @return mixed
87
     */
88 4
    private function updateCache(CreateCommand $command, callable $next, $item)
89
    {
90 4
        $file = $next($command);
91 4
        $item->lock();
92 4
        $this->dataStore->save($item->set($file));
93 4
        return $file;
94
    }
95
96
    /**
97
     * Convert path to ItemName
98
     *
99
     * @param string $path
100
     * @return string
101
     */
102 5
    private function getItemName($path)
103
    {
104 5
        return static::CACHE_NAMESPACE . '\\' . md5($path);
105
    }
106
}
107