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/LoggerSubscriber.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
/*
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\Formatter\FormatterInterface;
16
use Ivory\HttpAdapter\Event\MultiRequestCreatedEvent;
17
use Ivory\HttpAdapter\Event\MultiRequestErroredEvent;
18
use Ivory\HttpAdapter\Event\MultiRequestSentEvent;
19
use Ivory\HttpAdapter\Event\RequestCreatedEvent;
20
use Ivory\HttpAdapter\Event\RequestErroredEvent;
21
use Ivory\HttpAdapter\Event\RequestSentEvent;
22
use Ivory\HttpAdapter\Event\Timer\TimerInterface;
23
use Ivory\HttpAdapter\HttpAdapterException;
24
use Ivory\HttpAdapter\HttpAdapterInterface;
25
use Ivory\HttpAdapter\Message\InternalRequestInterface;
26
use Ivory\HttpAdapter\Message\ResponseInterface;
27
use Psr\Log\LoggerInterface;
28
29
/**
30
 * @author GeLo <[email protected]>
31
 */
32
class LoggerSubscriber extends AbstractFormatterSubscriber
33
{
34
    /**
35
     * @var LoggerInterface
36
     */
37
    private $logger;
38
39
    /**
40
     * @param LoggerInterface         $logger
41
     * @param FormatterInterface|null $formatter
42
     * @param TimerInterface|null     $timer
43
     */
44 63
    public function __construct(
45
        LoggerInterface $logger,
46
        FormatterInterface $formatter = null,
47
        TimerInterface $timer = null
48
    ) {
49 63
        parent::__construct($formatter, $timer);
50
51 63
        $this->logger = $logger;
52 63
    }
53
54
    /**
55
     * @return LoggerInterface
56
     */
57 18
    public function getLogger()
58
    {
59 18
        return $this->logger;
60
    }
61
62
    /**
63
     * @param RequestCreatedEvent $event
64
     */
65 18
    public function onRequestCreated(RequestCreatedEvent $event)
66
    {
67 18
        $event->setRequest($this->getTimer()->start($event->getRequest()));
68 18
    }
69
70
    /**
71
     * @param RequestSentEvent $event
72
     */
73 9
    public function onRequestSent(RequestSentEvent $event)
74
    {
75 9
        $event->setRequest($this->debug($event->getHttpAdapter(), $event->getRequest(), $event->getResponse()));
76 9
    }
77
78
    /**
79
     * @param RequestErroredEvent $event
80
     */
81 9
    public function onRequestErrored(RequestErroredEvent $event)
82
    {
83 9
        $event->getException()->setRequest($this->error($event->getHttpAdapter(), $event->getException()));
84 9
    }
85
86
    /**
87
     * @param MultiRequestCreatedEvent $event
88
     */
89 18
    public function onMultiRequestCreated(MultiRequestCreatedEvent $event)
90
    {
91 18
        foreach ($event->getRequests() as $request) {
92 18
            $event->removeRequest($request);
93 18
            $event->addRequest($this->getTimer()->start($request));
94 14
        }
95 18
    }
96
97
    /**
98
     * @param MultiRequestSentEvent $event
99
     */
100 9 View Code Duplication
    public function onMultiRequestSent(MultiRequestSentEvent $event)
101
    {
102 9
        foreach ($event->getResponses() as $response) {
103 9
            $request = $this->debug($event->getHttpAdapter(), $response->getParameter('request'), $response);
104
105 9
            $event->removeResponse($response);
106 9
            $event->addResponse($response->withParameter('request', $request));
0 ignored issues
show
$response->withParameter('request', $request) of type object<Ivory\HttpAdapter...ssage\MessageInterface> is not a sub-type of object<Ivory\HttpAdapter...sage\ResponseInterface>. It seems like you assume a child interface of the interface Ivory\HttpAdapter\Message\MessageInterface to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
107 7
        }
108 9
    }
109
110
    /**
111
     * @param MultiRequestErroredEvent $event
112
     */
113 9
    public function onMultiResponseErrored(MultiRequestErroredEvent $event)
114
    {
115 9
        foreach ($event->getExceptions() as $exception) {
116 9
            $exception->setRequest($this->error($event->getHttpAdapter(), $exception));
117 7
        }
118 9
    }
119
120
    /**
121
     * {@inheritdoc}
122
     */
123 9 View Code Duplication
    public static function getSubscribedEvents()
124
    {
125
        return [
126 9
            Events::REQUEST_CREATED       => ['onRequestCreated', 100],
127 7
            Events::REQUEST_SENT          => ['onRequestSent', 100],
128 7
            Events::REQUEST_ERRORED       => ['onRequestErrored', 100],
129 7
            Events::MULTI_REQUEST_CREATED => ['onMultiRequestCreated', 100],
130 7
            Events::MULTI_REQUEST_SENT    => ['onMultiRequestSent', 100],
131 7
            Events::MULTI_REQUEST_ERRORED => ['onMultiResponseErrored', 100],
132 7
        ];
133
    }
134
135
    /**
136
     * @param HttpAdapterInterface     $httpAdapter
137
     * @param InternalRequestInterface $request
138
     * @param ResponseInterface        $response
139
     *
140
     * @return InternalRequestInterface
141
     */
142 18
    private function debug(
143
        HttpAdapterInterface $httpAdapter,
144
        InternalRequestInterface $request,
145
        ResponseInterface $response
146
    ) {
147 18
        $request = $this->getTimer()->stop($request);
148
149 18
        $this->logger->debug(
150 14
            sprintf(
151 18
                'Send "%s %s" in %.2f ms.',
152 18
                $request->getMethod(),
153 18
                (string) $request->getUri(),
154 18
                $request->getParameter(TimerInterface::TIME)
155 14
            ),
156
            [
157 18
                'adapter'  => $httpAdapter->getName(),
158 18
                'request'  => $this->getFormatter()->formatRequest($request),
159 18
                'response' => $this->getFormatter()->formatResponse($response),
160
            ]
161 14
        );
162
163 18
        return $request;
164
    }
165
166
    /**
167
     * @param HttpAdapterInterface $httpAdapter
168
     * @param HttpAdapterException $exception
169
     *
170
     * @return InternalRequestInterface
171
     */
172 18
    private function error(HttpAdapterInterface $httpAdapter, HttpAdapterException $exception)
173
    {
174 18
        $request = $this->getTimer()->stop($exception->getRequest());
175
176 18
        $this->logger->error(
177 14
            sprintf(
178 18
                'Unable to send "%s %s".',
179 18
                $exception->getRequest()->getMethod(),
180 18
                (string) $exception->getRequest()->getUri()
181 14
            ),
182
            [
183 18
                'adapter'   => $httpAdapter->getName(),
184 18
                'exception' => $this->getFormatter()->formatException($exception),
185 18
                'request'   => $this->getFormatter()->formatRequest($request),
186 18
                'response'  => $exception->hasResponse()
187 18
                    ? $this->getFormatter()->formatResponse($exception->getResponse())
188 14
                    : null,
189
            ]
190 14
        );
191
192 18
        return $request;
193
    }
194
}
195