Issues (302)

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/Yandex/SiteSearchPinger/SiteSearchPinger.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
 * Yandex PHP Library
4
 *
5
 * @copyright NIX Solutions Ltd.
6
 * @link https://github.com/nixsolutions/yandex-php-library
7
 */
8
9
/**
10
 * @namespace
11
 */
12
namespace Yandex\SiteSearchPinger;
13
14
use Yandex\Common\AbstractServiceClient;
15
use Yandex\Common\Exception\InvalidArgumentException;
16
use Yandex\SiteSearchPinger\Exception\InvalidUrlException;
17
use Yandex\SiteSearchPinger\Exception\SiteSearchPingerException;
18
use GuzzleHttp\Psr7\Response;
19
use GuzzleHttp\Exception\ClientException;
20
21
/**
22
 * SiteSearchPinger
23
 *
24
 * @category Yandex
25
 * @package  SiteSearchPinger
26
 *
27
 * @property string $key
28
 * @property string $login
29
 * @property string $searchId
30
 * @property array $invalidUrls
31
 *
32
 * @author   Anton Shevchuk
33
 * @created  06.08.13 17:30
34
 */
35
class SiteSearchPinger extends AbstractServiceClient
36
{
37
    const DECODE_TYPE_DEFAULT = self::DECODE_TYPE_XML;
38
39
    /**
40
     * @var string
41
     */
42
    protected $serviceScheme = self::HTTP_SCHEME;
43
44
    /**
45
     * @var string
46
     */
47
    protected $serviceProtocolVersion = '1.0';
48
49
    /**
50
     * @var string
51
     */
52
    protected $serviceDomain = "site.yandex.ru";
53
54
    /**
55
     * @var string
56
     */
57
    protected $path = "ping.xml";
58
59
    /**
60
     * @var string
61
     */
62
    protected $key;
63
64
    /**
65
     * @var string
66
     */
67
    protected $login;
68
69
    /**
70
     * @var string
71
     */
72
    protected $searchId;
73
74
    /**
75
     * Connection Errors
76
     */
77
    const ERROR_ILLEGAL_PARAM_VALUE = 'ILLEGAL_PARAM_VALUE';
78
    const ERROR_ILLEGAL_VALUE_TYPE = 'ILLEGAL_VALUE_TYPE';
79
    const ERROR_NO_SUCH_USER_IN_PASSPORT = 'NO_SUCH_USER_IN_PASSPORT';
80
    const ERROR_SEARCH_NOT_OWNED_BY_USER = 'SEARCH_NOT_OWNED_BY_USER';
81
    const ERROR_TOO_DELAYED_PUBLISH = 'TOO_DELAYED_PUBLISH';
82
    const ERROR_USER_NOT_PERMITTED = 'USER_NOT_PERMITTED';
83
84
    /**
85
     * URL Errors
86
     */
87
    const INVALID_MALFORMED_URLS = 'MALFORMED_URLS';
88
    const INVALID_NOT_CONFIRMED_IN_WMC = 'NOT_CONFIRMED_IN_WMC';
89
    const INVALID_OUT_OF_SEARCH_AREA = 'OUT_OF_SEARCH_AREA';
90
91
    /**
92
     * @var array
93
     */
94
    protected $invalid = [
95
        self::INVALID_MALFORMED_URLS => "Invalid URL format",
96
        self::INVALID_NOT_CONFIRMED_IN_WMC => "Invalid site URL. Site is not confirmed on http://webmaster.yandex.ru/",
97
        self::INVALID_OUT_OF_SEARCH_AREA => "Invalid site URL. Site is not under your search area",
98
    ];
99
100
    /**
101
     * @var array
102
     */
103
    protected $invalidUrls = [];
104
105
    /**
106
     * set search key
107
     *
108
     * @param $value
109
     * @return self
110
     */
111 6
    public function setKey($value)
112
    {
113 6
        $this->key = $value;
114 6
        return $this;
115
    }
116
117
    /**
118
     * set search login
119
     *
120
     * @param $value
121
     * @return self
122
     */
123 6
    public function setLogin($value)
124
    {
125 6
        $this->login = $value;
126 6
        return $this;
127
    }
128
129
    /**
130
     * set search id
131
     *
132
     * @param $value
133
     * @return self
134
     */
135 6
    public function setSearchId($value)
136
    {
137 6
        $this->searchId = $value;
138 6
        return $this;
139
    }
140
141
    /**
142
     * get invalid Urls from request
143
     *
144
     * @return array
145
     */
146 1
    public function getInvalidUrls()
147
    {
148 1
        return $this->invalidUrls;
149
    }
150
151
    /**
152
     * ping
153
     *
154
     * @param string|array $urls
155
     * @param integer $publishDate seconds from now to publish urls
156
     *
157
     * @throws Exception\SiteSearchPingerException
158
     * @throws Exception\InvalidUrlException
159
     * @throws \Yandex\Common\Exception\InvalidArgumentException
160
     * @return int
161
     */
162 7
    public function ping($urls, $publishDate = 0)
163
    {
164 7
        $this->checkSettings();
165
166 6
        $urls = (array)$urls;
167
168
        try {
169 6
            $response = $this->doRequest($urls, $publishDate);
170 3
        } catch (ClientException $e) {
171 3
            $xml = $this->getDecodedBody($e->getResponse()->getBody());
172
173 3
            if (isset($xml->error) && isset($xml->error->message)) {
174 2
                $errorMessage = (string) $xml->error->message;
175 2
                if (isset($xml->error->param) && isset($xml->error->value)) {
176 1
                    $errorMessage .= " (".$xml->error->param." is ".$xml->error->value.")";
177
                }
178 2
                throw new InvalidArgumentException($errorMessage);
179
            }
180 1
            return 0;
181
        }
182
183 3
        if (!$xml = $this->getDecodedBody($response->getBody())) {
184 1
            throw new SiteSearchPingerException("Wrong server response format");
185 2
        } elseif ($xml->getName() == 'empty-param') {
186
            // workaround for invalid request, with empty `urls`
187 1
            throw new InvalidUrlException("URL param is required");
188
        }
189
190
        // retrieve count of valid urls
191 1
        $addedCount = 0;
192 1
        if (isset($xml->added) && isset($xml->added['count'])) {
193 1
            $addedCount = (int)$xml->added['count'];
194
        }
195
196
        // check invalid urls and fill errors stack
197 1
        $this->invalidUrls = [];
198 1
        if (isset($xml->invalid)) {
199 1
            foreach ($xml->invalid as $invalid) {
200 1
                foreach ($invalid as $url) {
201 1
                    $this->invalidUrls[(string)$url] = $this->invalid[(string) $invalid['reason']];
202
                }
203
            }
204
        }
205
206 1
        return $addedCount;
207
    }
208
209
    /**
210
     * doCheckOptions
211
     *
212
     * @return boolean
213
     */
214 7
    protected function doCheckSettings()
215
    {
216 7
        return $this->key && $this->login && $this->searchId;
217
    }
218
219
    /**
220
     * @param array $urls
221
     * @param integer $publishDate
222
     *
223
     * @return Response;
0 ignored issues
show
The doc-type Response; could not be parsed: Expected "|" or "end of type", but got ";" at position 8. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
224
     */
225 6
    protected function doRequest($urls, $publishDate)
226
    {
227 6
        $client = $this->getClient();
228
229 6
        return $client->request(
230 6
            'POST',
231 6
            '/' . $this->path,
232
            [
233 6
                'version' => $this->serviceProtocolVersion,
234
                'form_params' => [
235 6
                    'urls' => join("\n", $urls),
236 6
                    'publishdate' => $publishDate
237
                ],
238
                'query' => [
239 6
                    'key' => $this->key,
240 6
                    'login' => $this->login,
241 6
                    'search_id' => $this->searchId
242
                ],
243
                'headers' => [
244
                    'Y-SDK' => 'Pinger'
245
                ]
246
            ]
247
        );
248
    }
249
}
250