Issues (51)

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/SM_AreaValueDescription.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
use DataValues\Geo\Values\LatLongValue;
4
use SMW\DataValueFactory;
5
6
/**
7
 * Description of a geographical area defined by a coordinates set and a distance to the bounds.
8
 * The bounds are a 'rectangle' (but bend due to the earths curvature), as the resulting query
9
 * would otherwise be to resource intensive.
10
 *
11
 * @since 0.6
12
 *
13
 * @licence GNU GPL v2+
14
 * @author Jeroen De Dauw < [email protected]
15
 * 
16
 * TODO: would be awesome to use Spatial Extensions to select coordinates
17
 */
18
class SMAreaValueDescription extends SMWValueDescription {
19
	
20
	/**
21
	 * Associative array containing the bounds of the area, or false when not set.
22
	 * 
23
	 * @since 0.6
24
	 * 
25
	 * @var mixed
26
	 */
27
	protected $bounds = false;
28
29
	/**
30
	 * @since 3.0
31
	 *
32
	 * @var SMWDIGeoCoord
33
	 */
34
	protected $center;
35
36
	/**
37
	 * @since 3.0
38
	 *
39
	 * @var string
40
	 */
41
	protected $radius;
42
43
	/**
44
	 * @param SMWDataItem $areaCenter
45
	 * @param string $comparator
46
	 * @param string $radius
47
	 * @param SMWDIProperty $property
48
	 *
49
	 * @throws InvalidArgumentException
50
	 */
51
	public function __construct( SMWDataItem $areaCenter, $comparator, $radius, SMWDIProperty $property = null ) {
52
		if ( !( $areaCenter instanceof SMWDIGeoCoord ) ) {
53
			throw new InvalidArgumentException( '$areaCenter needs to be a SMWDIGeoCoord' );
54
		}
55
56
		parent::__construct( $areaCenter, $property, $comparator );
57
58
		$this->radius = MapsDistanceParser::parseDistance( $radius );
0 ignored issues
show
Documentation Bug introduced by
It seems like \MapsDistanceParser::parseDistance($radius) of type false or double is incompatible with the declared type string of property $radius.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
59
		$this->center = $areaCenter;
60
61
		$this->bounds = $this->getBoundingBox();
62
	}
63
64
	private function getPropertyCompat() {
65
		return method_exists( $this, 'getProperty' ) ? $this->getProperty() : $this->m_property;
66
	}
67
68
	/**
69
	 * @see SMWDescription:getQueryString
70
	 * 
71
	 * @since 0.6
72
	 * 
73
	 * @param boolean $asValue
74
	 * @return string
75
	 */
76
	public function getQueryString( $asValue = false ) {
77
		if ( $this->getDataItem() !== null ) {
78
			$queryString = DataValueFactory::newDataItemValue( $this->getDataItem(), $this->getPropertyCompat() )->getWikiValue();
0 ignored issues
show
Deprecated Code introduced by
The method SMW\DataValueFactory::newDataItemValue() has been deprecated with message: since 2.4, use DataValueFactory::newDataValueByItem

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
79
			return $asValue ? $queryString : "[[$queryString]]";
80
		} else {
81
			return $asValue ? '+' : '';
82
		}
83
	}
84
85
	/**
86
	 * @see SMWDescription:prune
87
	 * 
88
	 * @since 0.6
89
	 */
90
    public function prune( &$maxsize, &$maxdepth, &$log ) {
91
    	if ( ( $maxsize < $this->getSize() ) || ( $maxdepth < $this->getDepth() ) ) {
92
			$log[] = $this->getQueryString();
93
			
94
			$result = new SMWThingDescription();
95
			$result->setPrintRequests( $this->getPrintRequests() );
96
			
97
			return $result;
98
		} else {
99
			$maxsize = $maxsize - $this->getSize();
100
			$maxdepth = $maxdepth - $this->getDepth();
101
			return $this;
102
		}
103
    }
104
    
105
    /**
106
     * Returns the bounds of the area.
107
     * 
108
     * @since 0.6
109
     * 
110
     * @return array
111
     */
112
    public function getBounds() {
113
    	return $this->bounds;
114
    }    
115
	
116
	/**
117
	 * @see SMWDescription::getSQLCondition
118
	 *
119
	 * FIXME: store specific code should be in the store component
120
	 *
121
	 * @since 0.6
122
	 * 
123
	 * @param string $tableName
124
	 * @param array $fieldNames
125
	 * @param DatabaseBase $dbs
126
	 * 
127
	 * @return string or false
128
	 */
129
	public function getSQLCondition( $tableName, array $fieldNames, DatabaseBase $dbs ) {
130
		// Only execute the query when the description's type is geographical coordinates,
131
		// the description is valid, and the near comparator is used.
132
		if ( $this->getDataItem()->getDIType() != SMWDataItem::TYPE_GEO
133
			|| ( $this->getComparator() != SMW_CMP_EQ && $this->getComparator() != SMW_CMP_NEQ )
134
			) {
135
			return false;
136
		}
137
		
138
		$north = $dbs->addQuotes( $this->bounds['north'] );
139
		$east = $dbs->addQuotes( $this->bounds['east'] );
140
		$south = $dbs->addQuotes( $this->bounds['south'] );
141
		$west = $dbs->addQuotes( $this->bounds['west'] );
142
143
		$isEq = $this->getComparator() == SMW_CMP_EQ;
144
		
145
        $conditions = [];
146
147
        $smallerThen = $isEq ? '<' : '>=';
148
        $biggerThen = $isEq ? '>' : '<=';
149
        $joinCond = $isEq ? 'AND' : 'OR';
150
151
        $conditions[] = "{$tableName}.$fieldNames[1] $smallerThen $north";
152
        $conditions[] = "{$tableName}.$fieldNames[1] $biggerThen $south";
153
        $conditions[] = "{$tableName}.$fieldNames[2] $smallerThen $east";
154
        $conditions[] = "{$tableName}.$fieldNames[2] $biggerThen $west";
155
156
        $sql = implode( " $joinCond ", $conditions );
157
158
		return $sql;
159
	}
160
161
	/**
162
	 * @return float[] An associative array containing the limits with keys north, east, south and west.
163
	 */
164
	protected function getBoundingBox() {
165
		$center = new LatLongValue(
166
			$this->center->getLatitude(),
167
			$this->center->getLongitude()
168
		);
169
170
		$north = MapsGeoFunctions::findDestination( $center, 0, $this->radius );
171
		$east = MapsGeoFunctions::findDestination( $center, 90, $this->radius );
172
		$south = MapsGeoFunctions::findDestination( $center, 180, $this->radius );
173
		$west = MapsGeoFunctions::findDestination( $center, 270, $this->radius );
174
175
		return [
176
			'north' => $north['lat'],
177
			'east' => $east['lon'],
178
			'south' => $south['lat'],
179
			'west' => $west['lon'],
180
		];
181
	}
182
	
183
	/**
184
	 * Returns a boolean indicating if MapsGeoFunctions is available. 
185
	 * 
186
	 * @since 0.6
187
	 * 
188
	 * @return boolean
189
	 */
190
	protected function geoFunctionsAreAvailable() {
191
		return class_exists( 'MapsGeoFunctions' );
192
	}	
193
	
194
}