Issues (8)

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.

src/global.php (4 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
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 10 and the first side effect is on line 13.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/**
3
 * Created by Vitaly Iegorov <[email protected]>.
4
 * on 26.04.16 at 10:43
5
 */
6
7
use samsonphp\resource\ResourceValidator;
8
9
// Define this resource identifier
10
define('STATIC_RESOURCE_HANDLER', 'resourcer');
11
12
// Get current project web root directory
13
ResourceValidator::$webRoot = getcwd();
14
// Get current project root directory
15
ResourceValidator::$projectRoot = dirname(ResourceValidator::$webRoot);
16
17
/**
18
 * Static resource path builder.
19
 *
20
 * @deprecated Moving to use new samsonphp/view resource an $this->src() should be used
21
 *             in view file for generating paths to static resources
22
 *
23
 * @param string $path   Relative static resource resource path
24
 * @param null   $module Entity for path building, if not passed current resource is used
25
 *
26
 * @return string Static resource path
27
 * @throws \samsonphp\resource\exception\ResourceNotFound
28
 */
29
function src($path, $module = null)
30
{
31
    // Define resource
32
    switch (gettype($module)) {
33
        case 'string': // Find resource by identifier
34
            $module = m($module);
0 ignored issues
show
Deprecated Code introduced by
The function m() has been deprecated with message: Use $this->system->module() in module context

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
35
            break;
36
        case 'object': // Do nothing
37
            break;
38
        default: // Get current resource
39
            $module = m();
0 ignored issues
show
Deprecated Code introduced by
The function m() has been deprecated with message: Use $this->system->module() in module context

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
40
    }
41
42
    echo '/' . STATIC_RESOURCE_HANDLER . '/?p=' . ResourceValidator::getRelativePath($path, $module->path(), dirname(getcwd()));
0 ignored issues
show
It seems like $module is not always an object, but can also be of type null. Maybe add an additional type check?

If a variable is not always an object, we recommend to add an additional type check to ensure your method call is safe:

function someFunction(A $objectMaybe = null)
{
    if ($objectMaybe instanceof A) {
        $objectMaybe->doSomething();
    }
}
Loading history...
43
}
44
45
/** Collection of supported mime types */
46
$mimeTypes = array(
47
    'css' => 'text/css',
48
    'woff' => 'application/x-font-woff',
49
    'woff2' => 'application/x-font-woff2',
50
    'otf' => 'application/octet-stream',
51
    'ttf' => 'application/octet-stream',
52
    'eot' => 'application/vnd.ms-fontobject',
53
    'js' => 'application/x-javascript',
54
    'htm' => 'text/html;charset=utf-8',
55
    'htc' => 'text/x-component',
56
    'jpeg' => 'image/jpeg',
57
    'png' => 'image/png',
58
    'jpg' => 'image/jpg',
59
    'gif' => 'image/gif',
60
    'txt' => 'text/plain',
61
    'pdf' => 'application/pdf',
62
    'rtf' => 'application/rtf',
63
    'doc' => 'application/msword',
64
    'xls' => 'application/msexcel',
65
    'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
66
    'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
67
    'svg' => 'image/svg+xml',
68
    'mp4' => 'video/mp4',
69
    'ogg' => 'video/ogg'
70
);
71
72
// Perform custom simple URL parsing to match needed URL for static resource serving
73
$url = array_key_exists('REQUEST_URI', $_SERVER) ? $_SERVER['REQUEST_URI'] : '';
74
75
// Get URL path from URL and split with "/"
76
$url = array_values(array_filter(explode('/', parse_url($url, PHP_URL_PATH))));
77
78
// Special hook to avoid further framework loading if this is static resource request
79
if (array_key_exists(0, $url) && $url[0] === STATIC_RESOURCE_HANDLER) {
80
    // Get full path to static resource
81
    $filename = realpath('../' . $_GET['p']);
82
83
    if (file_exists($filename)) {
84
        // Receive current ETag for resource(if present)
85
        $clientETag = array_key_exists('HTTP_IF_NONE_MATCH', $_SERVER) ? $_SERVER['HTTP_IF_NONE_MATCH'] : '';
86
87
        // Generate ETag for resource
88
        $serverETag = filemtime($filename);
89
90
        // Set old cache headers
91
        header('Cache-Control:max-age=1800');
92
93
        // Always set new ETag header independently on further actions
94
        header('ETag:' . $serverETag);
95
96
        // Get file extension
97
        $extension = pathinfo($filename, PATHINFO_EXTENSION);
98
99
        // If server and client ETags are equal
100
        if ($clientETag === $serverETag) {
101
            header('HTTP/1.1 304 Not Modified');
102
        } elseif (array_key_exists($extension, $mimeTypes)) {
103
            // Set mime type
104
            header('Content-type: ' . $mimeTypes[$extension]);
105
106
            // Output resource
107
            echo file_get_contents($filename);
108
        } else { // File type is not supported
109
            header('HTTP/1.0 404 Not Found');
110
        }
111
    } else { // File not found
112
        header('HTTP/1.0 404 Not Found');
113
    }
114
115
    // Avoid further request processing
116
    die();
117
}
118