Issues (21)

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/Controller/AbstractController.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 Egzaminer\Controller;
4
5
use Egzaminer\Model\ExamsGroupModel;
6
use Egzaminer\Themes\MaterialDesignLite;
7
use Exception;
8
use Twig_Environment;
9
use Twig_Loader_Filesystem;
10
11
abstract class AbstractController
12
{
13
    /**
14
     * @var array
15
     */
16
    private $container;
17
18
    /**
19
     * @var array
20
     */
21
    protected $data;
22
23
    public function __construct(array $container)
24
    {
25
        $this->container = $container;
26
    }
27
28
    /**
29
     * @param string $name Item name
30
     *
31
     * @return mixed Item from container
32
     */
33
    public function get(string $name)
34
    {
35
        if (!isset($this->container[$name])) {
36
            return;
37
        }
38
39
        return $this->container[$name];
40
    }
41
42
    /**
43
     * @param string $name Config name
44
     *
45
     * @return mixed Config value
46
     */
47
    public function config(string $name)
48
    {
49
        if (!isset($this->get('config')[$name])) {
50
            return;
51
        }
52
53
        return $this->get('config')[$name];
54
    }
55
56
    /**
57
     * Get request variable.
58
     *
59
     * @param string $type Request type
60
     * @param string $name Index name. Null for all
61
     *
62
     * @return mixed
63
     */
64
    public function getFromRequest(string $type = 'get', string $name = null)
65
    {
66
        $request = $this->get('request');
67
68
        // if unknown request type
69
        if (!isset($request[$type])) {
70
            return;
71
        }
72
73
        // for get all indexes from type
74
        if (null === $name) {
75
            return $request[$type];
76
        }
77
78
        if (isset($request[$type][$name])) {
79
            return $request[$type][$name];
80
        }
81
    }
82
83
    public function dir(): string
84
    {
85
        return $this->get('dir');
86
    }
87
88
    public function isLogged(): bool
89
    {
90
        return $this->get('auth')->isLogged();
91
    }
92
93
    /**
94
     * @param string $type    Message type
95
     * @param string $message Message content
96
     *
97
     * @return void
98
     */
99
    public function setMessage($type = 'success', $message = 'Success')
100
    {
101
        switch ($type) {
102
            case 'success':
103
                $this->get('flash')->success($message);
104
                break;
105
            case 'info':
106
                $this->get('flash')->info($message);
107
                break;
108
            case 'warning':
109
                $this->get('flash')->warning($message);
110
                break;
111
            case 'error':
112
                $this->get('flash')->error($message);
113
                break;
114
115
            default:
116
                $this->get('flash')->error($message);
117
                break;
118
        }
119
    }
120
121
    /**
122
     * Redirect.
123
     *
124
     * @param string $path Path to redirect
125
     *
126
     * @return void
127
     */
128
    public function redirect($path)
129
    {
130
        header('Location: '.$this->dir().$path);
131
    }
132
133
    public function terminate($code = 1)
134
    {
135
        exit($code);
136
    }
137
138
    private function selectMessagesTemplate()
139
    {
140
        switch ($this->config('theme')) {
141
            case 'mdl':
142
                $this->get('flash')->setTemplate(new MaterialDesignLite());
143
                break;
144
        }
145
    }
146
147
    public function render(string $template, array $data = [])
148
    {
149
        $this->selectMessagesTemplate();
150
151
        $data['version'] = $this->get('version');
152
        $data['dir'] = $this->dir();
153
        $data['flash'] = $this->get('flash')->display();
154
        $data['headerTitle'] = $data['title'] ?? '';
155
        $data['isLogged'] = $this->isLogged();
156
        $data['siteTitle'] = $this->config('title');
157
        $data['pageTitle'] = isset($data['title'])
158
            ? $data['title'].' '.$this->config('title_divider').' '.$this->config('title')
159
            : $this->config('title');
160
161
        $data['examsGroups'] = (new ExamsGroupModel($this->get('dbh')))->getExamsGroups();
162
163
        $loader = new Twig_Loader_Filesystem(
0 ignored issues
show
Deprecated Code introduced by
The class Twig_Loader_Filesystem has been deprecated with message: since Twig 2.7, use "Twig\Loader\FilesystemLoader" instead

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
164
            $this->get('rootDir').'/resources/themes/'.$this->config('theme').'/templates/'
165
        );
166
        $twig = new Twig_Environment($loader, [
0 ignored issues
show
Deprecated Code introduced by
The class Twig_Environment has been deprecated with message: since Twig 2.7, use "Twig\Environment" instead

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
167
            'cache' => $this->config('cache') ? $this->get('rootDir').'/var/twig' : false,
168
            'debug' => $this->config('debug') ? true : false,
169
        ]);
170
171
        try {
172
            return $twig->render($template.'.twig', $data);
173
        } catch (Exception $e) {
174
            if ($this->config('debug')) {
175
                echo $e->getMessage();
176
            } else {
177
                echo 'Error 500';
178
            }
179
180
            return false;
181
        }
182
    }
183
}
184