Issues (3)

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.

src/Helper/OpcacheResetCommandHelper.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
namespace Timegryd\OpcacheResetBundle\Helper;
4
5
use Symfony\Component\HttpKernel\KernelInterface;
6
use Symfony\Component\HttpFoundation\Response;
7
use Symfony\Component\Filesystem\Filesystem;
8
use GuzzleHttp\Psr7\Response as HttpResponse;
9
10
class OpcacheResetCommandHelper
11
{
12
    const FILE_NAME_MODEL = 'opcache-reset-%s.php';
13
14
    /**
15
     * @var KernelInterface
16
     */
17
    protected $kernel;
18
19
    public function __construct(KernelInterface $kernel)
20
    {
21
        $this->kernel = $kernel;
22
    }
23
24
    /**
25
     * Return generated file name.
26
     *
27
     * @param string $replacement
28
     *
29
     * @return string
30
     */
31
    public function getFileName($replacement)
32
    {
33
        return sprintf(self::FILE_NAME_MODEL, $replacement);
34
    }
35
36
    /**
37
     * Return generated file path.
38
     *
39
     * @param string $dir
40
     * @param string $replacement
41
     *
42
     * @return string
43
     */
44
    public function getFilePath($dir, $replacement)
45
    {
46
        return sprintf('%s/%s', $dir, $this->getFileName($replacement));
47
    }
48
49
    /**
50
     * Generate url with given host and token.
51
     *
52
     * @param string $host
53
     * @param string $token
54
     *
55
     * @return string
56
     */
57
    public function generateUrl($host, $token)
58
    {
59
        return sprintf('%s/%s', $host, $this->getFileName($token));
60
    }
61
62
    /**
63
     * Create file in given directory.
64
     *
65
     * @param string $dir
66
     * @param string $token
67
     *
68
     * @return OpcacheResetCommandHelper
69
     */
70
    public function createFile($dir, $token)
71
    {
72
        if (!is_dir($dir)) {
73
            throw new \RuntimeException(sprintf('Web directory does not exists : %s', $dir));
74
        }
75
76
        $templatePath = $this->kernel->locateResource('@TimegrydOpcacheResetBundle/Resources/template/opcacheReset.php');
77
78
        $fileSystem = new FileSystem();
79
80
        $fileSystem->copy(
81
            $templatePath,
0 ignored issues
show
It seems like $templatePath defined by $this->kernel->locateRes...late/opcacheReset.php') on line 76 can also be of type array; however, Symfony\Component\Filesystem\Filesystem::copy() does only seem to accept string, 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...
82
            $this->getFilePath($dir, $token)
83
        );
84
85
        return $this;
86
    }
87
88
    /**
89
     * Remove all opcache reset files.
90
     *
91
     * @param string $dir
92
     *
93
     * @return OpcacheResetCommandHelper
94
     */
95
    public function clean($dir)
96
    {
97
        array_map('unlink', glob($this->getFilePath($dir, '*')));
98
99
        return $this;
100
    }
101
102
    /**
103
     * Handle given response and return message from it.
104
     *
105
     * @param HttpResponse $response
106
     *
107
     * @return string
108
     */
109
    public function handleResponse(HttpResponse $response)
110
    {
111
        if (Response::HTTP_OK !== $response->getStatusCode()) {
112
            throw new \RuntimeException('Unable to access url');
113
        }
114
115
        $result = json_decode($response->getBody());
116
117
        if (null === $result) {
118
            throw new \RuntimeException('Unable to decode json response.');
119
        }
120
121
        if (!property_exists($result, 'success')) {
122
            throw new \InvalidArgumentException('"success" property is missing in returned json.');
123
        }
124
125
        if (!property_exists($result, 'message')) {
126
            throw new \InvalidArgumentException('"message" property is missing in returned json.');
127
        }
128
129
        if (false === $result->success) {
130
            throw new \RuntimeException($result->message);
131
        }
132
133
        return $result->message;
134
    }
135
}
136