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/Map/DisplayMap/DisplayMapRenderer.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
namespace Maps\Map\DisplayMap;
6
7
use Maps\DataAccess\MediaWikiFileUrlFinder;
8
use Maps\LegacyModel\Location;
9
use Maps\Map\MapData;
10
use Maps\Map\MapOutput;
11
use Maps\Map\MapOutputBuilder;
12
use Maps\MappingService;
13
use Maps\Presentation\ElementJsonSerializer;
14
use Maps\Presentation\WikitextParser;
15
use Maps\WikitextParsers\LocationParser;
16
use Parser;
17
18
/**
19
 * Class handling the #display_map rendering.
20
 *
21
 * @licence GNU GPL v2+
22
 * @author Jeroen De Dauw < [email protected] >
23
 * @author Kim Eik
24
 */
25
class DisplayMapRenderer {
26
27
	public $service;
28
29
	/**
30
	 * @var LocationParser
31
	 */
32
	private $locationParser;
33
34
	/**
35
	 * @var MediaWikiFileUrlFinder
36
	 */
37
	private $fileUrlFinder;
38
39
	/**
40
	 * @var WikitextParser
41
	 */
42
	private $wikitextParser;
43
	/**
44
	 * @var ElementJsonSerializer
45
	 */
46
	private $elementSerializer;
47
48 27
	public function __construct( MappingService $service = null ) {
49 27
		$this->service = $service;
50 27
	}
51
52
	/**
53
	 * Handles the request from the parser hook by doing the work that's common for all
54
	 * mapping services, calling the specific methods and finally returning the resulting output.
55
	 *
56
	 * @param MapData $mapData
57
	 * @param Parser $parser
58
	 *
59
	 * @return MapOutput
60
	 */
61 27
	public final function renderMap( MapData $mapData, Parser $parser ): MapOutput {
62 27
		$factory = \Maps\MapsFactory::globalInstance();
63
64 27
		$this->locationParser = $factory->newLocationParser();
65 27
		$this->fileUrlFinder = $factory->getFileUrlFinder();
66
67 27
		$this->wikitextParser = new WikitextParser( clone $parser );
68 27
		$this->elementSerializer = new ElementJsonSerializer( $this->wikitextParser );
69
70 27
		$mapData->setParameters( $this->handleMarkerData( $mapData->getParameters() ) );
71
72
		// TODO: inject
73 27
		$outputBuilder = new MapOutputBuilder();
74
75 27
		return $outputBuilder->buildOutput( $this->service, $mapData );
0 ignored issues
show
It seems like $this->service can be null; however, buildOutput() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
76
	}
77
78
	/**
79
	 * Converts the data in the coordinates parameter to JSON-ready objects.
80
	 * These get stored in the locations parameter, and the coordinates on gets deleted.
81
	 */
82 27
	private function handleMarkerData( array $params ) {
83 27
		$params['centre'] = $this->getCenter( $params['centre'] );
84
85
		// FIXME: this parameter is google maps service specific
86 27
		if ( array_key_exists( 'wmsoverlay', $params ) && is_object( $params['wmsoverlay'] ) ) {
87
			$params['wmsoverlay'] = $params['wmsoverlay']->getJSONObject();
88
		}
89
90 27
		$params['locations'] = $this->getLocationJson( $params );
91
92 27
		unset( $params['coordinates'] );
93
94 27
		$this->handleShapeData( $params );
95
96 27
		return $params;
97
	}
98
99 27
	private function getCenter( $coordinatesOrAddress ) {
100 27
		if ( $coordinatesOrAddress === false ) {
101 27
			return false;
102
		}
103
104
		try {
105
			// FIXME: a Location makes no sense here, since the non-coordinate data is not used
106
			$location = $this->locationParser->parse( $coordinatesOrAddress );
107
		}
108
		catch ( \Exception $ex ) {
109
			// TODO: somehow report this to the user
110
			return false;
111
		}
112
113
		return $location->getJSONObject();
114
	}
115
116 27
	private function getLocationJson( array $params ) {
117 27
		$iconUrl = $this->fileUrlFinder->getUrlForFileName( $params['icon'] );
118 27
		$visitedIconUrl = $this->fileUrlFinder->getUrlForFileName( $params['visitedicon'] ?? '' );
119
120 27
		$locationJsonObjects = [];
121
122 27
		foreach ( $params['coordinates'] as $coordinatesOrAddress ) {
123
			try {
124 16
				$location = $this->locationParser->parse( $coordinatesOrAddress );
125
			}
126 1
			catch ( \Exception $ex ) {
127
				// TODO: somehow report this to the user
128 1
				continue;
129
			}
130
131 15
			$locationJsonObjects[] = $this->getLocationJsonObject(
132 15
				$location,
133
				$params,
134
				$iconUrl,
135
				$visitedIconUrl
136
			);
137
		}
138
139 27
		return $locationJsonObjects;
140
	}
141
142 15
	private function getLocationJsonObject( Location $location, array $params, $iconUrl, $visitedIconUrl ) {
143 15
		$jsonObj = $location->getJSONObject( $params['title'], $params['label'], $iconUrl, '', '', $visitedIconUrl );
144
145 15
		$this->elementSerializer->titleAndText( $jsonObj );
146
147 15
		if ( isset( $jsonObj['inlineLabel'] ) ) {
148 1
			$jsonObj['inlineLabel'] = strip_tags(
149 1
				$this->wikitextParser->wikitextToHtml( $jsonObj['inlineLabel'] ),
150 1
				'<a><img>'
151
			);
152
		}
153
154 15
		return $jsonObj;
155
	}
156
157 27
	private function handleShapeData( array &$params ) {
158
		$textContainers = [
159 27
			&$params['lines'],
160 27
			&$params['polygons'],
161 27
			&$params['circles'],
162 27
			&$params['rectangles'],
163 27
			&$params['imageoverlays'], // FIXME: this is Google Maps specific!!
164
		];
165
166 27
		foreach ( $textContainers as &$textContainer ) {
167 27
			if ( is_array( $textContainer ) ) {
168 27
				foreach ( $textContainer as &$obj ) {
169 5
					$obj = $this->elementSerializer->elementToJson( $obj );
170
				}
171
			}
172
		}
173 27
	}
174
175
}
176