Issues (61)

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/SemanticMW/AreaDescription.php (5 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 Maps\SemanticMW;
6
7
use DataValues\Geo\Values\LatLongValue;
8
use InvalidArgumentException;
9
use Maps\GeoFunctions;
10
use Maps\Presentation\MapsDistanceParser;
11
use SMW\DataValueFactory;
12
use SMW\DIProperty;
13
use SMW\Query\Language\ValueDescription;
14
use SMWDataItem;
15
use SMWDIGeoCoord;
16
use SMWThingDescription;
17
use Wikimedia\Rdbms\IDatabase;
18
19
/**
20
 * Description of a geographical area defined by a coordinates set and a distance to the bounds.
21
 * The bounds are a 'rectangle' (but bend due to the earths curvature), as the resulting query
22
 * would otherwise be to resource intensive.
23
 *
24
 * @licence GNU GPL v2+
25
 * @author Jeroen De Dauw < [email protected] >
26
 */
27
class AreaDescription extends ValueDescription {
28
29
	/**
30
	 * @var SMWDIGeoCoord
31
	 */
32
	private $center;
33
34
	private $radius;
35
36 4
	public function __construct( SMWDataItem $areaCenter, int $comparator, string $radius, DIProperty $property = null ) {
37 4
		if ( !( $areaCenter instanceof SMWDIGeoCoord ) ) {
0 ignored issues
show
The class SMWDIGeoCoord does not exist. Is this class maybe located in a folder that is not analyzed, or in a newer version of your dependencies than listed in your composer.lock/composer.json?
Loading history...
38
			throw new InvalidArgumentException( '$areaCenter needs to be a SMWDIGeoCoord' );
39
		}
40
41 4
		parent::__construct( $areaCenter, $property, $comparator );
42
43 4
		$this->center = $areaCenter;
44 4
		$this->radius = $radius;
45 4
	}
46
47
	/**
48
	 * @see Description::prune
49
	 */
50
	public function prune( &$maxsize, &$maxdepth, &$log ) {
51
		if ( ( $maxsize < $this->getSize() ) || ( $maxdepth < $this->getDepth() ) ) {
52
			$log[] = $this->getQueryString();
53
54
			$result = new SMWThingDescription();
55
			$result->setPrintRequests( $this->getPrintRequests() );
56
57
			return $result;
58
		}
59
60
		$maxsize = $maxsize - $this->getSize();
61
		$maxdepth = $maxdepth - $this->getDepth();
62
63
		return $this;
64
	}
65
66 1
	public function getQueryString( $asValue = false ) {
67 1
		$centerString = DataValueFactory::getInstance()->newDataValueByItem(
68 1
			$this->center,
69 1
			$this->getProperty()
70 1
		)->getWikiValue();
71
72 1
		$queryString = "$centerString ({$this->radius})";
73
74 1
		return $asValue ? $queryString : "[[$queryString]]";
75
	}
76
77
	/**
78
	 * @see SomePropertyInterpreter::mapValueDescription
79
	 *
80
	 * FIXME: store specific code should be in the store component
81
	 *
82
	 * @param string $tableName
83
	 * @param string[] $fieldNames
84
	 * @param IDatabase $db
85
	 *
86
	 * @return string|false
87
	 */
88 2
	public function getSQLCondition( $tableName, array $fieldNames, IDatabase $db ) {
89 2
		if ( $this->center->getDIType() != SMWDataItem::TYPE_GEO ) {
90
			throw new \LogicException( 'Constructor should have prevented this' );
91
		}
92
93 2
		if ( !$this->comparatorIsSupported() ) {
94 1
			return false;
95
		}
96
97 1
		$bounds = $this->getBoundingBox();
98
99 1
		$north = $db->addQuotes( $bounds['north'] );
100 1
		$east = $db->addQuotes( $bounds['east'] );
101 1
		$south = $db->addQuotes( $bounds['south'] );
102 1
		$west = $db->addQuotes( $bounds['west'] );
103
104 1
		$isEq = $this->getComparator() == SMW_CMP_EQ;
105
106 1
		$smallerThen = $isEq ? '<' : '>=';
107 1
		$biggerThen = $isEq ? '>' : '<=';
108 1
		$joinCond = $isEq ? 'AND' : 'OR';
109
110 1
		$conditions = [];
111
112 1
		$conditions[] = "{$tableName}.$fieldNames[1] $smallerThen $north";
113 1
		$conditions[] = "{$tableName}.$fieldNames[1] $biggerThen $south";
114 1
		$conditions[] = "{$tableName}.$fieldNames[2] $smallerThen $east";
115 1
		$conditions[] = "{$tableName}.$fieldNames[2] $biggerThen $west";
116
117 1
		return implode( " $joinCond ", $conditions );
118
	}
119
120 2
	private function comparatorIsSupported(): bool {
121 2
		return $this->getComparator() === SMW_CMP_EQ || $this->getComparator() === SMW_CMP_NEQ;
122
	}
123
124
	/**
125
	 * @return float[] An associative array containing the limits with keys north, east, south and west.
126
	 */
127 2
	public function getBoundingBox(): array {
128 2
		$center = new LatLongValue(
129 2
			$this->center->getLatitude(),
130 2
			$this->center->getLongitude()
131
		);
132
133 2
		$radiusInMeters = MapsDistanceParser::parseDistance( $this->radius ); // TODO: this can return false
134
135 2
		$north = GeoFunctions::findDestination( $center, 0, $radiusInMeters );
0 ignored issues
show
It seems like $radiusInMeters defined by \Maps\Presentation\MapsD...Distance($this->radius) on line 133 can also be of type false; however, Maps\GeoFunctions::findDestination() does only seem to accept double, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

Loading history...
136 2
		$east = GeoFunctions::findDestination( $center, 90, $radiusInMeters );
0 ignored issues
show
It seems like $radiusInMeters defined by \Maps\Presentation\MapsD...Distance($this->radius) on line 133 can also be of type false; however, Maps\GeoFunctions::findDestination() does only seem to accept double, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

Loading history...
137 2
		$south = GeoFunctions::findDestination( $center, 180, $radiusInMeters );
0 ignored issues
show
It seems like $radiusInMeters defined by \Maps\Presentation\MapsD...Distance($this->radius) on line 133 can also be of type false; however, Maps\GeoFunctions::findDestination() does only seem to accept double, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

Loading history...
138 2
		$west = GeoFunctions::findDestination( $center, 270, $radiusInMeters );
0 ignored issues
show
It seems like $radiusInMeters defined by \Maps\Presentation\MapsD...Distance($this->radius) on line 133 can also be of type false; however, Maps\GeoFunctions::findDestination() does only seem to accept double, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

Loading history...
139
140
		return [
141 2
			'north' => $north['lat'],
142 2
			'east' => $east['lon'],
143 2
			'south' => $south['lat'],
144 2
			'west' => $west['lon'],
145
		];
146
	}
147
148
}
149