Issues (248)

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.

tests/models/FlickrPhotoElasticaSearchHelper.php (3 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
use Elastica\Aggregation\Terms;
3
use Elastica\Query;
4
use Elastica\Aggregation\TopHits;
5
use Elastica\Aggregation\Range;
6
use SilverStripe\Elastica\RangedAggregation;
7
8
9
class FlickrPhotoTOElasticaSearchHelper implements ElasticaSearchHelperInterface,TestOnly {
0 ignored issues
show
Expected 1 space before "TestOnly"; 0 found
Loading history...
10
11 10
	public function __construct() {
12 10
		$aspectAgg = new RangedAggregation('Aspect', 'AspectRatio');
13 10
        $aspectAgg->addRange(0.0000001, 0.3, 'Panoramic');
14 10
        $aspectAgg->addRange(0.3, 0.9, 'Horizontal');
15 10
        $aspectAgg->addRange(0.9, 1.2, 'Square');
16 10
        $aspectAgg->addRange(1.2, 1.79, 'Vertical');
17 10
        $aspectAgg->addRange(1.79, 1e7, 'Tallest');
18 10
	}
19
20
	private static $titleFieldMapping = array(
21
		'ShutterSpeed' => 'Shutter Speed',
22
		'FocalLength35mm' => 'Focal Length'
23
	);
24
25
26
	/**
27
	 * Add a number of facets to the FlickrPhotoTO query
28
	 * @param  \Elastica\Query &$query the existing query object to be augmented.
29
	 */
30 9
	public function augmentQuery(&$query) {
31
		//FIXME probably move this back as default behaviour
32
		// set the order to be taken at in reverse if query is blank other than aggs
33 9
		$params = $query->getParams();
0 ignored issues
show
$params is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
34
35
		$wildcard = array(
0 ignored issues
show
$wildcard is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
36 9
			'query_string' => array('query' => '*')
37 9
		);
38
39 9
		if ($query->OriginalQueryText == '') {
40 3
			$query->setSort(array('TakenAt'=> 'desc'));
41 3
		}
42
43
		// add Aperture aggregate
44 9
		$agg1 = new Terms("Aperture");
45 9
		$agg1->setField("Aperture");
46 9
		$agg1->setSize(0);
47 9
		$agg1->setOrder('_term', 'asc');
48 9
		$query->addAggregation($agg1);
49
50
		// add shutter speed aggregate
51 9
		$agg2 = new Terms("ShutterSpeed");
52 9
		$agg2->setField("ShutterSpeed");
53 9
		$agg2->setSize(0);
54 9
		$agg2->setOrder('_term', 'asc');
55 9
		$query->addAggregation($agg2);
56
57
		// this currently needs to be same as the field name
58
		// needs fixed
59
		// Add focal length aggregate, may range this
60 9
		$agg3 = new Terms("FocalLength35mm");
61 9
		$agg3->setField("FocalLength35mm");
62 9
		$agg3->setSize(0);
63 9
		$agg3->setOrder('_term', 'asc');
64 9
		$query->addAggregation($agg3);
65
66
		// add film speed
67 9
		$agg4 = new Terms("ISO");
68 9
		$agg4->setField("ISO");
69 9
		$agg4->setSize(0);
70 9
		$agg4->setOrder('_term', 'asc');
71 9
		$query->addAggregation($agg4);
72
73 9
		$aspectRangedAgg = RangedAggregation::getByTitle('Aspect');
74 9
        $query->addAggregation($aspectRangedAgg->getRangeAgg());
75
76
		// remove NearestTo from the request so it does not get used as a term filter
77 9
		unset(Controller::curr()->request['NearestTo']);
78 9
	}
79
80
81
	/**
82
	 * Update filters, perhaps remaps them, prior to performing a search.
83
	 * This allows for aggregation values to be updated prior to rendering.
84
	 * @param  array &$filters array of key/value pairs for query filtering
85
	 */
86 9
	public function updateFilters(&$filters) {
87
88
		// shutter speed is stored as decimal to 6 decimal places, then a
89
		// vertical bar followed by the displayed speed as a fraction or a
90
		// whole number.  This puts the decimal back for matching purposes
91 9
		if (isset($filters['ShutterSpeed'])) {
92
93 1
			$sortable = $filters['ShutterSpeed'];
94
95 1
			$sortable = explode('/', $sortable);
96 1
			if (sizeof($sortable) == 1) {
97 1
				$sortable = trim($sortable[0]);
98
99 1
				if ($sortable === '1') {
100 1
					$sortable = '1.000000|1';
101 1
				}
102
103 1
			} else if (sizeof($sortable) == 2) {
104 1
				if ($sortable[0] === '' || $sortable[1] === '') {
105 1
					$sortable = '';
106
107 1
				} else {
108 1
					$sortable = floatval($sortable[0])/intval($sortable[1]);
109 1
					$sortable = round($sortable,6);
110 1
					$sortable = $sortable . '|' . $filters['ShutterSpeed'];
111
				}
112
113 1
			}
114
115 1
			$filters['ShutterSpeed'] = $sortable;
116 1
		}
117 9
	}
118
119
120
121
	/**
122
	 * Manipulate the results, e.g. fixing up values if issues with ordering in Elastica
123
	 * @param  array &$aggs Aggregates from an Elastica search to be tweaked
124
	 */
125 9
	public function updateAggregation(&$aggs) {
126
		// the shutter speeds are of the form decimal number | fraction, keep the latter half
127 9
		$shutterSpeeds = $aggs['ShutterSpeed']['buckets'];
128 9
		$ctr = 0;
129 9
		foreach ($shutterSpeeds as $bucket) {
130 9
			$key = $bucket['key'];
131 9
			$splits = explode('|', $key);
132 9
			$shutterSpeeds[$ctr]['key'] = end($splits);
133 9
			$ctr++;
134 9
		}
135 9
		$aggs['ShutterSpeed']['buckets'] = $shutterSpeeds;
136 9
	}
137
138
	/*
139
	In the event of aggregates being used and no query provided, sort by this (<field> => <order>)
140
	 */
141 3
	public function getDefaultSort() {
142 3
		return array('TakenAt' => 'desc');
143
	}
144
145
146 9
	public function getIndexFieldTitleMapping() {
147 9
		return self::$titleFieldMapping;
148
	}
149
}
150