Issues (100)

Security Analysis    no request data  

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/V4/IsmpApi.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
declare(strict_types=1);
4
5
namespace Lamoda\IsmpClient\V4;
6
7
use GuzzleHttp\ClientInterface;
8
use GuzzleHttp\Exception\BadResponseException;
9
use GuzzleHttp\RequestOptions;
10
use Lamoda\IsmpClient\Exception\IsmpGeneralErrorException;
11
use Lamoda\IsmpClient\Exception\IsmpRequestErrorException;
12
use Lamoda\IsmpClient\Serializer\SerializerInterface;
13
use Lamoda\IsmpClient\V3\Dto\AuthCertKeyResponse;
14
use Lamoda\IsmpClient\V3\Dto\AuthCertRequest;
15
use Lamoda\IsmpClient\V3\Dto\AuthCertResponse;
16
use Lamoda\IsmpClient\V3\Dto\DocumentCreateRequest;
17
use Lamoda\IsmpClient\V3\Dto\FacadeDocListV2Query;
18
use Lamoda\IsmpClient\V3\Dto\FacadeDocListV2Response;
19
use Lamoda\IsmpClient\V3\Dto\FacadeMarkedProductsResponse;
20
use Lamoda\IsmpClient\V3\Dto\ProductInfoResponse;
21
use Lamoda\IsmpClient\V3\IsmpApi as IsmpApiV3;
22
use Lamoda\IsmpClient\V3\IsmpApiInterface as IsmpApiV3Interface;
23
use Lamoda\IsmpClient\V4\Dto\FacadeCisListRequest;
24
use Lamoda\IsmpClient\V4\Dto\FacadeCisListResponse;
25
use Lamoda\IsmpClient\V4\Dto\FacadeDocBodyResponse;
26
27
class IsmpApi implements IsmpApiInterface
28
{
29
    /**
30
     * @var ClientInterface
31
     */
32
    private $client;
33
    /**
34
     * @var SerializerInterface
35
     */
36
    private $serializer;
37
    /**
38
     * @var IsmpApiV3|IsmpApiV3Interface
39
     */
40
    private $ismpApiV3;
41
42 15
    public function __construct(ClientInterface $client, SerializerInterface $serializer, ?IsmpApiV3Interface $ismpApiV3 = null)
43
    {
44 15
        $this->client = $client;
45 15
        $this->serializer = $serializer;
46 15
        $this->ismpApiV3 = $ismpApiV3 ?? new IsmpApiV3($client, $serializer);
47 15
    }
48
49 6
    public function facadeDocBody(string $token, string $docId, ?int $limit = null, ?string $orderColumn = null, ?string $orderedColumnValue = null, ?string $pageDir = null): FacadeDocBodyResponse
50
    {
51 6
        $query = null;
52 6
        if ($limit !== null) {
53 2
            $query['limit'] = $limit;
54
        }
55 6
        if ($orderColumn !== null) {
56 2
            $query['orderColumn'] = $orderColumn;
57
        }
58 6
        if ($orderedColumnValue !== null) {
59 2
            $query['orderedColumnValue'] = $orderedColumnValue;
60
        }
61 6
        if ($pageDir !== null) {
62 2
            $query['pageDir'] = $pageDir;
63
        }
64
65 6
        $result = $this->request('GET', sprintf('/api/v4/facade/doc/%s/body', $docId), null, $query, $token);
66
67
        /* @noinspection PhpIncompatibleReturnTypeInspection */
68 6
        return $this->serializer->deserialize(FacadeDocBodyResponse::class, $result);
69
    }
70
71 1
    public function facadeCisList(string $token, FacadeCisListRequest $request): FacadeCisListResponse
72
    {
73 1
        $body = $this->serializer->serialize($request);
0 ignored issues
show
$request is of type object<Lamoda\IsmpClient...o\FacadeCisListRequest>, but the function expects a object<Lamoda\IsmpClient\Serializer\object>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
74 1
        $response = $this->request('POST', '/api/v4/facade/cis/cis_list', $body, null, $token);
75
76
        /* @noinspection PhpIncompatibleReturnTypeInspection */
77 1
        return $this->serializer->deserialize(FacadeCisListResponse::class, $response);
78
    }
79
80 3
    public function authCertKey(): AuthCertKeyResponse
81
    {
82 3
        return $this->ismpApiV3->authCertKey();
83
    }
84
85 2
    public function authCert(AuthCertRequest $request, ?string $connection = null): AuthCertResponse
86
    {
87 2
        return $this->ismpApiV3->authCert($request, $connection);
88
    }
89
90 1
    public function facadeDocListV2(string $token, FacadeDocListV2Query $query): FacadeDocListV2Response
91
    {
92 1
        return $this->ismpApiV3->facadeDocListV2($token, $query);
93
    }
94
95 1
    public function lkDocumentsCreate(string $token, DocumentCreateRequest $request): string
96
    {
97 1
        return $this->ismpApiV3->lkDocumentsCreate($token, $request);
98
    }
99
100 1
    public function productInfo(string $token, array $gtins): ProductInfoResponse
101
    {
102 1
        return $this->ismpApiV3->productInfo($token, $gtins);
103
    }
104
105
    public function facadeMarkedProducts(string $token, string $cis): FacadeMarkedProductsResponse
106
    {
107
        return $this->ismpApiV3->facadeMarkedProducts($token, $cis);
108
    }
109
110 7
    private function request(string $method, string $uri, $body = null, $query = null, string $token = null): string
111
    {
112
        $options = [
113 7
            RequestOptions::BODY => $body,
114
            RequestOptions::HEADERS => [
115
                'Content-Type' => 'application/json',
116
            ],
117
            RequestOptions::HTTP_ERRORS => true,
118 7
            RequestOptions::QUERY => $query,
119
        ];
120
121 7
        if ($token) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $token of type null|string is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
122 7
            $options[RequestOptions::HEADERS]['Authorization'] = 'Bearer ' . $token;
123
        }
124
125 7
        $uri = ltrim($uri, '/');
126
127
        try {
128 7
            $result = $this->client->request($method, $uri, $options);
129
        } catch (\Throwable $exception) {
130
            /* @noinspection PhpUnhandledExceptionInspection */
131
            throw $this->handleRequestException($exception);
132
        }
133
134 7
        return (string)$result->getBody();
135
    }
136
137
    private function handleRequestException(\Throwable $exception): \Throwable
138
    {
139
        if ($exception instanceof BadResponseException) {
140
            $response = $exception->getResponse();
141
            $responseBody = $response ? (string)$response->getBody() : '';
142
            $responseCode = $response ? $response->getStatusCode() : 0;
143
144
            return IsmpRequestErrorException::becauseOfErrorResponse($responseCode, $responseBody, $exception);
145
        }
146
147
        return IsmpGeneralErrorException::becauseOfError($exception);
148
    }
149
}
150