Issues (27)

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/Util/util.php (2 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
namespace League\Plates\Util;
4
5
use League\Plates\Exception\PlatesException;
6
use League\Plates\Exception\StackException;
7
8
function id() {
9
    return function($arg) {
10 36
        return $arg;
11 36
    };
12
}
13
14
/** wraps a closure in output buffering and returns the buffered
15
    content. */
16
function obWrap(callable $wrap) {
17 28
    $cur_level = ob_get_level();
18
19
    try {
20 28
        ob_start();
21 28
        $wrap();
22 28
        return ob_get_clean();
23
    } catch (\Exception $e) {}
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
24
      catch (\Throwable $e) {}
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
25
26
    // clean the ob stack
27
    while (ob_get_level() > $cur_level) {
28
        ob_end_clean();
29
    }
30
31
    throw $e;
32
}
33
34
/** simple utility that wraps php echo which allows for stubbing out the
35
    echo func for testing */
36
function phpEcho() {
37
    return function($v) {
38 16
        echo $v;
39 28
    };
40
}
41
42
/** stack a set of functions into each other and returns the stacked func */
43
function stack(array $funcs) {
44
    return array_reduce($funcs, function($next, $func) {
45
        return function(...$args) use ($next, $func) {
46 60
            $args[] = $next;
47 60
            return $func(...$args);
48 60
        };
49
    }, function() {
50 4
        throw new StackException('No handler was able to return a result.');
51 64
    });
52
}
53
54
function stackGroup(array $funcs) {
55 28
    $end_next = null;
56
    array_unshift($funcs, function(...$args) use (&$end_next) {
57 4
        return $end_next(...array_slice($args, 0, -1));
58 28
    });
59 28
    $next = stack($funcs);
60
    return function(...$args) use ($next, &$end_next) {
61 20
        $end_next = end($args);
62 20
        return $next(...array_slice($args, 0, -1));
63 28
    };
64
}
65
66
/** compose(f, g)(x) = f(g(x)) */
67
function compose(...$funcs) {
68 24
    return pipe(...array_reverse($funcs));
69
}
70
71
/** pipe(f, g)(x) = g(f(x)) */
72
function pipe(...$funcs) {
73
    return function($arg) use ($funcs) {
74
        return array_reduce($funcs, function($acc, $func) {
75 24
            return $func($acc);
76 24
        }, $arg);
77 24
    };
78
}
79
80
function joinPath(array $parts, $sep = DIRECTORY_SEPARATOR) {
81
    return array_reduce(array_filter($parts), function($acc, $part) use ($sep) {
82 32
        if ($acc === null) {
83 32
            return rtrim($part, $sep);
84
        }
85
86 32
        return $acc . $sep . ltrim($part, $sep);
87 32
    }, null);
88
}
89
90
function isAbsolutePath($path) {
91 40
    return strpos($path, '/') === 0;
92
}
93
function isRelativePath($path) {
94 36
    return strpos($path, './') === 0 || strpos($path, '../') === 0;
95
}
96
function isResourcePath($path) {
97 20
    return strpos($path, '://') !== false;
98
}
99
function isPath($path) {
100 32
    return isAbsolutePath($path) || isRelativePath($path) || isResourcePath($path);
101
}
102
103
/** returns the debug type of an object as string for exception printing */
104
function debugType($v) {
105 8
    if (is_object($v)) {
106 4
        return 'object ' . get_class($v);
107
    }
108
109 4
    return gettype($v);
110
}
111
112
function spliceArrayAtKey(array $array, $key, array $values, $after = true) {
113
    $new_array = [];
114
    $spliced = false;
115
    foreach ($array as $array_key => $val) {
116
        if ($array_key == $key) {
117
            $spliced = true;
118
            if ($after) {
119
                $new_array[$array_key] = $val;
120
                $new_array = array_merge($new_array, $values);
121
            } else {
122
                $new_array = array_merge($new_array, $values);
123
                $new_array[$array_key] = $val;
124
            }
125
        } else {
126
            $new_array[$array_key] = $val;
127
        }
128
    }
129
130
    if (!$spliced) {
131
        throw new PlatesException('Could not find key ' . $key . ' in array.');
132
    }
133
134
    return $new_array;
135
}
136
137
function cachedFileExists(Psr\SimpleCache\CacheInterface $cache, $ttl = 3600, $file_exists = 'file_exists') {
138
    return function($path) use ($cache, $ttl, $file_exists) {
139
        $key = 'League.Plates.file_exists.' . $path;
140
        $res = $cache->get($key);
141
        if (!$res) {
142
            $res = $file_exists($path);
143
            $cache->set($key, $res, $ttl);
144
        }
145
        return $res;
146
    };
147
}
148
149
/** Invokes the callable if the predicate returns true. Returns the value otherwise. */
150
function when(callable $predicate, callable $fn) {
151
    return function($arg) use ($predicate, $fn) {
152 8
        return $predicate($arg) ? $fn($arg) : $arg;
153 8
    };
154
}
155