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/Guzzle6HttpAdapter.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 GuzzleHttp\Client;
15
use GuzzleHttp\ClientInterface;
16
use GuzzleHttp\Exception\RequestException;
17
use GuzzleHttp\Pool;
18
use GuzzleHttp\Psr7\Request;
19
use Ivory\HttpAdapter\Message\InternalRequestInterface;
20
use Ivory\HttpAdapter\Normalizer\BodyNormalizer;
21
22
/**
23
 * @author GeLo <[email protected]>
24
 */
25
class Guzzle6HttpAdapter extends AbstractHttpAdapter
26
{
27
    /**
28
     * @var ClientInterface
29
     */
30
    private $client;
31
32
    /**
33
     * @param ClientInterface|null        $client
34
     * @param ConfigurationInterface|null $configuration
35
     */
36 1138
    public function __construct(ClientInterface $client = null, ConfigurationInterface $configuration = null)
37
    {
38 1138
        parent::__construct($configuration);
39
40 1138
        $this->client = $client ?: new Client();
41 1138
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46 65
    public function getName()
47
    {
48 65
        return 'guzzle6';
49
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54 1080 View Code Duplication
    protected function sendInternalRequest(InternalRequestInterface $internalRequest)
0 ignored issues
show
This method seems to be duplicated in 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...
55
    {
56
        try {
57 1066
            $response = $this->client->send(
58 1066
                $this->createRequest($internalRequest),
59 1066
                $this->createOptions()
60 574
            );
61 592
        } catch (RequestException $e) {
62 39
            throw HttpAdapterException::cannotFetchUri(
63 39
                $e->getRequest()->getUri(),
64 39
                $this->getName(),
65 42
                $e->getMessage()
66 21
            );
67
        }
68
69 1030
        return $this->getConfiguration()->getMessageFactory()->createResponse(
70 1027
            (int) $response->getStatusCode(),
71 1027
            $response->getProtocolVersion(),
72 1027
            $response->getHeaders(),
73 1027
            BodyNormalizer::normalize(
74
                function () use ($response) {
75 1026
                    return $response->getBody()->detach();
76 1027
                },
77 1027
                $internalRequest->getMethod()
78 553
            )
79 553
        );
80
    }
81
82
    /**
83
     * {@inheritdoc}
84
     */
85 600
    protected function sendInternalRequests(array $internalRequests, $success, $error)
86
    {
87 26
        $requests = [];
88 26
        foreach ($internalRequests as $key => $internalRequest) {
89 26
            $requests[$key] = $this->createRequest($internalRequest);
90 14
        }
91
92 26
        $httpAdapter = $this;
93
94 26
        $pool = new Pool($this->client, $requests, array_merge($this->createOptions(), [
95
            'fulfilled' => function ($response, $index) use ($success, $internalRequests, $httpAdapter) {
96 26
                $response = $httpAdapter->getConfiguration()->getMessageFactory()->createResponse(
97 26
                    (int) $response->getStatusCode(),
98 26
                    $response->getProtocolVersion(),
99 26
                    $response->getHeaders(),
100 26
                    BodyNormalizer::normalize(
101
                        function () use ($response) {
102 26
                            return $response->getBody()->detach();
103 29
                        },
104 26
                        $internalRequests[$index]->getMethod()
105 14
                    )
106 14
                );
107
108 26
                $response = $response->withParameter('request', $internalRequests[$index]);
109 26
                call_user_func($success, $response);
110 26
            },
111 600 View Code Duplication
            'rejected' => function ($exception, $index) use ($error, $internalRequests, $httpAdapter) {
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...
112 13
                $exception = HttpAdapterException::cannotFetchUri(
113 13
                    $exception->getRequest()->getUri(),
114 13
                    $httpAdapter->getName(),
115 13
                    $exception->getMessage()
116 588
                );
117
118 13
                $exception->setRequest($internalRequests[$index]);
119 13
                call_user_func($error, $exception);
120 26
            },
121 14
        ]));
122
123 26
        $pool->promise()->wait();
124 26
    }
125
126
    /**
127
     * @param InternalRequestInterface $internalRequest
128
     *
129
     * @return Request
130
     */
131 1092
    private function createRequest(InternalRequestInterface $internalRequest)
132
    {
133 1092
        return new Request(
134 1092
            $internalRequest->getMethod(),
135 1092
            $internalRequest->getUri(),
136 1092
            $this->prepareHeaders($internalRequest),
137 1092
            $this->prepareBody($internalRequest),
138 1092
            $internalRequest->getProtocolVersion()
139 588
        );
140
    }
141
142
    /**
143
     * @return array
144
     */
145 1092
    private function createOptions()
146
    {
147
        return [
148 1092
            'http_errors'     => false,
149 588
            'allow_redirects' => false,
150 1092
            'timeout'         => $this->getConfiguration()->getTimeout(),
151 1092
            'connect_timeout' => $this->getConfiguration()->getTimeout(),
152 588
        ];
153
    }
154
}
155