Issues (9)

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/Service.php (5 issues)

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
 * Opine\Cache
4
 *
5
 * Copyright (c)2013, 2014 Ryan Mahoney, https://github.com/Opine-Org <[email protected]>
6
 *
7
 * Permission is hereby granted, free of charge, to any person obtaining a copy
8
 * of this software and associated documentation files (the "Software"), to deal
9
 * in the Software without restriction, including without limitation the rights
10
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
 * copies of the Software, and to permit persons to whom the Software is
12
 * furnished to do so, subject to the following conditions:
13
 *
14
 * The above copyright notice and this permission notice shall be included in
15
 * all copies or substantial portions of the Software.
16
 *
17
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
 * THE SOFTWARE.
24
 */
25
namespace Opine\Cache;
26
27
use Exception;
28
use Closure;
29
use Opine\Interfaces\Cache as CacheInterface;
30
use Symfony\Component\Yaml\Yaml;
31
32
class Service implements CacheInterface
33
{
34
    private $engine;
35
    private $host = false;
36
    private $port = false;
37
    private $root;
38
39 8
    public function __construct($root)
40
    {
41 8
        $this->root = $root;
42
43
        // determine config environment
44 8
        $environment = 'default';
45 8
        $test = getenv('OPINE_ENV');
46 8
        if ($test !== false) {
47
            $environment = $test;
48
        }
49 8
        if ($environment == 'default') {
50 8
            $environment = '.';
51
        }
52
53 8
        if (class_exists('\Memcache')) {
54
            // determine path of file
55
            $path = $root . '/../config/settings/' . $environment . '/cache.yml';
56
            if (!file_exists($path)) {
57
                $path = $root . '/config/settings/cache.yml';
58
            }
59
            if (!file_exists($path)) {
60
                $path = $root . '/../config/settings/cache.yml';
61
            }
62
            if (!file_exists($path)) {
63
                fwrite(STDERR, print_r([
64
                    $root, $path
65
                ], TRUE));
66
                return;
67
            }
68
69
            // read configuration
70
            $config = Yaml::parse(file_get_contents($path));
71
            $this->host = $config['settings']['host'];
72
            $this->port = $config['settings']['port'];
73
            $this->engine = new \Memcache();
74
            return;
75
        }
76 8
        $this->engine = new FileCache($this->root);
77 8
    }
78
79 1
    public function delete($key, $timeout = 0)
80
    {
81 1
        $result = @$this->engine->pconnect($this->host, $this->port);
82 1
        if ($result === false) {
83
            return false;
84
        }
85
86 1
        return $this->engine->delete($key, $timeout);
0 ignored issues
show
The call to FileCache::delete() has too many arguments starting with $timeout.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
87
    }
88
89 1
    public function set($key, $value, $expire = 0, $flag = 2)
90
    {
91 1
        $result = @$this->engine->pconnect($this->host, $this->port);
92 1
        if ($result === false) {
93
            return false;
94
        }
95
96 1
        return $this->engine->set($key, $value, $flag, $expire);
97
    }
98
99 4
    public function get($key, $flag = 2)
100
    {
101 4
        $result = @$this->engine->pconnect($this->host, $this->port);
102 4
        if ($result === false) {
103
            return false;
104
        }
105
106 4
        return $this->engine->get($key, $flag);
0 ignored issues
show
The call to FileCache::get() has too many arguments starting with $flag.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
107
    }
108
109 1
    public function getSetGet($key, Closure $callback, $ttl = 0, $flag = 2)
110
    {
111 1
        $result = @$this->engine->pconnect($this->host, $this->port);
112 1
        if ($result === false) {
113
            return false;
114
        }
115 1
        $data = $this->engine->get($key, $flag);
0 ignored issues
show
The call to FileCache::get() has too many arguments starting with $flag.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
116 1
        if ($data === false) {
117 1
            $data = $callback();
118 1
            if ($data !== false) {
119 1
                $this->engine->set($key, $data, $flag, $ttl);
120
            }
121
        }
122
123 1
        return $data;
124
    }
125
126 2
    public function getSetGetBatch(Array &$items, $ttl = 0, $flag = 2)
127
    {
128 2
        foreach ($items as $item) {
129 2
            if (!is_callable($item)) {
130 2
                throw new Exception('each item must have a callback defined');
131
            }
132
        }
133 1
        $result = @$this->engine->pconnect($this->host, $this->port);
134 1
        if ($result === false) {
135
            return false;
136
        }
137 1
        $data = $this->engine->get(array_keys($items));
138 1
        foreach ($items as $key => &$item) {
139 1
            if (!isset($data[$key]) || $data[$key] === false) {
140 1
                $items[$key] = $item();
141
            } else {
142 1
                $items[$key] = $data[$key];
143
            }
144 1
            if ($items[$key] !== false) {
145 1
                $this->engine->set($key, $items[$key], $flag, $ttl);
146
            }
147
        }
148
149 1
        return true;
150
    }
151
152 1
    public function getBatch(Array &$items, $flag = 2)
153
    {
154 1
        $count = sizeof($items);
155 1
        $result = @$this->engine->pconnect($this->host, $this->port);
156 1
        if ($result === false) {
157
            return false;
158
        }
159 1
        $data = $this->engine->get(array_keys($items), $flag);
0 ignored issues
show
The call to FileCache::get() has too many arguments starting with $flag.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
160 1
        $hits = 0;
161 1
        foreach ($items as $key => $item) {
162 1
            if (array_key_exists($key, $data)) {
163 1
                $items[$key] = $data[$key];
164 1
                $hits++;
165
            }
166
        }
167 1
        return $hits == $count;
168
    }
169
170 1
    public function deleteBatch(Array $items, $timeout = 0)
171
    {
172 1
        $result = @$this->engine->pconnect($this->host, $this->port);
173 1
        if ($result === false) {
174
            return false;
175
        }
176 1
        foreach ($items as $item) {
177 1
            $this->engine->delete($item, $timeout);
0 ignored issues
show
The call to FileCache::delete() has too many arguments starting with $timeout.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
178
        }
179
180 1
        return true;
181
    }
182
}
183