Issues (843)

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.

libs/geoPHP/lib/adapters/GoogleGeocode.class.php (6 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
 * (c) Camptocamp <[email protected]>
4
 * (c) Patrick Hayes
5
 *
6
 * This code is open-source and licenced under the Modified BSD License.
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
/**
12
 * PHP Google Geocoder Adapter
13
 *
14
 *
15
 * @package    geoPHP
16
 * @author     Patrick Hayes <[email protected]>
17
 */
18
class GoogleGeocode extends GeoAdapter
19
{
20
21
  /**
22
   * Read an address string or array geometry objects
23
   *
24
   * @param string - Address to geocode
25
   * @param string - Type of Geometry to return. Can either be 'points' or 'bounds' (polygon)
26
   * @param Geometry|bounds-array - Limit the search area to within this region. For example
27
   *                                by default geocoding "Cairo" will return the location of Cairo Egypt.
28
   *                                If you pass a polygon of illinois, it will return Cairo IL.
29
   * @param return_multiple - Return all results in a multipoint or multipolygon
30
   * @return Geometry|GeometryCollection
31
   */
32
  public function read($address, $return_type = 'point', $bounds = FALSE, $return_multiple = FALSE) {
33
    if (is_array($address)) $address = join(',', $address);
34
    
35
    if (gettype($bounds) == 'object') {
36
      $bounds = $bounds->getBBox();
0 ignored issues
show
The method getBBox cannot be called on $bounds (of type boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
37
    }
38
    if (gettype($bounds) == 'array') {
39
      $bounds_string = '&bounds='.$bounds['miny'].','.$bounds['minx'].'|'.$bounds['maxy'].','.$bounds['maxx'];
40
    }
41
    else {
42
      $bounds_string = '';
43
    }
44
    
45
    $url = "http://maps.googleapis.com/maps/api/geocode/json";
46
    $url .= '?address='. urlencode($address);
47
    $url .= $bounds_string;
48
    $url .= '&sensor=false';
49
    $this->result = json_decode(@file_get_contents($url));
0 ignored issues
show
The property result does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
50
    
51
    if ($this->result->status == 'OK') {
52
      if ($return_multiple == FALSE) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
53
        if ($return_type == 'point') {
54
          return $this->getPoint();
55
        }
56
        if ($return_type == 'bounds' || $return_type == 'polygon') {
57
          return $this->getPolygon();
58
        }
59
      }
60
      if ($return_multiple == TRUE) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
61
        if ($return_type == 'point') {
62
          $points = array();
63
          foreach ($this->result->results as $delta => $item) {
64
            $points[] = $this->getPoint($delta);
65
          }
66
          return new MultiPoint($points);
67
        }
68
        if ($return_type == 'bounds' || $return_type == 'polygon') {
69
          $polygons = array();
70
          foreach ($this->result->results as $delta => $item) {
71
            $polygons[] = $this->getPolygon($delta);
72
          }
73
          return new MultiPolygon($polygons);
74
        }
75
      }
76
    }
77
    else {
78
      if ($this->result->status) throw new Exception('Error in Google Geocoder: '.$this->result->status);
79
      else throw new Exception('Unknown error in Google Geocoder');
80
      return FALSE;
0 ignored issues
show
return FALSE; does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
81
    }
82
  }
83
84
  /**
85
   * Serialize geometries into a WKT string.
86
   *
87
   * @param Geometry $geometry
88
   * @param string $return_type Should be either 'string' or 'array'
89
   *
90
   * @return string Does a reverse geocode of the geometry
91
   */
92
  public function write(Geometry $geometry, $return_type = 'string') {
93
    $centroid = $geometry->getCentroid();
94
    $lat = $centroid->getY();
95
    $lon = $centroid->getX();
96
    
97
    $url = "http://maps.googleapis.com/maps/api/geocode/json";
98
    $url .= '?latlng='.$lat.','.$lon;
99
    $url .= '&sensor=false';
100
    $this->result = json_decode(@file_get_contents($url));
101
    
102
    if ($this->result->status == 'OK') {
103
      if ($return_type == 'string') {
104
        return $this->result->results[0]->formatted_address;
105
      }
106
      if ($return_type == 'array') {
107
        return $this->result->results[0]->address_components;
108
      }
109
    }
110
    else {
111
      if ($this->result->status) throw new Exception('Error in Google Reverse Geocoder: '.$this->result->status);
112
      else throw new Exception('Unknown error in Google Reverse Geocoder');
113
      return FALSE;
0 ignored issues
show
return FALSE; does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
114
    }
115
  }
116
  
117
  private function getPoint($delta = 0) {
118
    $lat = $this->result->results[$delta]->geometry->location->lat;
119
    $lon = $this->result->results[$delta]->geometry->location->lng;
120
    return new Point($lon, $lat);
121
  }
122
123
  private function getPolygon($delta = 0) {
124
    $points = array (
125
      $this->getTopLeft($delta),
126
      $this->getTopRight($delta),
127
      $this->getBottomRight($delta),
128
      $this->getBottomLeft($delta),
129
      $this->getTopLeft($delta),
130
    );
131
    $outer_ring = new LineString($points);
132
    return new Polygon(array($outer_ring));
133
  }
134
135
  private function getTopLeft($delta = 0) {
136
    $lat = $this->result->results[$delta]->geometry->bounds->northeast->lat;
137
    $lon = $this->result->results[$delta]->geometry->bounds->southwest->lng;
138
    return new Point($lon, $lat);
139
  }
140
141
  private function getTopRight($delta = 0) {
142
    $lat = $this->result->results[$delta]->geometry->bounds->northeast->lat;
143
    $lon = $this->result->results[$delta]->geometry->bounds->northeast->lng;
144
    return new Point($lon, $lat);
145
  }
146
  
147
  private function getBottomLeft($delta = 0) {
148
    $lat = $this->result->results[$delta]->geometry->bounds->southwest->lat;
149
    $lon = $this->result->results[$delta]->geometry->bounds->southwest->lng;
150
     return new Point($lon, $lat);
151
  }
152
153
  private function getBottomRight($delta = 0) {
154
    $lat = $this->result->results[$delta]->geometry->bounds->southwest->lat;
155
    $lon = $this->result->results[$delta]->geometry->bounds->northeast->lng;
156
    return new Point($lon, $lat);
157
  }
158
}
159