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/CargoFormat/CargoOutputBuilder.php (1 issue)

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\CargoFormat;
6
7
use CargoFieldDescription;
8
use DataValues\Geo\Values\LatLongValue;
9
use Maps\DataAccess\ImageRepository;
10
use Maps\Map\MapData;
11
use Maps\Map\MapOutput;
12
use Maps\Map\MapOutputBuilder;
13
use Maps\Map\Marker;
14
use Maps\Map\StructuredPopup;
15
use Maps\MappingService;
16
use Maps\MappingServices;
17
use ParamProcessor\ParamDefinitionFactory;
18
use ParamProcessor\Processor;
19
20
class CargoOutputBuilder {
21
22
	private $outputBuilder;
23
	private $services;
24
	private $paramDefinitionFactory;
25
	private $imageRepository;
26
27
	public function __construct( MapOutputBuilder $outputBuilder, MappingServices $services,
28
		ParamDefinitionFactory $paramDefinitionFactory, ImageRepository $imageRepository ) {
29
30
		$this->outputBuilder = $outputBuilder;
31
		$this->services = $services;
32
		$this->paramDefinitionFactory = $paramDefinitionFactory;
33
		$this->imageRepository = $imageRepository;
34
	}
35
36
	public function buildOutputFromCargoData( array $values, array $formattedValues, array $fieldDescriptions, array $displayParams ): MapOutput {
0 ignored issues
show
The parameter $values is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
37
		$service = $this->services->getDefaultService();
38
39
		$mapData = $service->newMapDataFromProcessingResult( $this->processParameters( $service, $displayParams ) );
40
		$mapData->setMarkers( $this->createMarkers( $formattedValues, $fieldDescriptions, $mapData ) );
41
42
		return $this->outputBuilder->buildOutput(
43
			$service,
44
			$mapData
45
		);
46
	}
47
48
	private function createMarkers( array $formattedValues, array $fieldDescriptions, MapData $mapData ): array {
49
		$markers = $this->cargoValuesToMarkers(
50
			$formattedValues,
51
			$fieldDescriptions
52
		);
53
54
		$this->setIconUrl( $markers, $mapData->getParameters()['icon'] );
55
56
		return $markers;
57
	}
58
59
	private function setIconUrl( array $markers, string $iconParameter ): void {
60
		if ( $iconParameter !== '' ) {
61
			$iconUrl = $this->imageRepository->getByName( $iconParameter )->getUrl();
62
63
			foreach ( $markers as $marker ) {
64
				$marker->setIconUrl( $iconUrl );
65
			}
66
		}
67
	}
68
69
	private function processParameters( MappingService $service, array $displayParams ) {
70
		$processor = Processor::newDefault();
71
72
		$processor->setParameters( $displayParams );
73
		$processor->setParameterDefinitions( $this->getParameterDefinitions( $service ) );
74
75
		return $processor->processParameters();
76
	}
77
78
	private function getParameterDefinitions( MappingService $service ): array {
79
		return $this->paramDefinitionFactory->newDefinitionsFromArrays( $service->getParameterInfo() ) ;
80
	}
81
82
	/**
83
	 * @return Marker[]
84
	 */
85
	private function cargoValuesToMarkers( array $formattedValues, array $fieldDescriptions ): array {
86
		$coordinateFields = $this->getCoordinateFieldNames( $fieldDescriptions );
87
		$markers = [];
88
89
		foreach ( $formattedValues as $valuesRow ) {
90
			foreach ( $coordinateFields as $coordinateField ) {
91
				$markers[] = $this->newMarker( $valuesRow, $coordinateField, $coordinateFields );
92
			}
93
		}
94
95
		return $markers;
96
	}
97
98
	/**
99
	 * @param CargoFieldDescription[] $fieldDescriptions
100
	 * @return string[]
101
	 */
102
	private function getCoordinateFieldNames( array $fieldDescriptions ): array {
103
		$names = [];
104
105
		foreach ( $fieldDescriptions as $fieldName => $field ) {
106
			if ( $field->mType === 'Coordinates' ) {
107
				$names[] = str_replace( ' ', '_', $fieldName );
108
			}
109
		}
110
111
		return $names;
112
	}
113
114
	private function newMarker( array $valuesRow, string $coordinateField, array $coordinateFields ): Marker {
115
		$marker = new Marker( new LatLongValue(
116
			(float)$valuesRow[$coordinateField . '  lat'],
117
			(float)$valuesRow[$coordinateField . '  lon']
118
		) );
119
120
		$marker->setText(
121
			( new StructuredPopup(
122
				array_shift( $valuesRow ) ?? '',
123
				$this->getPropertyValuesToDisplay( $valuesRow, $coordinateFields )
124
			) )->getHtml()
125
		);
126
127
		return $marker;
128
	}
129
130
	private function getPropertyValuesToDisplay( array $valuesRow, array $coordinateFields ): array {
131
		$propertyValues = [];
132
133
		foreach ( $valuesRow as $name => $value ) {
134
			if ( $this->shouldDisplayValue( $name, $coordinateFields ) ) {
135
				$propertyValues[$name] = $value;
136
			}
137
		}
138
139
		return $propertyValues;
140
	}
141
142
	private function shouldDisplayValue( string $name, array $coordinateFields ): bool {
143
		$hiddenFields = [];
144
145
		foreach ( $coordinateFields as $field ) {
146
			$hiddenFields[] = $field;
147
			$hiddenFields[] = $field . '  lat';
148
			$hiddenFields[] = $field . '  lon';
149
		}
150
151
		return !in_array( $name, $hiddenFields );
152
	}
153
154
}
155