GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Issues (153)

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/Provider/Nominatim/Nominatim.php (1 issue)

Labels
Severity

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
/*
6
 * This file is part of the Geocoder package.
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @license    MIT License
11
 */
12
13
namespace Geocoder\Provider\Nominatim;
14
15
use Geocoder\Collection;
16
use Geocoder\Exception\InvalidServerResponse;
17
use Geocoder\Exception\UnsupportedOperation;
18
use Geocoder\Location;
19
use Geocoder\Model\AddressBuilder;
20
use Geocoder\Model\AddressCollection;
21
use Geocoder\Query\GeocodeQuery;
22
use Geocoder\Query\ReverseQuery;
23
use Geocoder\Http\Provider\AbstractHttpProvider;
24
use Geocoder\Provider\Provider;
25
use Geocoder\Provider\Nominatim\Model\NominatimAddress;
26
use Http\Client\HttpClient;
27
28
/**
29
 * @author Niklas Närhinen <[email protected]>
30
 * @author Jonathan Beliën <[email protected]>
31
 */
32
final class Nominatim extends AbstractHttpProvider implements Provider
33
{
34
    /**
35
     * @var string
36
     */
37
    private $rootUrl;
38
39
    /**
40
     * @param HttpClient  $client
41
     * @param string|null $locale
0 ignored issues
show
There is no parameter named $locale. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
42
     *
43
     * @return Nominatim
44
     */
45
    public static function withOpenStreetMapServer(HttpClient $client)
46
    {
47
        return new self($client, 'https://nominatim.openstreetmap.org');
48
    }
49
50
    /**
51
     * @param HttpClient $client  an HTTP adapter
52
     * @param string     $rootUrl Root URL of the nominatim server
53
     */
54
    public function __construct(HttpClient $client, $rootUrl)
55
    {
56
        parent::__construct($client);
57
58
        $this->rootUrl = rtrim($rootUrl, '/');
59
    }
60
61
    /**
62
     * {@inheritdoc}
63
     */
64
    public function geocodeQuery(GeocodeQuery $query): Collection
65
    {
66
        $address = $query->getText();
67
        // This API does not support IPv6
68
        if (filter_var($address, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
69
            throw new UnsupportedOperation('The Nominatim provider does not support IPv6 addresses.');
70
        }
71
72
        if ('127.0.0.1' === $address) {
73
            return new AddressCollection([$this->getLocationForLocalhost()]);
74
        }
75
76
        $url = sprintf($this->getGeocodeEndpointUrl(), urlencode($address), $query->getLimit());
77
        $content = $this->executeQuery($url, $query->getLocale());
78
79
        $doc = new \DOMDocument();
80
        if (!@$doc->loadXML($content) || null === $doc->getElementsByTagName('searchresults')->item(0)) {
81
            throw InvalidServerResponse::create($url);
82
        }
83
84
        $searchResult = $doc->getElementsByTagName('searchresults')->item(0);
85
        $attribution = $searchResult->getAttribute('attribution');
86
        $places = $searchResult->getElementsByTagName('place');
87
88
        if (null === $places || 0 === $places->length) {
89
            return new AddressCollection([]);
90
        }
91
92
        $results = [];
93
        foreach ($places as $place) {
94
            $results[] = $this->xmlResultToArray($place, $place, $attribution, false);
95
        }
96
97
        return new AddressCollection($results);
98
    }
99
100
    /**
101
     * {@inheritdoc}
102
     */
103
    public function reverseQuery(ReverseQuery $query): Collection
104
    {
105
        $coordinates = $query->getCoordinates();
106
        $longitude = $coordinates->getLongitude();
107
        $latitude = $coordinates->getLatitude();
108
        $url = sprintf($this->getReverseEndpointUrl(), $latitude, $longitude, $query->getData('zoom', 18));
109
        $content = $this->executeQuery($url, $query->getLocale());
110
111
        $doc = new \DOMDocument();
112
        if (!@$doc->loadXML($content) || $doc->getElementsByTagName('error')->length > 0) {
113
            return new AddressCollection([]);
114
        }
115
116
        $searchResult = $doc->getElementsByTagName('reversegeocode')->item(0);
117
        $attribution = $searchResult->getAttribute('attribution');
118
        $addressParts = $searchResult->getElementsByTagName('addressparts')->item(0);
119
        $result = $searchResult->getElementsByTagName('result')->item(0);
120
121
        return new AddressCollection([$this->xmlResultToArray($result, $addressParts, $attribution, true)]);
122
    }
123
124
    /**
125
     * @param \DOMElement $resultNode
126
     * @param \DOMElement $addressNode
127
     *
128
     * @return Location
129
     */
130
    private function xmlResultToArray(\DOMElement $resultNode, \DOMElement $addressNode, string $attribution, bool $reverse): Location
131
    {
132
        $builder = new AddressBuilder($this->getName());
133
134
        foreach (['state', 'county'] as $i => $tagName) {
135
            if (null !== ($adminLevel = $this->getNodeValue($addressNode->getElementsByTagName($tagName)))) {
136
                $builder->addAdminLevel($i + 1, $adminLevel, '');
137
            }
138
        }
139
140
        // get the first postal-code when there are many
141
        $postalCode = $this->getNodeValue($addressNode->getElementsByTagName('postcode'));
142
        if (!empty($postalCode)) {
143
            $postalCode = current(explode(';', $postalCode));
144
        }
145
        $builder->setPostalCode($postalCode);
146
147
        $localityFields = ['city', 'town', 'village', 'hamlet'];
148
        foreach ($localityFields as $localityField) {
149
            $localityFieldContent = $this->getNodeValue($addressNode->getElementsByTagName($localityField));
150
            if (!empty($localityFieldContent)) {
151
                $builder->setLocality($localityFieldContent);
152
153
                break;
154
            }
155
        }
156
157
        $builder->setStreetName($this->getNodeValue($addressNode->getElementsByTagName('road')) ?: $this->getNodeValue($addressNode->getElementsByTagName('pedestrian')));
158
        $builder->setStreetNumber($this->getNodeValue($addressNode->getElementsByTagName('house_number')));
159
        $builder->setSubLocality($this->getNodeValue($addressNode->getElementsByTagName('suburb')));
160
        $builder->setCountry($this->getNodeValue($addressNode->getElementsByTagName('country')));
161
162
        $countryCode = $this->getNodeValue($addressNode->getElementsByTagName('country_code'));
163
        if (!empty($countryCode)) {
164
            $countryCode = strtoupper($countryCode);
165
        }
166
        $builder->setCountryCode($countryCode);
167
168
        $builder->setCoordinates($resultNode->getAttribute('lat'), $resultNode->getAttribute('lon'));
169
170
        $boundsAttr = $resultNode->getAttribute('boundingbox');
171
        if ($boundsAttr) {
172
            $bounds = [];
173
            list($bounds['south'], $bounds['north'], $bounds['west'], $bounds['east']) = explode(',', $boundsAttr);
174
            $builder->setBounds($bounds['south'], $bounds['west'], $bounds['north'], $bounds['east']);
175
        }
176
177
        $location = $builder->build(NominatimAddress::class);
178
        $location = $location->withAttribution($attribution);
179
        $location = $location->withOSMId(intval($resultNode->getAttribute('osm_id')));
180
        $location = $location->withOSMType($resultNode->getAttribute('osm_type'));
181
182
        if (false === $reverse) {
183
            $location = $location->withClass($resultNode->getAttribute('class'));
184
            $location = $location->withDisplayName($resultNode->getAttribute('display_name'));
185
            $location = $location->withType($resultNode->getAttribute('type'));
186
        } else {
187
            $location = $location->withDisplayName($resultNode->nodeValue);
188
        }
189
190
        return $location;
191
    }
192
193
    /**
194
     * {@inheritdoc}
195
     */
196
    public function getName(): string
197
    {
198
        return 'nominatim';
199
    }
200
201
    /**
202
     * @param string      $url
203
     * @param string|null $locale
204
     *
205
     * @return string
206
     */
207
    private function executeQuery(string $url, string $locale = null): string
208
    {
209
        if (null !== $locale) {
210
            $url = sprintf('%s&accept-language=%s', $url, $locale);
211
        }
212
213
        return $this->getUrlContents($url);
214
    }
215
216
    private function getGeocodeEndpointUrl(): string
217
    {
218
        return $this->rootUrl.'/search?q=%s&format=xml&addressdetails=1&limit=%d';
219
    }
220
221
    private function getReverseEndpointUrl(): string
222
    {
223
        return $this->rootUrl.'/reverse?format=xml&lat=%F&lon=%F&addressdetails=1&zoom=%d';
224
    }
225
226
    private function getNodeValue(\DOMNodeList $element)
227
    {
228
        return $element->length ? $element->item(0)->nodeValue : null;
229
    }
230
}
231