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/Guzzle3HttpAdapter.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;
13
14
use Guzzle\Common\Event;
15
use Guzzle\Http\Client;
16
use Guzzle\Http\ClientInterface;
17
use Guzzle\Http\Exception\RequestException;
18
use Ivory\HttpAdapter\Message\InternalRequestInterface;
19
use Ivory\HttpAdapter\Normalizer\BodyNormalizer;
20
21
/**
22
 * @author GeLo <[email protected]>
23
 */
24
class Guzzle3HttpAdapter extends AbstractCurlHttpAdapter
25
{
26
    /**
27
     * @var ClientInterface
28
     */
29
    private $client;
30
31
    /**
32
     * @param ClientInterface|null        $client
33
     * @param ConfigurationInterface|null $configuration
34
     */
35 705
    public function __construct(ClientInterface $client = null, ConfigurationInterface $configuration = null)
36
    {
37 705
        parent::__construct($configuration);
38
39 704
        $this->client = $client ?: new Client();
40 704
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45 49
    public function getName()
46
    {
47 49
        return 'guzzle3';
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53 674
    protected function sendInternalRequest(InternalRequestInterface $internalRequest)
54
    {
55
        try {
56 656
            $response = $this->createRequest($internalRequest)->send();
57 498
        } catch (RequestException $e) {
58 24
            throw HttpAdapterException::cannotFetchUri(
59 24
                $e->getRequest()->getUrl(),
0 ignored issues
show
It seems like $e->getRequest()->getUrl() targeting Guzzle\Http\Message\RequestInterface::getUrl() can also be of type object<Guzzle\Http\Url>; however, Ivory\HttpAdapter\HttpAd...ption::cannotFetchUri() does only seem to accept string, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
60 24
                $this->getName(),
61 24
                $e->getMessage()
62 18
            );
63
        }
64
65 632
        return $this->getConfiguration()->getMessageFactory()->createResponse(
66 632
            $response->getStatusCode(),
67 632
            $response->getProtocolVersion(),
68 632
            $response->getHeaders()->toArray(),
69 632
            BodyNormalizer::normalize(
70
                function () use ($response) {
71 584
                    $resource = $response->getBody()->getStream();
72 584
                    $response->getBody()->detachStream();
73
74 584
                    return $resource;
75 668
                },
76 632
                $internalRequest->getMethod()
77 474
            )
78 474
        );
79 6
    }
80
81
    /**
82
     * {@inheritdoc}
83
     */
84 16
    protected function sendInternalRequests(array $internalRequests, $success, $error)
85
    {
86 16
        $requests = [];
87 16
        foreach ($internalRequests as $internalRequest) {
88 16
            $requests[] = $this->createRequest($internalRequest, $success, $error);
89 12
        }
90
91
        try {
92 16
            $this->client->send($requests);
93 14
        } catch (\Exception $e) {
94
        }
95 16
    }
96
97
    /**
98
     * {@inheritdoc}
99
     */
100 80
    protected function createFile($file)
101
    {
102 80
        return '@'.$file;
103
    }
104
105
    /**
106
     * @param InternalRequestInterface $internalRequest
107
     * @param callable|null            $success
108
     * @param callable|null            $error
109
     *
110
     * @return RequestInterface
111
     */
112 672
    private function createRequest(InternalRequestInterface $internalRequest, $success = null, $error = null)
113
    {
114 672
        $request = $this->client->createRequest(
115 672
            $internalRequest->getMethod(),
116 672
            (string) $internalRequest->getUri(),
117 672
            $this->prepareHeaders($internalRequest),
118 672
            $this->prepareContent($internalRequest),
119
            [
120 672
                'exceptions'      => false,
121 504
                'allow_redirects' => false,
122 672
                'timeout'         => $this->getConfiguration()->getTimeout(),
123 672
                'connect_timeout' => $this->getConfiguration()->getTimeout(),
124
            ]
125 504
        );
126
127 672
        $request->setProtocolVersion($internalRequest->getProtocolVersion());
128
129 672
        if (is_callable($success)) {
130 16
            $messageFactory = $this->getConfiguration()->getMessageFactory();
131
132 16
            $request->getEventDispatcher()->addListener(
133 16
                'request.success',
134
                function (Event $event) use ($messageFactory, $success, $internalRequest) {
135 16
                    $response = $messageFactory->createResponse(
136 16
                        $event['response']->getStatusCode(),
137 16
                        $event['response']->getProtocolVersion(),
138 16
                        $event['response']->getHeaders()->toArray(),
139 16
                        BodyNormalizer::normalize(
140
                            function () use ($event) {
141 16
                                $resource = $event['response']->getBody()->getStream();
142 16
                                $event['response']->getBody()->detachStream();
143
144 16
                                return $resource;
145 16
                            },
146 16
                            $internalRequest->getMethod()
147 12
                        )
148 12
                    );
149
150 16
                    $response = $response->withParameter('request', $internalRequest);
151 16
                    call_user_func($success, $response);
152 16
                }
153 12
            );
154 12
        }
155
156 672
        if (is_callable($error)) {
157 16
            $httpAdapterName = $this->getName();
158
159 16
            $request->getEventDispatcher()->addListener(
160 16
                'request.exception',
161 10
                function (Event $event) use ($error, $internalRequest, $httpAdapterName) {
162 8
                    $exception = HttpAdapterException::cannotFetchUri(
163 8
                        $event['exception']->getRequest()->getUrl(),
164 6
                        $httpAdapterName,
165 8
                        $event['exception']->getMessage()
166 6
                    );
167
168 8
                    $exception->setRequest($internalRequest);
169 8
                    call_user_func($error, $exception);
170 10
                }
171 12
            );
172 12
        }
173
174 672
        return $request;
175
    }
176
}
177