Issues (49)

Security Analysis    12 potential vulnerabilities

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting (10)
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 (2)
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.

functions.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
 * General functions to use in img.php.
4
 */
5
6
7
8
/**
9
 * Trace and log execution to logfile, useful for debugging and development.
10
 *
11
 * @param string $msg message to log to file.
12
 *
13
 * @return void
14
 */
15
function trace($msg)
16
{
17
    $file = CIMAGE_DEBUG_FILE;
18
    if (!is_writable($file)) {
19
        return;
20
    }
21
22
    $timer = number_format((microtime(true) - $_SERVER["REQUEST_TIME_FLOAT"]), 6);
23
    $details  = "{$timer}ms";
24
    $details .= ":" . round(memory_get_peak_usage()/1024/1024, 3) . "MB";
25
    $details .= ":" . count(get_included_files());
26
    file_put_contents($file, "$details:$msg\n", FILE_APPEND);
27
}
28
29
30
31
/**
32
 * Display error message.
33
 *
34
 * @param string $msg to display.
35
 * @param int $type of HTTP error to display.
36
 *
37
 * @return void
38
 */
39
function errorPage($msg, $type = 500)
40
{
41
    global $mode;
42
43
    switch ($type) {
44
        case 403:
45
            $header = "403 Forbidden";
46
            break;
47
        case 404:
48
            $header = "404 Not Found";
49
            break;
50
        default:
51
            $header = "500 Internal Server Error";
52
    }
53
54
    if ($mode == "strict") {
55
        $header = "404 Not Found";
56
    }
57
58
    header("HTTP/1.0 $header");
59
60
    if ($mode == "development") {
61
        die("[img.php] $msg");
62
    }
63
64
    error_log("[img.php] $msg");
65
    die("HTTP/1.0 $header");
66
}
67
68
69
70
/**
71
 * Get input from query string or return default value if not set.
72
 *
73
 * @param mixed $key     as string or array of string values to look for in $_GET.
74
 * @param mixed $default value to return when $key is not set in $_GET.
75
 *
76
 * @return mixed value from $_GET or default value.
77
 */
78
function get($key, $default = null)
79
{
80
    if (is_array($key)) {
81
        foreach ($key as $val) {
82
            if (isset($_GET[$val])) {
83
                return $_GET[$val];
84
            }
85
        }
86
    } elseif (isset($_GET[$key])) {
87
        return $_GET[$key];
88
    }
89
    return $default;
90
}
91
92
93
94
/**
95
 * Get input from query string and set to $defined if defined or else $undefined.
96
 *
97
 * @param mixed $key       as string or array of string values to look for in $_GET.
98
 * @param mixed $defined   value to return when $key is set in $_GET.
99
 * @param mixed $undefined value to return when $key is not set in $_GET.
100
 *
101
 * @return mixed value as $defined or $undefined.
102
 */
103
function getDefined($key, $defined, $undefined)
104
{
105
    return get($key) === null ? $undefined : $defined;
106
}
107
108
109
110
/**
111
 * Get value of input from query string or else $undefined.
112
 *
113
 * @param mixed $key       as string or array of string values to look for in $_GET.
114
 * @param mixed $undefined value to return when $key has no, or empty value in $_GET.
115
 *
116
 * @return mixed value as or $undefined.
117
 */
118
function getValue($key, $undefined)
119
{
120
    $val = get($key);
121
    if (is_null($val) || $val === "") {
122
        return $undefined;
123
    }
124
    return $val;
125
}
126
127
128
129
/**
130
 * Get value from config array or default if key is not set in config array.
131
 *
132
 * @param string $key    the key in the config array.
133
 * @param mixed $default value to be default if $key is not set in config.
134
 *
135
 * @return mixed value as $config[$key] or $default.
136
 */
137
function getConfig($key, $default)
138
{
139
    global $config;
140
    return isset($config[$key])
141
        ? $config[$key]
142
        : $default;
143
}
144
145
146
147
/**
148
 * Log when verbose mode, when used without argument it returns the result.
149
 *
150
 * @param string $msg to log.
151
 *
152
 * @return void or array.
153
 */
154
function verbose($msg = null, $arg = "")
155
{
156
    global $verbose, $verboseFile;
157
    static $log = array();
158
159
    if (!($verbose || $verboseFile)) {
160
        return;
161
    }
162
163
    if (is_null($msg)) {
164
        return $log;
165
    }
166
167
    if (is_null($arg)) {
168
        $arg = "null";
169
    } elseif ($arg === false) {
170
        $arg = "false";
171
    } elseif ($arg === true) {
172
        $arg = "true";
173
    }
174
175
    $log[] = $msg . $arg;
176
}
177
178
179
180
/**
181
 * Log when verbose mode, when used without argument it returns the result.
182
 *
183
 * @param string $msg to log.
0 ignored issues
show
There is no parameter named $msg. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
184
 *
185
 * @return void or array.
186
 */
187
function checkExternalCommand($what, $enabled, $commandString)
188
{
189
    $no = $enabled ? null : 'NOT';
190
    $text = "Post processing $what is $no enabled.<br>";
191
192
    list($command) = explode(" ", $commandString);
193
    $no = is_executable($command) ? null : 'NOT';
194
    $text .= "The command for $what is $no an executable.<br>";
195
196
    return $text;
197
}
198