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/Extension/Path/path.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
2
3
namespace League\Plates\Extension\Path;
4
5
use League\Plates;
6
7
function resolvePathCompose(callable $resolve_path) {
8
    return function(Plates\Template $template) use ($resolve_path) {
9 24
        return $template->with('path', $resolve_path(ResolvePathArgs::fromTemplate($template, $resolve_path)));
0 ignored issues
show
The call to ResolvePathArgs::fromTemplate() has too many arguments starting with $resolve_path.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
10 24
    };
11
}
12
13
function normalizeNameCompose(callable $normalize_name) {
14
    return function(Plates\Template $template) use ($normalize_name) {
15 32
        return $template->with(
16 32
            'normalized_name',
17 32
             Plates\Util\isPath($template->name) ? $normalize_name($template->get('path')) : $template->name
18
        );
19 32
    };
20
}
21
22
function stripExtNormalizeName() {
23
    return function($name) {
24 24
        $ext = pathinfo($name, PATHINFO_EXTENSION);
25 24
        if (!$ext) {
26 4
            return $name;
27
        }
28
29 20
        return substr($name, 0, (strlen($ext) + 1) * -1); // +1 for the leading `.`
30 32
    };
31
}
32
33
function stripPrefixNormalizeName(array $prefixes) {
34 32
    $prefixes = array_filter($prefixes);
35
    return function($name) use ($prefixes) {
36 24
        foreach ($prefixes as $prefix) {
37 20
            if (strpos($name, $prefix . '/') === 0) {
38 20
                return substr($name, strlen($prefix) + 1); // +1 for the trailing `/`
39
            }
40
        }
41
42 8
        return $name;
43 32
    };
44
}
45
46
/** appends an extension to the name */
47
48
function extResolvePath($ext = 'phtml') {
49 32
    $full_ext = '.' . $ext;
50 32
    $ext_len = strlen($full_ext);
51
    return function(ResolvePathArgs $args, $next) use ($full_ext, $ext_len) {
52
        // ext is already there, just skip
53 32
        if (strrpos($args->path, $full_ext) === strlen($args->path) - $ext_len) {
54 8
            return $next($args);
55
        }
56
57 28
        return $next($args->withPath($args->path . $full_ext));
58 32
    };
59
}
60
61
function prefixResolvePath(array $prefixes, $file_exists = 'file_exists') {
62
    return function(ResolvePathArgs $args, $next) use ($prefixes, $file_exists) {
63 28
        if (!$prefixes) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $prefixes of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
64
            return $next($args);
65
        }
66
67 28
        foreach ($prefixes as $cur_prefix) {
68 28
            $path = Plates\Util\isAbsolutePath($args->path)
69 16
                ? $next($args)
70 20
                : $next($args->withPath(
71 28
                    Plates\Util\joinPath([$cur_prefix, $args->path])
72
                ));
73
74
            // we have a match, let's return
75 28
            if ($file_exists($path)) {
76 28
                return $path;
77
            }
78
79
            // at this point, we need to try the next prefix, but before we do, let's strip the prefix
80
            // if there is one since this might a be a relative path
81 4
            $stripped_args = null;
82 4
            foreach ($prefixes as $prefix) {
83 4
                if (strpos($path, $prefix) === 0) {
84 4
                    $stripped_args = $args->withPath(substr($path, strlen($prefix))); // remove the prefix
85 4
                    break;
86
                }
87
            }
88
89
            // could not strip the prefix, so there's not point in continuing on
90 4
            if (!$stripped_args) {
91
                return $path;
92
            }
93
94 4
            $args = $stripped_args;
95
        }
96
97
        // at this point, none of the paths resolved into a valid path, let's just return the last one
98 4
        return $path;
0 ignored issues
show
The variable $path does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
99 28
    };
100
}
101
102
/** Figures out the path based off of the parent templates current path */
103
function relativeResolvePath() {
104
    return function(ResolvePathArgs $args, $next) {
105 32
        $is_relative = Plates\Util\isRelativePath($args->path) && $args->template->parent;
106
107 32
        if (!$is_relative) {
108 28
            return $next($args); // nothing to do
109
        }
110
111 12
        $current_directory = dirname($args->template->parent()->get('path'));
112 12
        return $next($args->withPath(
113 12
            Plates\Util\joinPath([$current_directory, $args->path])
114
        ));
115 32
    };
116
}
117
118
function idResolvePath() {
119
    return function(ResolvePathArgs $args, $next) {
0 ignored issues
show
The parameter $next 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...
120 52
        return $args->path;
121 52
    };
122
}
123