Issues (71)

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.

Lib/ShellSeedProcessor.php (1 issue)

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
App::uses('ColumnTypeGuesser', 'FakeSeeder.Lib');
4
5
/**
6
 * Shell Seed Processor
7
 */
8
class ShellSeedProcessor {
9
10
	/**
11
	 * Aseeder shell task instance
12
	 *
13
	 * @var null|SeederTaskBase
14
	 */
15
	protected $_seeder = null;
16
17
	/**
18
	 * ModelTruncator constructor
19
	 *
20
	 * @param Shell $seeder A seeder shell task
21
	 */
22
	public function __construct($seeder) {
23
		$this->_seeder = $seeder;
0 ignored issues
show
Documentation Bug introduced by
It seems like $seeder of type object<Shell> is incompatible with the declared type null|object<SeederTaskBase> of property $_seeder.

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...
24
	}
25
26
	/**
27
	 * Process the fixtures
28
	 *
29
	 * @return void
30
	 */
31
	public function processFixtures() {
32
		$fixtures = $this->_seeder->fixtureRecords();
33
		if (empty($fixtures)) {
34
			return;
35
		}
36
		$this->saveSeeds($fixtures);
37
	}
38
39
	/**
40
	 * Sow the seeds
41
	 *
42
	 * @return void
43
	 */
44
	public function sowSeeds() {
45
		$modelName = $this->_seeder->getModelName();
46
		$recordsTotal = $this->_seeder->getRecordsCount();
47
		$this->_seeder->out(__('Sowing %s seeds for model %s', $recordsTotal, $modelName));
48
49
		$fieldFormatters = $this->getFieldFormatters();
50
		if (empty($fieldFormatters)) {
51
			$this->_seeder->out(__('No field formatters configured, aborting.'));
52
			return;
53
		}
54
55
		// Improve seed access
56
		$this->_seeder->seeds = array();
57
		for ($record = 1; $record <= $recordsTotal; $record++) {
58
			$newSeed = $this->createSeed($fieldFormatters);
59
			if (empty($newSeed)) {
60
				$this->_seeder->out(__('Created seed is empty! Check the field formatters.'));
61
				break;
62
			}
63
			$this->_seeder->seeds[] = $newSeed;
64
65
			$this->_seeder->out('.', 0);
66
			$modulo = $record % 50;
67
			if ($modulo == 0 || $record == $recordsTotal) {
68
				$alignSpaces = 0;
69
				if ($modulo !== 0 && $record >= 50) {
70
					$alignSpaces = 50 - $modulo;
71
				}
72
				$alignSpaces = $alignSpaces + strlen($recordsTotal) - strlen($record) + 1;
73
				$alignSpaces = str_repeat(' ', $alignSpaces);
74
				$this->_seeder->out(sprintf('%s%s / %s', $alignSpaces, $record, $recordsTotal));
75
			}
76
		}
77
		$this->saveSeeds($this->_seeder->seeds);
78
79
		$this->_seeder->out(__('Finished sowing %s seeds for model %s', $recordsTotal, $modelName));
80
	}
81
82
	/**
83
	 * Get the field formatters depending on the seeding mode
84
	 *
85
	 * 'manual' = No Field formatters are guessed.
86
	 * 'auto' = All field formatters are guessed.
87
	 * 'mixed' = Only missing field formatters are guessed.
88
	 *
89
	 * @return array The field formatters
90
	 */
91
	public function getFieldFormatters() {
92
		$mode = $this->_seeder->getSeedingMode();
93
		switch ($mode) {
94
			case 'manual':
95
				return $this->_seeder->fieldFormatters();
96
			case 'auto':
97
				return $this->_guessFieldFormatters();
98
			case 'mixed':
99
				// TODO Improve by only guessing those needed
100
				$guesedFormatters = $this->_guessFieldFormatters();
101
				$setFormatters = $this->_seeder->fieldFormatters();
102
				return array_merge(
103
					$guesedFormatters,
104
					$setFormatters
105
				);
106
		}
107
		// TODO Handle invalid mode
108
		return array();
109
	}
110
111
	/**
112
	 * Guess the field formatters based on the column type
113
	 *
114
	 * @return array The guessed field formatters.
115
	 */
116
	protected function _guessFieldFormatters() {
117
		$columns = $this->_getColumns();
118
119
		$columnTypeGuesser = $this->_getColumnTypeGuesser();
120
		$fieldFormatters = array();
121
		foreach ($columns as $columnName => $column) {
122
			$fieldFormatters[$columnName] = $columnTypeGuesser->guessFormat($column);
123
		}
124
		return $fieldFormatters;
125
	}
126
127
	/**
128
	 * Get a ColumnTypeGuesser instance
129
	 *
130
	 * @return ColumnTypeGuesser A ColumnTypeGuesser instance.
131
	 */
132
	protected function _getColumnTypeGuesser() {
133
		return new ColumnTypeGuesser($this->_seeder->faker);
134
	}
135
136
	/**
137
	 * Get the columns (schema)
138
	 *
139
	 * Removes the primary key, though.
140
	 *
141
	 * @return array The columns (schema).
142
	 */
143
	protected function _getColumns() {
144
		$model = $this->_getModel();
145
		$columns = $model->schema();
146
		unset($columns[$model->primaryKey]);
147
		return $columns;
148
	}
149
150
	/**
151
	 * Create seed to sow
152
	 *
153
	 * Gets some (optional) record state data,
154
	 * which can be shared by all field formatters of one record.
155
	 *
156
	 * @param array $fieldFormatters The fields and their formatter
157
	 * @return array A seed to sow.
158
	 */
159
	public function createSeed($fieldFormatters) {
160
		$seed = array();
161
		$modelName = $this->_seeder->getModelName();
162
		$state = $this->_seeder->recordState();
163
164
		foreach ($fieldFormatters as $fieldName => $formatter) {
165
			$seed[$modelName][$fieldName] = $formatter($state);
166
		}
167
		return $seed;
168
	}
169
170
	/**
171
	 * Save the seeds
172
	 *
173
	 * @param array $seeds The seeds to save.
174
	 * @return void
175
	 * @todo Make data saving/validation handling configurable (atomic true/false)
176
	 */
177
	public function saveSeeds($seeds) {
178
		$model = $this->_getModel();
179
		$validate = $this->_seeder->getValidateSeeding();
180
181
		if ($validate === 'false') {
182
			$validate = false;
183
		} elseif ($validate !== 'first' && $validate !== 'only') {
184
			$validate = (bool)$validate;
185
		}
186
187
		$saved = $model->saveAll(
188
			$seeds,
189
			array(
190
				'validate' => $validate
191
			)
192
		);
193
		if (!$saved) {
194
			$this->_seeder->out(__('Seeds could not be saved successfully!'));
195
			$this->_seeder->out(__('Data validation errors: %s', var_export($model->validationErrors, true)), 1, Shell::VERBOSE);
196
		}
197
	}
198
199
	/**
200
	 * Get the model instance
201
	 *
202
	 * @return Model The model instance.
203
	 */
204
	protected function _getModel() {
205
		$modelName = $this->_seeder->getModelName();
206
		$model = ClassRegistry::init($modelName);
207
		return $model;
208
	}
209
}