Issues (8)

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.

Entity/Request.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 Daken\ReleaseProfilerBundle\Entity;
4
5
use Doctrine\Common\Collections\ArrayCollection;
6
use Doctrine\ORM\Mapping as ORM;
7
use Symfony\Component\HttpFoundation\Request as HttpRequest;
8
9
/**
10
 * Request
11
 *
12
 * @ORM\Table(name="profiler_request")
13
 * @ORM\Entity(repositoryClass="Daken\ReleaseProfilerBundle\Repository\RequestRepository")
14
 */
15
class Request
16
{
17
    /**
18
     * @var int
19
     *
20
     * @ORM\Column(name="id", type="integer")
21
     * @ORM\Id
22
     * @ORM\GeneratedValue(strategy="AUTO")
23
     */
24
    private $id;
25
26
    /**
27
     * @var \DateTime
28
     *
29
     * @ORM\Column(name="created", type="datetime")
30
     */
31
    private $created;
32
33
    /**
34
     * @var string
35
     *
36
     * @ORM\Column(name="scheme", type="string", length=8)
37
     */
38
    private $scheme;
39
40
    /**
41
     * @var string
42
     *
43
     * @ORM\Column(name="host", type="string", length=255)
44
     */
45
    private $host;
46
47
    /**
48
     * @var string
49
     *
50
     * @ORM\Column(name="path", type="text")
51
     */
52
    private $path;
53
54
    /**
55
     * @var string
56
     *
57
     * @ORM\Column(name="query", type="text", nullable=true)
58
     */
59
    private $query;
60
61
    /**
62
     * @var string
63
     *
64
     * @ORM\Column(name="matched_route", type="string", length=255, nullable=true)
65
     */
66
    private $matchedRoute;
67
68
    /**
69
     * @var int
70
     *
71
     * @ORM\Column(name="time", type="integer")
72
     */
73
    private $time;
74
75
    /**
76
     * @var string
77
     *
78
     * @ORM\Column(name="request_method", type="string", length=8)
79
     */
80
    private $requestMethod;
81
82
    /**
83
     * @var string
84
     *
85
     * @ORM\Column(name="request_body", type="blob", nullable=true)
86
     */
87
    private $requestBody;
88
89
    /**
90
     * @var int
91
     *
92
     * @ORM\Column(name="response_code", type="integer")
93
     */
94
    private $responseCode;
95
96
    /**
97
     * @var string|resource
98
     *
99
     * @ORM\Column(name="response", type="blob", nullable=true)
100
     */
101
    private $response;
102
103
    /**
104
     * @var string
105
     *
106
     * @ORM\Column(name="client_ip", type="string", length=39)
107
     */
108
    private $clientIp;
109
110
    /**
111
     * @var string
112
     *
113
     * @ORM\Column(name="user_agent", type="text")
114
     */
115
    private $userAgent;
116
117
    /**
118
     * @var integer
119
     *
120
     * @ORM\Column(name="total_database_query_time", type="integer")
121
     */
122
    private $totalDatabaseQueryTime;
123
124
    /**
125
     * @var integer
126
     *
127
     * @ORM\Column(name="total_database_query_count", type="integer")
128
     */
129
    private $totalDatabaseQueryCount;
130
131
    private $createdMicroTime;
132
133
    /**
134
     * @ORM\OneToMany(
135
     *     targetEntity="Daken\ReleaseProfilerBundle\Entity\DatabaseQuery", mappedBy="request", cascade={"all"}
136
     *     )
137
     */
138
    private $databaseQueries;
139
140
    /**
141
     * @ORM\OneToMany(targetEntity="Daken\ReleaseProfilerBundle\Entity\Error", mappedBy="request", cascade={"all"})
142
     */
143
    private $errors;
144
145
    /**
146
     * @var string
147
     *
148
     * @ORM\Column(name="username", type="string", length=255, nullable=true)
149
     */
150
    private $username;
151
152 10
    public function __construct()
0 ignored issues
show
__construct uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
153
    {
154 10
        $this->created = new \DateTime();
155
156 10
        $this->createdMicroTime = $_SERVER['REQUEST_TIME_FLOAT'];
157 10
        $this->databaseQueries = new ArrayCollection();
158 10
        $this->errors = new ArrayCollection();
159 10
    }
160
161 5
    public static function fromHttpRequest(HttpRequest $request)
162
    {
163 5
        $instance = new Request();
164 5
        $instance->setClientIp($request->getClientIp());
165 5
        $instance->setHost($request->getHost());
166 5
        $instance->setPath($request->getPathInfo());
167 5
        $instance->setQuery($request->getQueryString());
168 5
        $instance->setRequestMethod($request->getMethod());
169 5
        $instance->setScheme($request->getScheme());
170 5
        $instance->setUserAgent($request->headers->get('User-Agent'));
171
        
172 5
        return $instance;
173
    }
174
175 1
    public function __toString()
176
    {
177 1
        return $this->getResponseCode().' '.$this->getRequestMethod().
178 1
        ' '.$this->getScheme().'://'.$this->getHost().$this->getPath();
179
    }
180
181 2
    public function stop()
182
    {
183 2
        $this->setTime((microtime(true) - $this->createdMicroTime) * 1000);
184 2
    }
185
186
    /**
187
     * Get id
188
     *
189
     * @return int
190
     */
191 1
    public function getId()
192
    {
193 1
        return $this->id;
194
    }
195
196
    /**
197
     * Set created
198
     *
199
     * @param \DateTime $created
200
     *
201
     * @return Request
202
     */
203 1
    public function setCreated($created)
204
    {
205 1
        $this->created = $created;
206
207 1
        return $this;
208
    }
209
210
    /**
211
     * Get created
212
     *
213
     * @return \DateTime
214
     */
215 1
    public function getCreated()
216
    {
217 1
        return $this->created;
218
    }
219
220
    /**
221
     * Set host
222
     *
223
     * @param string $host
224
     *
225
     * @return Request
226
     */
227 5
    public function setHost($host)
228
    {
229 5
        $this->host = $host;
230
231 5
        return $this;
232
    }
233
234
    /**
235
     * Get host
236
     *
237
     * @return string
238
     */
239 5
    public function getHost()
240
    {
241 5
        return $this->host;
242
    }
243
244
    /**
245
     * Set url
246
     *
247
     * @param string $path
248
     *
249
     * @return Request
250
     */
251 5
    public function setPath($path)
252
    {
253 5
        $this->path = $path;
254
255 5
        return $this;
256
    }
257
258
    /**
259
     * Get url
260
     *
261
     * @return string
262
     */
263 3
    public function getPath()
264
    {
265 3
        return $this->path;
266
    }
267
268
    /**
269
     * Set matchedRoute
270
     *
271
     * @param string $matchedRoute
272
     *
273
     * @return Request
274
     */
275 3
    public function setMatchedRoute($matchedRoute)
276
    {
277 3
        $this->matchedRoute = $matchedRoute;
278
279 3
        return $this;
280
    }
281
282
    /**
283
     * Get matchedRoute
284
     *
285
     * @return string
286
     */
287 1
    public function getMatchedRoute()
288
    {
289 1
        return $this->matchedRoute;
290
    }
291
292
    /**
293
     * Set time
294
     *
295
     * @param integer $time
296
     *
297
     * @return Request
298
     */
299 2
    public function setTime($time)
300
    {
301 2
        $this->time = $time;
302
303 2
        return $this;
304
    }
305
306
    /**
307
     * Get time
308
     *
309
     * @return int
310
     */
311 1
    public function getTime()
312
    {
313 1
        return $this->time;
314
    }
315
316
    /**
317
     * Set requestMethod
318
     *
319
     * @param string $requestMethod
320
     *
321
     * @return Request
322
     */
323 5
    public function setRequestMethod($requestMethod)
324
    {
325 5
        $this->requestMethod = $requestMethod;
326
327 5
        return $this;
328
    }
329
330
    /**
331
     * Get requestMethod
332
     *
333
     * @return string
334
     */
335 2
    public function getRequestMethod()
336
    {
337 2
        return $this->requestMethod;
338
    }
339
340
    /**
341
     * Set requestBody
342
     *
343
     * @param string|resource $requestBody
344
     *
345
     * @return Request
346
     */
347 4
    public function setRequestBody($requestBody)
348
    {
349 4
        $this->requestBody = $requestBody;
0 ignored issues
show
Documentation Bug introduced by
It seems like $requestBody can also be of type resource. However, the property $requestBody is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
350
351 4
        return $this;
352
    }
353
354
    /**
355
     * Get requestBody
356
     *
357
     * @return string
358
     */
359 1
    public function getRequestBody()
360
    {
361 1
        return $this->requestBody;
362
    }
363
364
    /**
365
     * Set responseCode
366
     *
367
     * @param integer $responseCode
368
     *
369
     * @return Request
370
     */
371 2
    public function setResponseCode($responseCode)
372
    {
373 2
        $this->responseCode = $responseCode;
374
375 2
        return $this;
376
    }
377
378
    /**
379
     * Get responseCode
380
     *
381
     * @return int
382
     */
383 3
    public function getResponseCode()
384
    {
385 3
        return $this->responseCode;
386
    }
387
388
    /**
389
     * Set response
390
     *
391
     * @param string $response
392
     *
393
     * @return Request
394
     */
395 3
    public function setResponse($response)
396
    {
397 3
        $this->response = $response;
398
399 3
        return $this;
400
    }
401
402
    /**
403
     * Get response
404
     *
405
     * @return string|resource
406
     */
407 3
    public function getResponse()
408
    {
409 3
        return $this->response;
410
    }
411
412
    /**
413
     * Set clientIp
414
     *
415
     * @param string $clientIp
416
     *
417
     * @return Request
418
     */
419 5
    public function setClientIp($clientIp)
420
    {
421 5
        $this->clientIp = $clientIp;
422
423 5
        return $this;
424
    }
425
426
    /**
427
     * Get clientIp
428
     *
429
     * @return string
430
     */
431 1
    public function getClientIp()
432
    {
433 1
        return $this->clientIp;
434
    }
435
436
    /**
437
     * Set query
438
     *
439
     * @param string $query
440
     *
441
     * @return Request
442
     */
443 5
    public function setQuery($query)
444
    {
445 5
        $this->query = $query;
446
447 5
        return $this;
448
    }
449
450
    /**
451
     * Get query
452
     *
453
     * @return string
454
     */
455 1
    public function getQuery()
456
    {
457 1
        return $this->query;
458
    }
459
460
    /**
461
     * Add databaseQuery
462
     *
463
     * @param \Daken\ReleaseProfilerBundle\Entity\DatabaseQuery $databaseQuery
464
     *
465
     * @return Request
466
     */
467 2
    public function addDatabaseQuery(DatabaseQuery $databaseQuery)
468
    {
469 2
        $this->databaseQueries[] = $databaseQuery;
470 2
        $databaseQuery->setRequest($this);
471
472 2
        return $this;
473
    }
474
475
    /**
476
     * Remove databaseQuery
477
     *
478
     * @param \Daken\ReleaseProfilerBundle\Entity\DatabaseQuery $databaseQuery
479
     */
480 1
    public function removeDatabaseQuery(DatabaseQuery $databaseQuery)
481
    {
482 1
        $this->databaseQueries->removeElement($databaseQuery);
483 1
    }
484
485
    /**
486
     * Get databaseQueries
487
     *
488
     * @return DatabaseQuery[]|\Doctrine\Common\Collections\Collection
489
     */
490 2
    public function getDatabaseQueries()
491
    {
492 2
        return $this->databaseQueries;
493
    }
494
495
    /**
496
     * Add error
497
     *
498
     * @param \Daken\ReleaseProfilerBundle\Entity\Error $error
499
     *
500
     * @return Request
501
     */
502 2
    public function addError(Error $error)
503
    {
504 2
        $this->errors[] = $error;
505 2
        $error->setRequest($this);
506
507 2
        return $this;
508
    }
509
510
    /**
511
     * Remove error
512
     *
513
     * @param \Daken\ReleaseProfilerBundle\Entity\Error $error
514
     */
515 1
    public function removeError(Error $error)
516
    {
517 1
        $this->errors->removeElement($error);
518 1
    }
519
520
    /**
521
     * Get errors
522
     *
523
     * @return \Doctrine\Common\Collections\Collection
524
     */
525 2
    public function getErrors()
526
    {
527 2
        return $this->errors;
528
    }
529
530
    /**
531
     * Set schema
532
     *
533
     * @param string $scheme
534
     *
535
     * @return Request
536
     */
537 5
    public function setScheme($scheme)
538
    {
539 5
        $this->scheme = $scheme;
540
541 5
        return $this;
542
    }
543
544
    /**
545
     * Get schema
546
     *
547
     * @return string
548
     */
549 2
    public function getScheme()
550
    {
551 2
        return $this->scheme;
552
    }
553
554
    /**
555
     * Set userAgent
556
     *
557
     * @param string $userAgent
558
     *
559
     * @return Request
560
     */
561 5
    public function setUserAgent($userAgent)
562
    {
563 5
        $this->userAgent = $userAgent;
564
565 5
        return $this;
566
    }
567
568
    /**
569
     * Get userAgent
570
     *
571
     * @return string
572
     */
573 1
    public function getUserAgent()
574
    {
575 1
        return $this->userAgent;
576
    }
577
578
    /**
579
     * Set totalDatabaseQueryTime
580
     *
581
     * @param integer $totalDatabaseQueryTime
582
     *
583
     * @return Request
584
     */
585 1
    public function setTotalDatabaseQueryTime($totalDatabaseQueryTime)
586
    {
587 1
        $this->totalDatabaseQueryTime = $totalDatabaseQueryTime;
588
589 1
        return $this;
590
    }
591
592
    /**
593
     * Get totalDatabaseQueryTime
594
     *
595
     * @return integer
596
     */
597 1
    public function getTotalDatabaseQueryTime()
598
    {
599 1
        return $this->totalDatabaseQueryTime;
600
    }
601
602
    /**
603
     * Set totalDatabaseQueryCount
604
     *
605
     * @param integer $totalDatabaseQueryCount
606
     *
607
     * @return Request
608
     */
609 1
    public function setTotalDatabaseQueryCount($totalDatabaseQueryCount)
610
    {
611 1
        $this->totalDatabaseQueryCount = $totalDatabaseQueryCount;
612
613 1
        return $this;
614
    }
615
616
    /**
617
     * Get totalDatabaseQueryCount
618
     *
619
     * @return integer
620
     */
621 1
    public function getTotalDatabaseQueryCount()
622
    {
623 1
        return $this->totalDatabaseQueryCount;
624
    }
625
626 1
    public function responseAsString()
627
    {
628 1
        return $this->getResponse() ? stream_get_contents($this->getResponse()) : null;
629
    }
630
631
    /**
632
     * Set username
633
     *
634
     * @param string $username
635
     *
636
     * @return Request
637
     */
638 1
    public function setUsername($username)
639
    {
640 1
        $this->username = $username;
641
642 1
        return $this;
643
    }
644
645
    /**
646
     * Get username
647
     *
648
     * @return string
649
     */
650 1
    public function getUsername()
651
    {
652 1
        return $this->username;
653
    }
654
}
655