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/EventDispatcherHttpAdapter.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;
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\Message\InternalRequestInterface;
22
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
23
24
/**
25
 * @author GeLo <[email protected]>
26
 */
27
class EventDispatcherHttpAdapter extends PsrHttpAdapterDecorator
28
{
29
    /**
30
     * @var EventDispatcherInterface
31
     */
32
    private $eventDispatcher;
33
34
    /**
35
     * @param PsrHttpAdapterInterface  $httpAdapter
36
     * @param EventDispatcherInterface $eventDispatcher
37
     */
38 108
    public function __construct(PsrHttpAdapterInterface $httpAdapter, EventDispatcherInterface $eventDispatcher)
39
    {
40 108
        parent::__construct($httpAdapter);
41
42 108
        $this->eventDispatcher = $eventDispatcher;
43 108
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48 63
    protected function doSendInternalRequest(InternalRequestInterface $internalRequest)
49
    {
50
        try {
51 63
            $this->eventDispatcher->dispatch(
52 63
                Events::REQUEST_CREATED,
53 63
                $requestCreatedEvent = new RequestCreatedEvent($this, $internalRequest)
54 49
            );
55
56 63
            if ($requestCreatedEvent->hasException()) {
57 9
                throw $requestCreatedEvent->getException();
58
            }
59
60 54
            $response = $requestCreatedEvent->hasResponse()
61 44
                ? $requestCreatedEvent->getResponse()
62 54
                : parent::doSendInternalRequest($requestCreatedEvent->getRequest());
63
64 36
            $this->eventDispatcher->dispatch(
65 36
                Events::REQUEST_SENT,
66 36
                $requestSentEvent = new RequestSentEvent($this, $requestCreatedEvent->getRequest(), $response)
67 28
            );
68
69 36
            if ($requestSentEvent->hasException()) {
70 9
                throw $requestSentEvent->getException();
71
            }
72
73 27
            $response = $requestSentEvent->getResponse();
74 57
        } catch (HttpAdapterException $e) {
75 36
            $e->setRequest($internalRequest);
76 36
            $e->setResponse(isset($response) ? $response : null);
77
78 36
            $this->eventDispatcher->dispatch(
79 36
                Events::REQUEST_ERRORED,
80 36
                $exceptionEvent = new RequestErroredEvent($this, $e)
81 28
            );
82
83 36
            if ($exceptionEvent->hasResponse()) {
84 9
                return $exceptionEvent->getResponse();
85
            }
86
87 27
            throw $exceptionEvent->getException();
88
        }
89
90 27
        return $response;
91
    }
92
93
    /**
94
     * {@inheritdoc}
95
     */
96 45
    protected function doSendInternalRequests(array $internalRequests)
97
    {
98 45
        $responses = [];
99 45
        $exceptions = [];
100
101 45 View Code Duplication
        if (!empty($internalRequests)) {
0 ignored issues
show
This code seems to be duplicated across 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...
102 45
            $this->eventDispatcher->dispatch(
103 45
                Events::MULTI_REQUEST_CREATED,
104 45
                $multiRequestCreatedEvent = new MultiRequestCreatedEvent($this, $internalRequests)
105 35
            );
106
107 45
            $internalRequests = $multiRequestCreatedEvent->getRequests();
108 45
            $responses = $multiRequestCreatedEvent->getResponses();
109 45
            $exceptions = $multiRequestCreatedEvent->getExceptions();
110 35
        }
111
112
        try {
113 45
            $responses = array_merge($responses, parent::doSendInternalRequests($internalRequests));
114 39
        } catch (MultiHttpAdapterException $e) {
115 18
            $responses = array_merge($responses, $e->getResponses());
116 18
            $exceptions = array_merge($exceptions, $e->getExceptions());
117
        }
118
119 45 View Code Duplication
        if (!empty($responses)) {
0 ignored issues
show
This code seems to be duplicated across 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...
120 27
            $this->eventDispatcher->dispatch(
121 27
                Events::MULTI_REQUEST_SENT,
122 27
                $requestSentEvent = new MultiRequestSentEvent($this, $responses)
123 21
            );
124
125 27
            $exceptions = array_merge($exceptions, $requestSentEvent->getExceptions());
126 27
            $responses = $requestSentEvent->getResponses();
127 21
        }
128
129 45
        if (!empty($exceptions)) {
130 27
            $this->eventDispatcher->dispatch(
131 27
                Events::MULTI_REQUEST_ERRORED,
132 27
                $exceptionEvent = new MultiRequestErroredEvent($this, $exceptions)
133 21
            );
134
135 27
            $responses = array_merge($responses, $exceptionEvent->getResponses());
136 27
            $exceptions = $exceptionEvent->getExceptions();
137
138 27
            if (!empty($exceptions)) {
139 18
                throw new MultiHttpAdapterException($exceptions, $responses);
140
            }
141 7
        }
142
143 27
        return $responses;
144
    }
145
}
146