Issues (5)

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.

File/Locator.php (1 issue)

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 JK\Sam\File;
4
5
use Exception;
6
use SplFileInfo;
7
use Symfony\Component\Finder\Finder;
8
9
class Locator
10
{
11
    /**
12
     * The normalizer associated to the file locator.
13
     *
14
     * @var Normalizer
15
     */
16
    protected $normalizer;
17
    
18
    /**
19
     * Locator constructor.
20
     *
21
     * @param Normalizer $normalizer
22
     */
23 5
    public function __construct(Normalizer $normalizer)
24
    {
25 5
        $this->normalizer = $normalizer;
26 5
    }
27
    
28
    /**
29
     * Locate a source either if it a file or a directory and normalize it. Return an array of SplFileInfo.
30
     *
31
     * @param mixed $source
32
     * @return SplFileInfo[]
33
     * @throws Exception
34
     */
35 5
    public function locate($source)
36
    {
37 5
        $sources = [];
38 5
        $normalizedSources = [];
39
        
40
        // if the wildcard is at the end of the string, it means that we look for a directory
41 5
        $endingWithWilCard = substr($source, strlen($source) - 2) === '/*';
42
        
43 5
        if ($endingWithWilCard) {
44 1
            $source = substr($source, 0, strlen($source) - 2);
45
        }
46
        
47 5
        if (is_dir($source) || $endingWithWilCard) {
48 2
            $finder = new Finder();
49
            $finder
50 2
                ->files()
51 2
                ->in($this->removeLastSlash($source))
52
            ;
53
            
54 2
            foreach ($finder as $file) {
55 2
                $sources[] = $file;
56
            }
57 3
        } else if (strstr($source, '*') !== false) {
58
            // if the source contains a wildcard, we use it with the finder component
59 2
            $sources = $this->getSourcesFromFinder($source);
60
        } else {
61 2
            $sources[] = $source;
62
        }
63
        
64
        // each found sources should be normalized
65 5
        foreach ($sources as $source) {
66 5
            $normalizedSources[] = $this
67 5
                ->normalizer
68 5
                ->normalize($source);
69
        }
70
        
71 5
        return $normalizedSources;
72
    }
73
    
74
    /**
75
     * Return the normalizer associated to the file locator.
76
     *
77
     * @return Normalizer
78
     */
79 2
    public function getNormalizer()
80
    {
81 2
        return $this->normalizer;
82
    }
83
    
84
    /**
85
     * Return files sources using the finder to allow wild wards.
86
     *
87
     * @param $source
88
     *
89
     * @return SplFileInfo[]
90
     */
91 2
    protected function getSourcesFromFinder($source)
92
    {
93 2
        $array = explode(DIRECTORY_SEPARATOR, $source);
94 2
        $filename = array_pop($array);
95 2
        $directory = $source;
96 2
        $pattern = '*';
97
        
98
        // if a dot is present, the last part is the filename pattern
99 2
        if (strstr($filename, '.') !== false) {
100 2
            $pattern = $filename;
101 2
            $directory = implode('/', $array);
102
        }
103 2
        $finder = new Finder();
104
        $finder
105 2
            ->name($pattern)
106 2
            ->in($directory);
107
        
108 2
        $sources = [];
109
        
110 2
        foreach ($finder as $source) {
111 2
            $sources[] = $source;
112
        }
113
        
114 2
        return $sources;
115
    }
116
    
117
    /**
118
     * Remove the last slash of the string.
119
     *
120
     * @param string $string
121
     *
122
     * @return string
123
     */
124 2 View Code Duplication
    private function removeLastSlash($string)
0 ignored issues
show
This method 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...
125
    {
126 2
        if ('/' === substr($string, strlen($string) - 1)) {
127
            $string = substr($string, 0, strlen($string) - 1);
128
        }
129
        
130 2
        return $string;
131
    }
132
}
133