Issues (9)

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/controllers/LogViewerController.php (6 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 Rap2hpoutre\LaravelLogViewer;
4
5
use Illuminate\Support\Facades\Crypt;
6
7
if (class_exists("\\Illuminate\\Routing\\Controller")) {	
8
    class BaseController extends \Illuminate\Routing\Controller {}	
9
} elseif (class_exists("Laravel\\Lumen\\Routing\\Controller")) {	
10
    class BaseController extends \Laravel\Lumen\Routing\Controller {}	
0 ignored issues
show
Comprehensibility Best Practice introduced by
The type Rap2hpoutre\LaravelLogViewer\BaseController has been defined more than once; this definition is ignored, only the first definition in this file (L8-8) is considered.

This check looks for classes that have been defined more than once in the same file.

If you can, we would recommend to use standard object-oriented programming techniques. For example, to avoid multiple types, it might make sense to create a common interface, and then multiple, different implementations for that interface.

This also has the side-effect of providing you with better IDE auto-completion, static analysis and also better OPCode caching from PHP.

Loading history...
11
}
12
13
/**
14
 * Class LogViewerController
15
 * @package Rap2hpoutre\LaravelLogViewer
16
 */
17
class LogViewerController extends BaseController
18
{
19
    /**
20
     * @var \Illuminate\Http\Request
21
     */
22
    protected $request;
23
24
    /**
25
     * @var LaravelLogViewer
26
     */
27
    private $log_viewer;
28
29
    /**
30
     * @var string
31
     */
32
    protected $view_log = 'laravel-log-viewer::log';
33
34
    /**
35
     * LogViewerController constructor.
36
     */
37
    public function __construct()
38
    {
39
        $this->log_viewer = new LaravelLogViewer();
40
        $this->request = app('request');
41
    }
42
43
    /**
44
     * @return array|mixed
45
     * @throws \Exception
46
     */
47
    public function index()
48
    {
49
        $folderFiles = [];
50
        if ($this->request->input('f')) {
51
            $this->log_viewer->setFolder(Crypt::decrypt($this->request->input('f')));
0 ignored issues
show
It seems like $this->request->input('f') targeting Illuminate\Http\Concerns...ractsWithInput::input() can also be of type array; however, Illuminate\Support\Facades\Crypt::decrypt() does only seem to accept string, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
52
            $folderFiles = $this->log_viewer->getFolderFiles(true);
53
        }
54
        if ($this->request->input('l')) {
55
            $this->log_viewer->setFile(Crypt::decrypt($this->request->input('l')));
0 ignored issues
show
It seems like $this->request->input('l') targeting Illuminate\Http\Concerns...ractsWithInput::input() can also be of type array; however, Illuminate\Support\Facades\Crypt::decrypt() does only seem to accept string, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
56
        }
57
58
        if ($early_return = $this->earlyReturn()) {
59
            return $early_return;
60
        }
61
62
        $data = [
63
            'logs' => $this->log_viewer->all(),
64
            'folders' => $this->log_viewer->getFolders(),
65
            'current_folder' => $this->log_viewer->getFolderName(),
66
            'folder_files' => $folderFiles,
67
            'files' => $this->log_viewer->getFiles(true),
68
            'current_file' => $this->log_viewer->getFileName(),
69
            'standardFormat' => true,
70
        ];
71
72
        if ($this->request->wantsJson()) {
73
            return $data;
74
        }
75
76
        if (is_array($data['logs']) && count($data['logs']) > 0) {
77
            $firstLog = reset($data['logs']);
78
            if (!$firstLog['context'] && !$firstLog['level']) {
79
                $data['standardFormat'] = false;
80
            }
81
        }
82
83
        return app('view')->make($this->view_log, $data);
84
    }
85
86
    /**
87
     * @return bool|mixed
88
     * @throws \Exception
89
     */
90
    private function earlyReturn()
91
    {
92
        if ($this->request->input('f')) {
93
            $this->log_viewer->setFolder(Crypt::decrypt($this->request->input('f')));
0 ignored issues
show
It seems like $this->request->input('f') targeting Illuminate\Http\Concerns...ractsWithInput::input() can also be of type array; however, Illuminate\Support\Facades\Crypt::decrypt() does only seem to accept string, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
94
        }
95
96
        if ($this->request->input('dl')) {
97
            return $this->download($this->pathFromInput('dl'));
98
        } elseif ($this->request->has('clean')) {
99
            app('files')->put($this->pathFromInput('clean'), '');
100
            return $this->redirect(url()->previous());
101
        } elseif ($this->request->has('del')) {
102
            app('files')->delete($this->pathFromInput('del'));
103
            return $this->redirect($this->request->url());
104
        } elseif ($this->request->has('delall')) {
105
            $files = ($this->log_viewer->getFolderName())
106
                        ? $this->log_viewer->getFolderFiles(true)
107
                        : $this->log_viewer->getFiles(true);
108
            foreach ($files as $file) {
109
                app('files')->delete($this->log_viewer->pathToLogFile($file));
110
            }
111
            return $this->redirect($this->request->url());
112
        }
113
        return false;
114
    }
115
116
    /**
117
     * @param string $input_string
118
     * @return string
119
     * @throws \Exception
120
     */
121
    private function pathFromInput($input_string)
122
    {
123
        return $this->log_viewer->pathToLogFile(Crypt::decrypt($this->request->input($input_string)));
0 ignored issues
show
It seems like $this->request->input($input_string) targeting Illuminate\Http\Concerns...ractsWithInput::input() can also be of type array or null; however, Illuminate\Support\Facades\Crypt::decrypt() does only seem to accept string, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
124
    }
125
126
    /**
127
     * @param $to
128
     * @return mixed
129
     */
130
    private function redirect($to)
131
    {
132
        if (function_exists('redirect')) {
133
            return redirect($to);
134
        }
135
136
        return app('redirect')->to($to);
137
    }
138
139
    /**
140
     * @param string $data
141
     * @return mixed
142
     */
143
    private function download($data)
144
    {
145
        if (function_exists('response')) {
146
            return response()->download($data);
0 ignored issues
show
The method download does only exist in Illuminate\Contracts\Routing\ResponseFactory, but not in Illuminate\Http\Response.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
147
        }
148
149
        // For laravel 4.2
150
        return app('\Illuminate\Support\Facades\Response')->download($data);
151
    }
152
}
153