Issues (18)

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.

includes/OPCache/OPCache.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
2
3
namespace OPCache;
4
5
use OPCache\FCGIRequest;
6
use OPCache\HTTPRequest;
7
use OPCache\OPCacheConfiguration;
8
use OPCache\OPCacheStatus;
9
10
class OPCache {
11
12
  private $queryString;
13
  private $scripts;
14
  private $servers;
15
  private $uri;
16
17
  public function __construct() {
18
    $this->servers = variable_get('opcache_backends', NULL);
19
  }
20
21
  private function buildQueryString($params) {
22
    $this->buildUri($params);
23
    $this->queryString = 'q=' . $this->uri;
24
  }
25
26
  private function buildUri($params) {
27
    $token = $this->getToken();
28
    $this->uri = 'opcache/' . REQUEST_TIME . '/' . $token . '/' . $params['op'];
29
    if (isset($params['script'])) {
30
      $this->uri .= '/' . $params['script'];
31
    }
32
    if ($params['op'] == 'reset' && $params['all']) {
33
      $this->uri .= '/all';
34
    }
35
  }
36
37
  public function cacheClear() {
38
    if (!$this->servers) {
39
      return $this->reset();
40
    }
41
42
    // Multiple backends must be cleared.
43
    $params = [];
44
    $params['op'] = 'reset';
45
    $this->multiBackendRequest($params);
46
  }
47
48
  public function config() {
49
    $config = new OPCacheConfiguration();
50
    return $config->getDirectives();
51
  }
52
53
  private function drushBuildUrl($server, $params) {
54
    $this->buildQueryString($params);
55
    $url = "{$server}?{$this->queryString}";
56
    return $url;
57
  }
58
59
  public function drushInvalidate($script) {
60
    $params = array();
61
    $params['op'] = 'invalidate';
62
    $params['script'] = $script;
63
    $this->drushRequest($params);
64
  }
65
66
  public function drushReset($all) {
67
    $params = array();
68
    $params['op'] = 'reset';
69
    $params['all'] = $all;
70
    $this->drushRequest($params);
71
  }
72
73
  public function drushStatus() {
74
    $params = array();
75
    $params['op'] = 'status';
76
    return $this->drushRequest($params);
77
  }
78
79
  private function drushRequest($params = array()) {
80
    global $base_url;
81
    if (preg_match('/default$/', $base_url) && !$this->servers) {
82
      drush_log(dt("In order to properly reset the OPcache cache, please use the -l/--uri flag to specify the correct URL of this Drupal installation, or specify paths to the PHP proxy servers in the OPcache module's settings form."), 'error');
83
      return;
84
    }
85
    if (!$this->servers) {
86
      $server = url('<front>', array('absolute' => TRUE));
87
      $this->httpRequest($server, $params);
88
    }
89
    else {
90
      $this->multiBackendRequest($params);
91
    }
92
  }
93
94
  private function fcgiRequest($server, $params) {
0 ignored issues
show
The parameter $params is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
95
    $fcgi = substr($server, 7);
96
    try {
97
      $command = new FCGIRequest($fcgi, $this->uri, $this->queryString);
98
      $command->run();
99
    } catch (\Exception $e) {
100
      watchdog('opcache', 'An error was encountered clearing OPCache on %server. Message: %error', array('%server' => $server, '%error' => $e->getMessage()), WATCHDOG_ERROR);
101
    }
102
  }
103
104
  private function getScripts() {
105
    $status = new OPCacheStatus(TRUE);
106
    $scripts = $status->getScripts();
107
    foreach ($scripts as $script) {
108
      if (strpos($script['full_path'], DRUPAL_ROOT) !== FALSE) {
109
        $this->scripts[] = $script['full_path'];
110
      }
111
    }
112
  }
113
114
  public function getToken($request_time = REQUEST_TIME) {
115
    return drupal_hmac_base64('opcache:' . $request_time, drupal_get_private_key() . drupal_get_hash_salt());
116
  }
117
118
  private function httpRequest($server, $params) {
119
    global $base_url;
120
    $urldata = @parse_url($base_url);
121
122
    $url = $this->drushBuildUrl($server, $params);
123
    try {
124
      $client = new HTTPRequest();
125
      $request = $client->createRequest('GET', $url);
0 ignored issues
show
The method createRequest() does not exist on OPCache\HTTPRequest. Did you maybe mean request()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
126
      $request->setHeader('Host', $urldata['host']);
127
      $response = $client->send($request);
128
      $status = $response->getStatusCode();
129
      $this->logResponse($server, $status, $params);
130
    } catch (\Exception $e) {
131
      watchdog('opcache', 'An error was encountered clearing OPCache on %server. Message: %error', array('%server' => $server, '%error' => $e->getMessage()), WATCHDOG_ERROR);
132
    }
133
  }
134
135
  public function isEnabled() {
136
    $status = new OPCacheStatus();
137
    $info = $status->getCurrentStatus();
138
    if ($info['opcache_enabled']) {
139
      return TRUE;
140
    }
141
  }
142
143
  public function invalidate($script, $force = FALSE) {
144
    return opcache_invalidate($script, $force);
145
  }
146
147
  public function invalidateMultiple(array $scripts, $force = FALSE) {
148
    $invalidation_counter = 0;
149
    if (!empty($scripts)) {
150
      foreach ($scripts as $script) {
151
        $this->invalidate($script, $force);
152
        $invalidation_counter++;
153
      }
154
155
      watchdog('opcache', '@scripts scripts were invalidated in OPCache.', array('@scripts' => $invalidation_counter), WATCHDOG_INFO);
156
    }
157
    else {
158
      watchdog('opcache', 'No scripts were available for invalidation in OPCache.', array(), WATCHDOG_INFO);
159
    }
160
  }
161
162
  private function logResponse($server, $status, $params) {
163
    switch ($status) {
164
      case 200:
165
        if ($params['op'] === 'reset') {
166
          watchdog('opcache', 'OPcache was reset at @server.', array('@server' => $server), WATCHDOG_INFO);
167
        }
168
        elseif ($params['op'] === 'invalidate') {
169
          watchdog('opcache', '@script was invalidated in OPcache at @server.', array('@script' => $params['script'], '@server' => $server), WATCHDOG_INFO);
170
        }
171
        break;
172
      case 404:
173
        watchdog('opcache', 'OPcache operation at @server failed; the reset path could not be found (404).', array('@server' => $server), WATCHDOG_ERROR);
174
        break;
175
      case 403:
176
        watchdog('opcache', 'OPcache operation at @server failed; access to the reset path was denied (403). This may happen if too much time elapsed during the request process. Please try again.', array('@server' => $server), WATCHDOG_ERROR);
177
        break;
178
      case 0:
179
        watchdog('opcache', 'OPcache operation at @server failed; server could not be reached.', array('@server' => $server), WATCHDOG_ERROR);
180
        break;
181
      default:
182
        watchdog('opcache', 'OPcache operation at @server failed; status code @code.', array('@server' => $server, '@code' => $status), WATCHDOG_ERROR);
183
    }
184
  }
185
186
  private function multiBackendRequest($params) {
187
    foreach ($this->servers as $server) {
188
      if (substr($server, 0, 7) == 'fcgi://') {
189
        $method = 'fcgiRequest';
190
      }
191
      else {
192
        $method = 'httpRequest';
193
      }
194
195
      $this->{$method}($server, $params);
196
    }
197
  }
198
199
  public function reset($all = FALSE) {
200
    if ($all) {
201
      return opcache_reset();
202
    }
203
204
    $this->getScripts();
205
    $this->invalidateMultiple($this->scripts, TRUE);
206
  }
207
208
  public function status() {
209
    $status = new OPCacheStatus();
210
    return $status->getStatusData();
211
  }
212
213
  public function verifyToken($request_time, $token) {
214
    return $token === $this->getToken($request_time);
215
  }
216
217
}
218