Issues (197)

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/CheckNamespaces.php (4 issues)

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
namespace Imanghafoori\LaravelMicroscope;
4
5
use Illuminate\Support\Str;
6
use Imanghafoori\LaravelMicroscope\Analyzers\GetClassProperties;
7
use Imanghafoori\LaravelMicroscope\Analyzers\NamespaceCorrector;
8
use Imanghafoori\LaravelMicroscope\ErrorReporters\ErrorPrinter;
9
use Imanghafoori\LaravelMicroscope\LaravelPaths\FilePath;
10
use Imanghafoori\LaravelMicroscope\LaravelPaths\LaravelPaths;
11
12
class CheckNamespaces
13
{
14
    public static $checkedNamespaces = 0;
15
16
    public static $changedNamespaces = [];
17
18
    /**
19
     * Get all of the listeners and their corresponding events.
20
     *
21
     * @param  iterable  $paths
22
     * @param  $composerPath
23
     * @param  $composerNamespace
24
     * @param  $command
25
     *
26
     * @return void
27
     */
28
    public static function within($paths, $composerPath, $composerNamespace, $command)
29
    {
30
        $detailed = $command->option('detailed');
31
32
        foreach ($paths as $classFilePath) {
33
            $absFilePath = $classFilePath->getRealPath();
34
35
            // exclude blade files
36
            if (Str::endsWith($absFilePath, ['.blade.php'])) {
37
                continue;
38
            }
39
40
            // exclude migration directories
41
            if (Str::startsWith($absFilePath, LaravelPaths::migrationDirs())) {
42
                continue;
43
            }
44
45
            if (! self::hasOpeningTag($absFilePath)) {
46
                continue;
47
            }
48
49
            [
50
                $currentNamespace,
0 ignored issues
show
The variable $currentNamespace does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
51
                $class,
0 ignored issues
show
The variable $class does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
52
                $type,
0 ignored issues
show
The variable $type does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
53
                $parent,
0 ignored issues
show
The variable $parent does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
54
            ] = GetClassProperties::fromFilePath($absFilePath);
55
56
            // Skip if there is no class/trait/interface definition found.
57
            // For example a route file or a config file.
58
            if (! $class || $parent == 'Migration') {
59
                continue;
60
            }
61
62
            $detailed && event('microscope.checking', [$classFilePath->getRelativePathname(), $command]);
63
64
            $relativePath = FilePath::getRelativePath($absFilePath);
65
            $correctNamespace = NamespaceCorrector::calculateCorrectNamespace($relativePath, $composerPath, $composerNamespace);
66
            self::$checkedNamespaces++;
67
68
            if ($currentNamespace === $correctNamespace) {
69
                continue;
70
            }
71
72
            self::changedNamespaces($class, $currentNamespace, $correctNamespace);
73
            ErrorPrinter::warnIncorrectNamespace($currentNamespace, $relativePath, $class);
74
75
            if (! $command->option('nofix') && ErrorPrinter::ask($command, $correctNamespace)) {
76
                self::doNamespaceCorrection($absFilePath, $currentNamespace, $correctNamespace);
77
                // maybe an event listener
78
                app(ErrorPrinter::class)->badNamespace($relativePath, $correctNamespace, $currentNamespace);
79
            }
80
        }
81
    }
82
83
    public static function hasOpeningTag($file)
84
    {
85
        $fp = fopen($file, 'r');
86
87
        if (feof($fp)) {
88
            return false;
89
        }
90
91
        $buffer = fread($fp, 20);
92
        fclose($fp);
93
94
        return Str::startsWith($buffer, '<?php');
95
    }
96
97
    protected static function doNamespaceCorrection($absFilePath, $currentNamespace, $correctNamespace)
98
    {
99
        event('laravel_microscope.namespace_fixing', get_defined_vars());
100
        NamespaceCorrector::fix($absFilePath, $currentNamespace, $correctNamespace);
101
        event('laravel_microscope.namespace_fixed', get_defined_vars());
102
    }
103
104
    private static function changedNamespaces($class, $currentNamespace, $correctNamespace)
105
    {
106
        $_currentClass = $currentNamespace.'\\'.$class;
107
        $_correctClass = $correctNamespace.'\\'.$class;
108
        $relPath = NamespaceCorrector::getRelativePathFromNamespace($currentNamespace);
109
        if (is_dir(base_path($relPath.DIRECTORY_SEPARATOR.$class))) {
110
            self::$changedNamespaces[$_currentClass.';'] = $_correctClass.';';
111
            self::$changedNamespaces[$_currentClass.'('] = $_correctClass.'(';
112
            self::$changedNamespaces[$_currentClass.'::'] = $_correctClass.'::';
113
            self::$changedNamespaces[$_currentClass.' as'] = $_correctClass.' as';
114
        } else {
115
            self::$changedNamespaces[$_currentClass] = $_correctClass;
116
        }
117
    }
118
}
119