Issues (107)

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.

Controller/HealthCheckController.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 Liip\MonitorBundle\Controller;
4
5
use Liip\MonitorBundle\Helper\ArrayReporter;
6
use Liip\MonitorBundle\Helper\PathHelper;
7
use Liip\MonitorBundle\Helper\RunnerManager;
8
use Liip\MonitorBundle\Runner;
9
use Symfony\Component\HttpFoundation\JsonResponse;
10
use Symfony\Component\HttpFoundation\Request;
11
use Symfony\Component\HttpFoundation\Response;
12
13
class HealthCheckController
14
{
15
    protected $runnerManager;
16
    protected $pathHelper;
17
    protected $template;
18
    protected $failureStatusCode;
19
20
    /**
21
     * @param $template
22
     * @param $failureStatusCode
23
     */
24
    public function __construct(RunnerManager $runnerManager, PathHelper $pathHelper, $template, $failureStatusCode)
25
    {
26
        $this->runnerManager = $runnerManager;
27
        $this->pathHelper = $pathHelper;
28
        $this->template = $template;
29
        $this->failureStatusCode = $failureStatusCode;
30
    }
31
32
    /**
33
     * @return Response
34
     */
35
    public function indexAction(Request $request)
36
    {
37
        $group = $this->getGroup($request);
38
39
        $urls = $this->pathHelper->getRoutesJs([
40
            'liip_monitor_run_all_checks' => ['group' => $group],
41
            'liip_monitor_run_single_check' => ['checkId' => 'replaceme', 'group' => $group],
42
        ]);
43
44
        $css = $this->pathHelper->getStyleTags([
45
            'bundles/liipmonitor/css/bootstrap/css/bootstrap.min.css',
46
            'bundles/liipmonitor/css/style.css',
47
        ]);
48
49
        $javascript = $this->pathHelper->getScriptTags([
50
            'bundles/liipmonitor/javascript/jquery-1.7.1.min.js',
51
            'bundles/liipmonitor/javascript/ember-0.9.5.min.js',
52
            'bundles/liipmonitor/javascript/app.js',
53
        ]);
54
55
        // this is a hack to make the bundle template agnostic.
56
        // URL generation for Assets and Routes is still handled by the framework.
57
        ob_start();
58
        include $this->template;
59
        $content = ob_get_clean();
60
61
        return new Response($content, 200, ['Content-Type' => 'text/html']);
62
    }
63
64
    /**
65
     * @return Response
66
     */
67
    public function listAction(Request $request)
68
    {
69
        $ret = [];
70
71
        $runner = $this->getRunner($request);
72
73
        foreach ($runner->getChecks() as $alias => $check) {
74
            $ret[] = $alias;
75
        }
76
77
        return new JsonResponse($ret);
78
    }
79
80
    /**
81
     * @return JsonResponse
82
     */
83
    public function listAllAction()
84
    {
85
        $allChecks = [];
86
87
        foreach ($this->runnerManager->getRunners() as $group => $runner) {
88
            foreach ($runner->getChecks() as $alias => $check) {
89
                $allChecks[$group][] = $alias;
90
            }
91
        }
92
93
        return new JsonResponse($allChecks);
94
    }
95
96
    /**
97
     * @return JsonResponse
98
     */
99
    public function listGroupsAction()
100
    {
101
        $groups = $this->runnerManager->getGroups();
102
103
        return new JsonResponse($groups);
104
    }
105
106
    /**
107
     * @return Response
108
     */
109
    public function runAllChecksAction(Request $request)
110
    {
111
        $report = $this->runTests($request);
112
113
        return new JsonResponse([
114
            'checks' => $report->getResults(),
115
            'globalStatus' => $report->getGlobalStatus(),
116
        ]);
117
    }
118
119
    /**
120
     * @return Response
121
     */
122 View Code Duplication
    public function runAllChecksHttpStatusAction(Request $request)
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...
123
    {
124
        $report = $this->runTests($request);
125
126
        return new Response(
127
            '',
128
            (ArrayReporter::STATUS_OK === $report->getGlobalStatus() ? 200 : $this->failureStatusCode)
129
        );
130
    }
131
132
    /**
133
     * @param string $checkId
134
     *
135
     * @return Response
136
     */
137 View Code Duplication
    public function runSingleCheckHttpStatusAction($checkId, Request $request)
138
    {
139
        $report = $this->runTests($request, $checkId);
140
141
        return new Response(
142
            '',
143
            (ArrayReporter::STATUS_OK === $report->getGlobalStatus() ? 200 : $this->failureStatusCode)
144
        );
145
    }
146
147
    /**
148
     * @param string $checkId
149
     *
150
     * @return Response
151
     */
152
    public function runSingleCheckAction($checkId, Request $request)
153
    {
154
        $results = $this->runTests($request, $checkId)->getResults();
155
156
        return new JsonResponse($results[0]);
157
    }
158
159
    /**
160
     * @param string|null $checkId
161
     *
162
     * @return ArrayReporter
163
     */
164
    protected function runTests(Request $request, $checkId = null)
165
    {
166
        $reporters = $request->query->get('reporters') ?? [];
167
168
        if (!is_array($reporters)) {
169
            $reporters = [$reporters];
170
        }
171
172
        $reporter = new ArrayReporter();
173
174
        $runner = $this->getRunner($request);
175
176
        $runner->addReporter($reporter);
177
        $runner->useAdditionalReporters($reporters);
178
        $runner->run($checkId);
179
180
        return $reporter;
181
    }
182
183
    /**
184
     * @return Runner
185
     *
186
     * @throws \Exception
187
     */
188
    private function getRunner(Request $request)
189
    {
190
        $group = $this->getGroup($request);
191
192
        $runner = $this->runnerManager->getRunner($group);
193
194
        if ($runner) {
195
            return $runner;
196
        }
197
198
        throw new \RuntimeException(sprintf('Unknown check group "%s"', $group));
199
    }
200
201
    /**
202
     * @return string
203
     */
204
    private function getGroup(Request $request)
205
    {
206
        return $request->query->get('group') ?: $this->runnerManager->getDefaultGroup();
207
    }
208
209
    /**
210
     * @return Response
211
     */
212
    public function listReportersAction()
213
    {
214
        return new JsonResponse($this->runnerManager->getReporters());
215
    }
216
}
217