Issues (1)

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/BaseManager.php (1 issue)

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
 * Created by PhpStorm.
4
 * User: jaredchu
5
 * Date: 04/08/2017
6
 * Time: 11:36
7
 */
8
9
namespace JC\Cache;
10
11
/**
12
 * Class CacheManager
13
 * @package JC
14
 *
15
 * Manage the list of caching file and object
16
 * Save in $cFilename
17
 */
18
abstract class BaseManager
19
{
20
    /**
21
     * @var string
22
     */
23
    protected static $cFileName;
24
25
    /**
26
     * @param $cFileName
27
     */
28
    public static function setCFileName($cFileName)
29
    {
30
        static::$cFileName = $cFileName;
31
    }
32
33
    /**
34
     * @return string
35
     */
36
    public static function getCFileName()
37
    {
38
        return static::$cFileName;
39
    }
40
41
    /**
42
     * @return string
43
     *
44
     * Return absolute file path which store cache list
45
     */
46
    public static function getCFilePath()
47
    {
48
        return sys_get_temp_dir() . '/' . static::getCFileName();
49
    }
50
51
    /**
52
     * Unique string for each server
53
     * @param string $salt
54
     * @return string
55
     */
56
    public static function getUniqueString($salt = '')
0 ignored issues
show
getUniqueString uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
57
    {
58
        $uniqueString = isset($_SERVER['SERVER_SIGNATURE']) ? $_SERVER['SERVER_SIGNATURE'] . __DIR__ : __DIR__;
59
        return md5($uniqueString . $salt);
60
    }
61
62
    /**
63
     * @param $key
64
     * @return bool|string
65
     *
66
     * Return absolute file path of caching object
67
     */
68
    public static function get($key)
69
    {
70
        $cacheList = static::getCacheList();
71
        if (isset($cacheList[$key])) {
72
            if (($cacheList[$key][0] == 0 || $cacheList[$key][0] >= time())) {
73
                return $cacheList[$key][1];
74
            } else {
75
                unlink($cacheList[$key][1]);
76
                static::remove($key);
77
            }
78
        }
79
80
        return false;
81
    }
82
83
    /**
84
     * @param $key
85
     * @param $filePath
86
     * @return bool
87
     *
88
     * Save $key and $filePath in cacheList
89
     */
90
    public static function set($key, $filePath, $ttl)
91
    {
92
        $cacheList = static::getCacheList();
93
94
        if ($ttl != 0) {
95
            $ttl += time();
96
        }
97
        $cacheList[$key] = [$ttl, $filePath];
98
99
        return static::setCacheList($cacheList);
100
    }
101
102
    /**
103
     * @param $key
104
     * @return bool
105
     *
106
     * Remove caching object file and remove from cache list
107
     */
108
    public static function remove($key)
109
    {
110
        $cacheList = static::getCacheList();
111
        unset($cacheList[$key]);
112
113
        return static::setCacheList($cacheList);
114
    }
115
116
    /**
117
     * @param $key
118
     * @return bool
119
     */
120
    public static function has($key)
121
    {
122
        $cacheList = static::getCacheList();
123
        if (is_array($cacheList)) {
124
            return array_key_exists($key, $cacheList);
125
        }
126
127
        return false;
128
    }
129
130
    /**
131
     * @return array
132
     *
133
     * Return cache list in array
134
     */
135
    protected static function getCacheList()
136
    {
137
        if (file_exists(static::getCFilePath())) {
138
            return static::decode(file_get_contents(static::getCFilePath()));
139
        }
140
141
        return array();
142
    }
143
144
    /**
145
     * @param $cacheList
146
     * @return bool
147
     */
148
    protected static function setCacheList($cacheList)
149
    {
150
        return (bool)file_put_contents(static::getCFilePath(), static::encode($cacheList));
151
    }
152
153
    /**
154
     * @param $array
155
     * @return string
156
     */
157
    protected static function encode($array)
158
    {
159
        return json_encode($array);
160
    }
161
162
    /**
163
     * @param $string
164
     * @return array
165
     */
166
    protected static function decode($string)
167
    {
168
        return json_decode($string, true);
169
    }
170
}