Issues (89)

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/Event/Subscriber/StopwatchSubscriber.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
/*
4
 * This file is part of the Ivory Http Adapter package.
5
 *
6
 * (c) Eric GELOEN <[email protected]>
7
 *
8
 * For the full copyright and license information, please read the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Ivory\HttpAdapter\Event\Subscriber;
13
14
use Ivory\HttpAdapter\Event\Events;
15
use Ivory\HttpAdapter\Event\MultiRequestCreatedEvent;
16
use Ivory\HttpAdapter\Event\MultiRequestErroredEvent;
17
use Ivory\HttpAdapter\Event\MultiRequestSentEvent;
18
use Ivory\HttpAdapter\Event\RequestCreatedEvent;
19
use Ivory\HttpAdapter\Event\RequestErroredEvent;
20
use Ivory\HttpAdapter\Event\RequestSentEvent;
21
use Ivory\HttpAdapter\HttpAdapterInterface;
22
use Ivory\HttpAdapter\Message\InternalRequestInterface;
23
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
24
use Symfony\Component\Stopwatch\Stopwatch;
25
26
/**
27
 * @author GeLo <[email protected]>
28
 */
29
class StopwatchSubscriber implements EventSubscriberInterface
30
{
31
    /**
32
     * @var Stopwatch
33
     */
34
    private $stopwatch;
35
36
    /**
37
     * @param Stopwatch $stopwatch
38
     */
39 72
    public function __construct(Stopwatch $stopwatch)
40
    {
41 72
        $this->stopwatch = $stopwatch;
42 72
    }
43
44
    /**
45
     * @return Stopwatch
46
     */
47 9
    public function getStopwatch()
48
    {
49 9
        return $this->stopwatch;
50
    }
51
52
    /**
53
     * @param RequestCreatedEvent $event
54
     */
55 9
    public function onRequestCreated(RequestCreatedEvent $event)
56
    {
57 9
        $this->stopwatch->start($this->getStopwatchName($event->getHttpAdapter(), $event->getRequest()));
58 9
    }
59
60
    /**
61
     * @param RequestSentEvent $event
62
     */
63 9
    public function onRequestSent(RequestSentEvent $event)
64
    {
65 9
        if (!$event->hasException()) {
66 9
            $this->stopwatch->stop($this->getStopwatchName($event->getHttpAdapter(), $event->getRequest()));
67 7
        }
68 9
    }
69
70
    /**
71
     * @param RequestErroredEvent $event
72
     */
73 9
    public function onRequestErrored(RequestErroredEvent $event)
74
    {
75 9
        $this->stopwatch->stop($this->getStopwatchName($event->getHttpAdapter(), $event->getException()->getRequest()));
0 ignored issues
show
It seems like $event->getException()->getRequest() can be null; however, getStopwatchName() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
76 9
    }
77
78
    /**
79
     * @param MultiRequestCreatedEvent $event
80
     */
81 9
    public function onMultiRequestCreated(MultiRequestCreatedEvent $event)
82
    {
83 9
        foreach ($event->getRequests() as $request) {
84 9
            $this->stopwatch->start($this->getStopwatchName($event->getHttpAdapter(), $request));
85 7
        }
86 9
    }
87
88
    /**
89
     * @param MultiRequestSentEvent $event
90
     */
91 9
    public function onMultiRequestSent(MultiRequestSentEvent $event)
92
    {
93 9
        foreach ($event->getResponses() as $response) {
94 9
            $this->stopwatch->stop(
95 9
                $this->getStopwatchName($event->getHttpAdapter(), $response->getParameter('request'))
96 7
            );
97 7
        }
98 9
    }
99
100
    /**
101
     * @param MultiRequestErroredEvent $event
102
     */
103 9
    public function onMultiResponseErrored(MultiRequestErroredEvent $event)
104
    {
105 9
        foreach ($event->getResponses() as $response) {
106 9
            $this->stopwatch->stop(
107 9
                $this->getStopwatchName($event->getHttpAdapter(), $response->getParameter('request'))
108 7
            );
109 7
        }
110
111 9
        foreach ($event->getExceptions() as $exception) {
112 9
            $this->stopwatch->stop(
113 9
                $this->getStopwatchName($event->getHttpAdapter(), $exception->getRequest())
0 ignored issues
show
It seems like $exception->getRequest() can be null; however, getStopwatchName() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
114 7
            );
115 7
        }
116 9
    }
117
118
    /**
119
     * {@inheritdoc}
120
     */
121 9 View Code Duplication
    public static function getSubscribedEvents()
122
    {
123
        return [
124 9
            Events::REQUEST_CREATED       => ['onRequestCreated', 10000],
125 7
            Events::REQUEST_SENT          => ['onRequestSent', -10000],
126 7
            Events::REQUEST_ERRORED       => ['onRequestErrored', -10000],
127 7
            Events::MULTI_REQUEST_CREATED => ['onMultiRequestCreated', 10000],
128 7
            Events::MULTI_REQUEST_SENT    => ['onMultiRequestSent', -10000],
129 7
            Events::MULTI_REQUEST_ERRORED => ['onMultiResponseErrored', -10000],
130 7
        ];
131
    }
132
133
    /**
134
     * @param HttpAdapterInterface     $httpAdapter
135
     * @param InternalRequestInterface $internalRequest
136
     *
137
     * @return string
138
     */
139 54
    private function getStopwatchName(HttpAdapterInterface $httpAdapter, InternalRequestInterface $internalRequest)
140
    {
141 54
        return sprintf('ivory.http_adapter.%s (%s)', $httpAdapter->getName(), (string) $internalRequest->getUri());
142
    }
143
}
144