Issues (152)

Security Analysis    not enabled

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.

code/api/MysqlCache.php (5 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
 * to do: separate into MEMORY and NON-MEMORY
4
 *
5
 */
6
7 View Code Duplication
class MysqlCache extends Object implements flushable
0 ignored issues
show
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
8
{
9
    private static $cache_in_mysql_tables = array();
0 ignored issues
show
The property $cache_in_mysql_tables is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
10
11
    public static function flush()
12
    {
13
        $cache = SS_Cache::factory('any');
14
        $cache->clean(Zend_Cache::CLEANING_MODE_ALL);
15
        $tables = Config::inst()->get('EcommerceCache', 'cache_in_mysql_tables');
16
        if (is_array($tables)) {
17
            foreach ($tables as $table) {
18
                $table = self::make_mysql_table_name($table);
19
                DB::query(
20
                    '
21
                    DROP TABLE IF EXISTS "'.$table.'";
22
                    '
23
                );
24
                DB::query(
25
                    '
26
                    CREATE TABLE "'.$table.'" (
27
                      "PAGEID" int(11) NOT NULL,
28
                      "CACHEKEY" CHAR(50) NOT NULL,
29
                      "DATA" TEXT
30
                    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
31
                    '
32
                );
33
34
                DB::query(
35
                    '
36
                    ALTER TABLE "'.$table.'"
37
                      ADD PRIMARY KEY ("PAGEID","CACHEKEY"),
38
                      ADD KEY "CACHEKEY" ("CACHEKEY"),
39
                      ADD KEY "PAGEID" ("PAGEID");
40
                    '
41
                );
42
            }
43
        }
44
    }
45
46
    public static function clean()
47
    {
48
        $tables = Config::inst()->get('EcommerceCache', 'cache_in_mysql_tables');
49
        if (is_array($tables)) {
50
            foreach ($tables as $table) {
51
                $table = self::make_mysql_table_name($table);
52
                DB::query(
53
                    '
54
                    DELETE FROM "'.$table.'";
55
                    '
56
                );
57
            }
58
        }
59
    }
60
61
    private static $_items = array();
62
63
    /**
64
     * @param string           $table
65
     * @param int              $id
66
     * @param string           $cacheKey
67
     * @return mixed
68
     */
69
    public static function load($table, $id, $cacheKey)
70
    {
71
        $tables = Config::inst()->get('EcommerceCache', 'cache_in_mysql_tables');
72
        if (is_array($tables) && in_array($table, $tables)) {
73
            $table = self::make_mysql_table_name($table);
74
            $id = (int)$id;
75
            if (isset(self::$_items[$table])) {
76
                if (isset(self::$_items[$table][$id])) {
77
                    if (isset(self::$_items[$table][$id][$cacheKey])) {
78
                        if (self::$_items[$table][$id][$cacheKey] !== null) {
79
                            return @unserialize(self::$_items[$table][$id][$cacheKey]);
80
                        }
81
                    }
82
                }
83
            }
84
85
            //we are now loading the data ...
86
            if (!isset(self::$_items[$table])) {
87
                self::$_items[$table] = array();
88
            }
89
            if (! isset(self::$_items[$table][$id])) {
90
                self::$_items[$table][$id] = array();
91
                $rows = DB::query('SELECT "CACHEKEY", "DATA" FROM "'.$table.'" WHERE "PAGEID" = '.$id.' ;');
92
                foreach ($rows as $row) {
93
                    self::$_items[$table][$id][$row['CACHEKEY']] = $row['DATA'];
94
                }
95
                //return the value, if there is one.
96
                if (isset(self::$_items[$table][$id])) {
97
                    if (isset(self::$_items[$table][$id][$cacheKey])) {
98
                        return @unserialize(self::$_items[$table][$id][$cacheKey]);
99
                    }
100
                }
101
            }
102
        } else {
103
            $cache = SS_Cache::factory($table.'_'.$id);
104
            $data = $cache->load($cacheKey);
105
            if (!$data) {
106
                return;
107
            }
108
109
            return @unserialize($data);
110
        }
111
    }
112
113
    /**
114
     * @param string           $table
115
     * @param int              $id
116
     * @param string           $cacheKey
117
     * @param mixed            $data
118
     *
119
     */
120
    public static function save($table, $id, $cacheKey, $data)
121
    {
122
        $tables = Config::inst()->get('EcommerceCache', 'cache_in_mysql_tables');
123
        if (is_array($tables) && in_array($table, $tables)) {
124
            $table = self::make_mysql_table_name($table);
125
            $id = (int)$id;
126
            if (strlen($cacheKey) > 50) {
127
                user_error('ERROR: CACHEKEY longer than 50 characters: '.$cacheKey);
128
            }
129
            $data = Convert::raw2sql(serialize($data));
130
            if (!isset(self::$_items[$table])) {
131
                self::$_items[$table] = array();
132
            }
133
            if (isset(self::$_items[$table][$id])) {
134
                self::$_items[$table][$id] = array();
135
            }
136
            self::$_items[$table][$id][$cacheKey] = $data;
137
            DB::query('
138
                INSERT INTO "'.$table.'" ("PAGEID", "CACHEKEY", "DATA")
139
                VALUES ('.$id.', \''.$cacheKey.'\', \''.$data.'\')
140
                ON DUPLICATE KEY UPDATE DATA = \''.$data.'\';
141
            ');
142
        } else {
143
            $cache = SS_Cache::factory($table."_".$id);
144
            $data = serialize($data);
145
            $cache->save($data, $cacheKey);
146
        }
147
    }
148
149
    /**
150
     * @param string           $table
151
     * @param int              $id
152
     * @param string           $cacheKey
153
     * @param mixed            $data
154
     */
155
    public static function touch($table, $id, $cacheKey, $data)
0 ignored issues
show
The parameter $data 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...
156
    {
157
        $data = self::load($table, $inty, $cacheKey);
0 ignored issues
show
The variable $inty does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
158
        self::save($table, $id, $cacheKey, $data);
159
    }
160
161
    private static function make_mysql_table_name($table)
162
    {
163
        return strtoupper($table). '_CACHE';
164
    }
165
}
166