Issues (6)

Security Analysis    no request data  

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  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.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  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.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  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.
  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.
  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.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
  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.
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  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.
  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.
  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.
  Header Injection
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/Artax/functions.php (2 issues)

1
<?php
2
3
/**
4
 * Abstraction over Http client implementations.
5
 *
6
 * @author  Maksim Masiukevich <[email protected]>
7
 * @license MIT
8
 * @license https://opensource.org/licenses/MIT
9
 */
10
11
declare(strict_types = 0);
12
13
namespace ServiceBus\HttpClient\Artax;
14
15
use Amp\CancelledException;
16
use Amp\Dns\DnsException;
17
use Amp\Dns\NoRecordException;
18
use Amp\Http\Client\ParseException;
19
use Amp\Http\Client\Request;
20
use Amp\Http\Client\SocketException;
21
use Amp\Http\Client\TimeoutException;
22
use Amp\Promise;
23
use GuzzleHttp\Psr7\Response;
24
use Psr\Log\LoggerInterface;
25
use ServiceBus\HttpClient\Exception as HttpClientExceptions;
26
use function ServiceBus\Common\throwableMessage;
0 ignored issues
show
The function ServiceBus\Common\throwableMessage was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
27
28
/**
29
 * Download file.
30
 *
31
 * @api
32
 *
33
 * @return Promise<string>
34
 *
35
 * @throws \ServiceBus\HttpClient\Exception\HttpClientException
36
 * @throws \ServiceBus\HttpClient\Exception\ConnectionFailed
37
 * @throws \ServiceBus\HttpClient\Exception\DnsResolveFailed
38
 * @throws \ServiceBus\HttpClient\Exception\IncorrectParameters
39
 * @throws \ServiceBus\HttpClient\Exception\RequestTimeoutReached
40
 */
41
function downloadFile(string $url, string $toDirectory, string $withName): Promise
42
{
43 1
    return (new ArtaxHttpClient())->download($url, $toDirectory, $withName);
44
}
45
46
/**
47
 * @internal
48
 */
49 3
function logArtaxRequest(LoggerInterface $logger, Request $request, string $requestId): \Generator
50
{
51 3
    $logger->debug(
52 3
        'Request: [{requestMethod}] {requestUri} {requestHeaders}',
53
        [
54 3
            'requestMethod'  => $request->getMethod(),
55 3
            'requestUri'     => $request->getUri(),
56 3
            'requestContent' => yield $request->getBody()->createBodyStream()->read(),
57 3
            'requestHeaders' => $request->getHeaders(),
58 3
            'requestId'      => $requestId,
59
        ]
60
    );
61 3
}
62
63
/**
64
 * @internal
65
 *
66
 * @return void
67
 */
68
function logArtaxResponse(LoggerInterface $logger, Response $response, string $requestId, string $executionTime): void
69
{
70 1
    $logger->debug(
71 1
        'Response: {responseHttpCode} {responseContent} {responseHeaders}',
72
        [
73 1
            'responseHttpCode' => $response->getStatusCode(),
74 1
            'responseContent'  => (string) $response->getBody(),
75 1
            'responseHeaders'  => $response->getHeaders(),
76 1
            'requestId'        => $requestId,
77 1
            'executionTime'    => \sprintf('%.2f', $executionTime)
78
        ]
79
    );
80 1
}
81
82
/**
83
 * @internal
84
 *
85
 * @return void
86
 */
87
function logArtaxThrowable(LoggerInterface $logger, \Throwable $throwable, string $requestId, string $executionTime): void
88
{
89 2
    $logger->error(
90 2
        'During the execution of the request with identifier "{requestId}" an exception was caught: "{throwableMessage}"',
91
        [
92 2
            'requestId'        => $requestId,
93 2
            'throwableMessage' => throwableMessage($throwable),
0 ignored issues
show
The function throwableMessage was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

93
            'throwableMessage' => /** @scrutinizer ignore-call */ throwableMessage($throwable),
Loading history...
94 2
            'throwablePoint'   => \sprintf('%s:%d', $throwable->getFile(), $throwable->getLine()),
95 2
            'executionTime'    => \sprintf('%.2f', $executionTime)
96
        ]
97
    );
98 2
}
99
100
/**
101
 * @internal
102
 *
103
 * @return \Throwable
104
 */
105
function adaptArtaxThrowable(\Throwable $throwable): \Throwable
106
{
107
    /** @psalm-var array<class-string<\Amp\Http\Client\HttpException>, class-string<\Exception>> $mapping */
108 2
    $mapping = [
109
        NoRecordException::class  => HttpClientExceptions\DnsResolveFailed::class,
110
        DnsException::class       => HttpClientExceptions\DnsResolveFailed::class,
111
        SocketException::class    => HttpClientExceptions\ConnectionFailed::class,
112
        ParseException::class     => HttpClientExceptions\IncorrectParameters::class,
113
        TimeoutException::class   => HttpClientExceptions\RequestTimeoutReached::class,
114
        CancelledException::class => HttpClientExceptions\RequestTimeoutReached::class,
115
    ];
116
117
    /** @psalm-var class-string<\Amp\Http\Client\HttpException> $exceptionClass */
118 2
    $exceptionClass = \get_class($throwable);
119
120 2
    if (isset($mapping[$exceptionClass]))
121
    {
122
        /** @var class-string<\Exception> $exceptionClass */
123 1
        $exceptionClass = $mapping[$exceptionClass];
124
125
        /** @psalm-suppress UnsafeInstantiation */
126 1
        return new $exceptionClass($throwable->getMessage(), (int) $throwable->getCode(), $throwable);
127
    }
128
129 1
    return new HttpClientExceptions\HttpClientException(
130 1
        $throwable->getMessage(),
131 1
        (int) $throwable->getCode(),
132
        $throwable
133
    );
134
}
135