|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Routes. |
|
4
|
|
|
* |
|
5
|
|
|
* @copyright Zikula contributors (Zikula) |
|
6
|
|
|
* @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License |
|
7
|
|
|
* @author Zikula contributors <[email protected]>. |
|
8
|
|
|
* @link http://www.zikula.org |
|
9
|
|
|
* @link http://zikula.org |
|
10
|
|
|
* @version Generated by ModuleStudio 0.7.0 (http://modulestudio.de). |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
namespace Zikula\RoutesModule\Form\Handler\Route\Base; |
|
14
|
|
|
|
|
15
|
|
|
use Zikula\RoutesModule\Form\Handler\Common\EditHandler; |
|
16
|
|
|
|
|
17
|
|
|
use Symfony\Component\HttpFoundation\RedirectResponse; |
|
18
|
|
|
use Symfony\Component\Security\Core\Exception\AccessDeniedException; |
|
19
|
|
|
use ModUtil; |
|
20
|
|
|
use RuntimeException; |
|
21
|
|
|
use System; |
|
22
|
|
|
use UserUtil; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* This handler class handles the page events of editing forms. |
|
26
|
|
|
* It aims on the route object type. |
|
27
|
|
|
*/ |
|
28
|
|
|
abstract class AbstractEditHandler extends EditHandler |
|
29
|
|
|
{ |
|
30
|
|
|
/** |
|
31
|
|
|
* Initialise form handler. |
|
32
|
|
|
* |
|
33
|
|
|
* This method takes care of all necessary initialisation of our data and form states. |
|
34
|
|
|
* |
|
35
|
|
|
* @param array $templateParameters List of preassigned template variables |
|
36
|
|
|
* |
|
37
|
|
|
* @return boolean False in case of initialisation errors, otherwise true |
|
38
|
|
|
*/ |
|
39
|
|
|
public function processForm(array $templateParameters) |
|
40
|
|
|
{ |
|
41
|
|
|
$this->objectType = 'route'; |
|
42
|
|
|
$this->objectTypeCapital = 'Route'; |
|
43
|
|
|
$this->objectTypeLower = 'route'; |
|
44
|
|
|
|
|
45
|
|
|
$this->hasPageLockSupport = true; |
|
46
|
|
|
|
|
47
|
|
|
$result = parent::processForm($templateParameters); |
|
48
|
|
|
|
|
49
|
|
|
if ($this->templateParameters['mode'] == 'create') { |
|
50
|
|
|
$modelHelper = $this->container->get('zikula_routes_module.model_helper'); |
|
51
|
|
|
if (!$modelHelper->canBeCreated($this->objectType)) { |
|
52
|
|
|
$this->request->getSession()->getFlashBag()->add('error', $this->__('Sorry, but you can not create the route yet as other items are required which must be created before!')); |
|
53
|
|
|
$logger = $this->container->get('logger'); |
|
54
|
|
|
$logArgs = ['app' => 'ZikulaRoutesModule', 'user' => $this->container->get('zikula_users_module.current_user')->get('uname'), 'entity' => $this->objectType]; |
|
55
|
|
|
$logger->notice('{app}: User {user} tried to create a new {entity}, but failed as it other items are required which must be created before.', $logArgs); |
|
56
|
|
|
|
|
57
|
|
|
return new RedirectResponse($this->getRedirectUrl(['commandName' => '']), 302); |
|
|
|
|
|
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
$entity = $this->entityRef; |
|
62
|
|
|
|
|
63
|
|
|
// save entity reference for later reuse |
|
64
|
|
|
$this->entityRef = $entity; |
|
65
|
|
|
|
|
66
|
|
|
$entityData = $entity->toArray(); |
|
67
|
|
|
|
|
68
|
|
|
// assign data to template as array (makes translatable support easier) |
|
69
|
|
|
$this->templateParameters[$this->objectTypeLower] = $entityData; |
|
70
|
|
|
|
|
71
|
|
|
return $result; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Creates the form type. |
|
76
|
|
|
*/ |
|
77
|
|
|
protected function createForm() |
|
78
|
|
|
{ |
|
79
|
|
|
$options = [ |
|
80
|
|
|
'mode' => $this->templateParameters['mode'], |
|
81
|
|
|
'actions' => $this->templateParameters['actions'], |
|
82
|
|
|
]; |
|
83
|
|
|
|
|
84
|
|
|
return $this->container->get('form.factory')->create('Zikula\RoutesModule\Form\Type\RouteType', $this->entityRef, $options); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* Get list of allowed redirect codes. |
|
90
|
|
|
* |
|
91
|
|
|
* @return array list of possible redirect codes |
|
92
|
|
|
*/ |
|
93
|
|
|
protected function getRedirectCodes() |
|
94
|
|
|
{ |
|
95
|
|
|
$codes = parent::getRedirectCodes(); |
|
96
|
|
|
|
|
97
|
|
|
|
|
98
|
|
|
return $codes; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* Get the default redirect url. Required if no returnTo parameter has been supplied. |
|
103
|
|
|
* This method is called in handleCommand so we know which command has been performed. |
|
104
|
|
|
* |
|
105
|
|
|
* @param array $args List of arguments |
|
106
|
|
|
* |
|
107
|
|
|
* @return string The default redirect url |
|
108
|
|
|
*/ |
|
109
|
|
|
protected function getDefaultReturnUrl($args) |
|
110
|
|
|
{ |
|
111
|
|
|
$objectIsPersisted = $args['commandName'] != 'delete' && !($this->templateParameters['mode'] == 'create' && $args['commandName'] == 'cancel'); |
|
112
|
|
|
|
|
113
|
|
|
if (null !== $this->returnTo) { |
|
114
|
|
|
|
|
115
|
|
|
$isDisplayOrEditPage = substr($this->returnTo, -7) == 'display' || substr($this->returnTo, -4) == 'edit'; |
|
116
|
|
|
if (!$isDisplayOrEditPage || $objectIsPersisted) { |
|
117
|
|
|
// return to referer |
|
118
|
|
|
return $this->returnTo; |
|
119
|
|
|
} |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
$routeArea = array_key_exists('routeArea', $this->templateParameters) ? $this->templateParameters['routeArea'] : ''; |
|
123
|
|
|
|
|
124
|
|
|
// redirect to the list of routes |
|
125
|
|
|
$viewArgs = []; |
|
126
|
|
|
$url = $this->router->generate('zikularoutesmodule_' . $this->objectTypeLower . '_' . $routeArea . 'view', $viewArgs); |
|
127
|
|
|
|
|
128
|
|
|
return $url; |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
/** |
|
132
|
|
|
* Command event handler. |
|
133
|
|
|
* |
|
134
|
|
|
* This event handler is called when a command is issued by the user. |
|
135
|
|
|
* |
|
136
|
|
|
* @param array $args List of arguments |
|
137
|
|
|
* |
|
138
|
|
|
* @return mixed Redirect or false on errors |
|
139
|
|
|
*/ |
|
140
|
|
|
public function handleCommand($args = []) |
|
141
|
|
|
{ |
|
142
|
|
|
$result = parent::handleCommand($args); |
|
143
|
|
|
if (false === $result) { |
|
144
|
|
|
return $result; |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
// build $args for BC (e.g. used by redirect handling) |
|
148
|
|
View Code Duplication |
foreach ($this->templateParameters['actions'] as $action) { |
|
|
|
|
|
|
149
|
|
|
if ($this->form->get($action['id'])->isClicked()) { |
|
|
|
|
|
|
150
|
|
|
$args['commandName'] = $action['id']; |
|
151
|
|
|
} |
|
152
|
|
|
} |
|
153
|
|
|
if ($this->form->get('cancel')->isClicked()) { |
|
|
|
|
|
|
154
|
|
|
$args['commandName'] = 'cancel'; |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
return new RedirectResponse($this->getRedirectUrl($args), 302); |
|
|
|
|
|
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
/** |
|
161
|
|
|
* Get success or error message for default operations. |
|
162
|
|
|
* |
|
163
|
|
|
* @param array $args Arguments from handleCommand method |
|
164
|
|
|
* @param Boolean $success Becomes true if this is a success, false for default error |
|
165
|
|
|
* |
|
166
|
|
|
* @return String desired status or error message |
|
167
|
|
|
*/ |
|
168
|
|
|
protected function getDefaultMessage($args, $success = false) |
|
169
|
|
|
{ |
|
170
|
|
|
if (false === $success) { |
|
171
|
|
|
return parent::getDefaultMessage($args, $success); |
|
172
|
|
|
} |
|
173
|
|
|
|
|
174
|
|
|
$message = ''; |
|
|
|
|
|
|
175
|
|
|
switch ($args['commandName']) { |
|
176
|
|
|
case 'submit': |
|
177
|
|
|
if ($this->templateParameters['mode'] == 'create') { |
|
178
|
|
|
$message = $this->__('Done! Route created.'); |
|
179
|
|
|
} else { |
|
180
|
|
|
$message = $this->__('Done! Route updated.'); |
|
181
|
|
|
} |
|
182
|
|
|
break; |
|
183
|
|
|
case 'delete': |
|
184
|
|
|
$message = $this->__('Done! Route deleted.'); |
|
185
|
|
|
break; |
|
186
|
|
|
default: |
|
187
|
|
|
$message = $this->__('Done! Route updated.'); |
|
188
|
|
|
break; |
|
189
|
|
|
} |
|
190
|
|
|
|
|
191
|
|
|
return $message; |
|
192
|
|
|
} |
|
193
|
|
|
|
|
194
|
|
|
/** |
|
195
|
|
|
* This method executes a certain workflow action. |
|
196
|
|
|
* |
|
197
|
|
|
* @param array $args Arguments from handleCommand method |
|
198
|
|
|
* |
|
199
|
|
|
* @return bool Whether everything worked well or not |
|
200
|
|
|
* |
|
201
|
|
|
* @throws RuntimeException Thrown if concurrent editing is recognised or another error occurs |
|
202
|
|
|
*/ |
|
203
|
|
|
public function applyAction(array $args = []) |
|
204
|
|
|
{ |
|
205
|
|
|
// get treated entity reference from persisted member var |
|
206
|
|
|
$entity = $this->entityRef; |
|
207
|
|
|
|
|
208
|
|
|
$action = $args['commandName']; |
|
209
|
|
|
|
|
210
|
|
|
$success = false; |
|
211
|
|
|
$flashBag = $this->request->getSession()->getFlashBag(); |
|
212
|
|
|
$logger = $this->container->get('logger'); |
|
213
|
|
|
try { |
|
214
|
|
|
// execute the workflow action |
|
215
|
|
|
$workflowHelper = $this->container->get('zikula_routes_module.workflow_helper'); |
|
216
|
|
|
$success = $workflowHelper->executeAction($entity, $action); |
|
217
|
|
|
} catch(\Exception $e) { |
|
218
|
|
|
$flashBag->add('error', $this->__f('Sorry, but an error occured during the %action% action. Please apply the changes again!', ['%action%' => $action]) . ' ' . $e->getMessage()); |
|
219
|
|
|
$logArgs = ['app' => 'ZikulaRoutesModule', 'user' => $this->container->get('zikula_users_module.current_user')->get('uname'), 'entity' => 'route', 'id' => $entity->createCompositeIdentifier(), 'errorMessage' => $e->getMessage()]; |
|
|
|
|
|
|
220
|
|
|
$logger->error('{app}: User {user} tried to edit the {entity} with id {id}, but failed. Error details: {errorMessage}.', $logArgs); |
|
221
|
|
|
} |
|
222
|
|
|
|
|
223
|
|
|
$this->addDefaultMessage($args, $success); |
|
224
|
|
|
|
|
225
|
|
|
if ($success && $this->templateParameters['mode'] == 'create') { |
|
226
|
|
|
// store new identifier |
|
227
|
|
|
foreach ($this->idFields as $idField) { |
|
228
|
|
|
$this->idValues[$idField] = $entity[$idField]; |
|
229
|
|
|
} |
|
230
|
|
|
} |
|
231
|
|
|
|
|
232
|
|
|
return $success; |
|
233
|
|
|
} |
|
234
|
|
|
|
|
235
|
|
|
/** |
|
236
|
|
|
* Get url to redirect to. |
|
237
|
|
|
* |
|
238
|
|
|
* @param array $args List of arguments |
|
239
|
|
|
* |
|
240
|
|
|
* @return string The redirect url |
|
241
|
|
|
*/ |
|
242
|
|
|
protected function getRedirectUrl($args) |
|
243
|
|
|
{ |
|
244
|
|
|
if ($this->repeatCreateAction) { |
|
245
|
|
|
return $this->repeatReturnUrl; |
|
246
|
|
|
} |
|
247
|
|
|
|
|
248
|
|
|
if ($this->request->getSession()->has('referer')) { |
|
249
|
|
|
$this->request->getSession()->del('referer'); |
|
|
|
|
|
|
250
|
|
|
} |
|
251
|
|
|
|
|
252
|
|
|
// normal usage, compute return url from given redirect code |
|
253
|
|
|
if (!in_array($this->returnTo, $this->getRedirectCodes())) { |
|
254
|
|
|
// invalid return code, so return the default url |
|
255
|
|
|
return $this->getDefaultReturnUrl($args); |
|
256
|
|
|
} |
|
257
|
|
|
|
|
258
|
|
|
// parse given redirect code and return corresponding url |
|
259
|
|
|
switch ($this->returnTo) { |
|
260
|
|
|
case 'admin': |
|
261
|
|
|
return $this->router->generate('zikularoutesmodule_' . $this->objectTypeLower . '_adminindex'); |
|
262
|
|
|
case 'adminView': |
|
263
|
|
|
return $this->router->generate('zikularoutesmodule_' . $this->objectTypeLower . '_adminview'); |
|
264
|
|
View Code Duplication |
case 'adminDisplay': |
|
|
|
|
|
|
265
|
|
|
if ($args['commandName'] != 'delete' && !($this->templateParameters['mode'] == 'create' && $args['commandName'] == 'cancel')) { |
|
266
|
|
|
foreach ($this->idFields as $idField) { |
|
267
|
|
|
$urlArgs[$idField] = $this->idValues[$idField]; |
|
|
|
|
|
|
268
|
|
|
} |
|
269
|
|
|
return $this->router->generate('zikularoutesmodule_' . $this->objectTypeLower . '_admindisplay', $urlArgs); |
|
|
|
|
|
|
270
|
|
|
} |
|
271
|
|
|
return $this->getDefaultReturnUrl($args); |
|
272
|
|
|
case 'user': |
|
273
|
|
|
return $this->router->generate('zikularoutesmodule_' . $this->objectTypeLower . '_index'); |
|
274
|
|
|
case 'userView': |
|
275
|
|
|
return $this->router->generate('zikularoutesmodule_' . $this->objectTypeLower . '_view'); |
|
276
|
|
View Code Duplication |
case 'userDisplay': |
|
|
|
|
|
|
277
|
|
|
if ($args['commandName'] != 'delete' && !($this->templateParameters['mode'] == 'create' && $args['commandName'] == 'cancel')) { |
|
278
|
|
|
foreach ($this->idFields as $idField) { |
|
279
|
|
|
$urlArgs[$idField] = $this->idValues[$idField]; |
|
280
|
|
|
} |
|
281
|
|
|
return $this->router->generate('zikularoutesmodule_' . $this->objectTypeLower . '_display', $urlArgs); |
|
282
|
|
|
} |
|
283
|
|
|
return $this->getDefaultReturnUrl($args); |
|
284
|
|
|
default: |
|
285
|
|
|
return $this->getDefaultReturnUrl($args); |
|
286
|
|
|
} |
|
287
|
|
|
} |
|
288
|
|
|
} |
|
289
|
|
|
|
$this->getRedirectUrl(array('commandName' => ''))can contain request data and is used in output context(s) leading to a potential security vulnerability.3 paths for user data to reach this point
in src/system/RoutesModule/Form/Handler/Common/Base/AbstractEditHandler.php on line 207
in src/system/RoutesModule/Form/Handler/Route/Base/AbstractEditHandler.php on line 118
in src/system/RoutesModule/Form/Handler/Route/Base/AbstractEditHandler.php on line 255
in src/system/RoutesModule/Form/Handler/Route/Base/AbstractEditHandler.php on line 57
in src/system/RoutesModule/Form/Handler/Common/Base/AbstractEditHandler.php on line 201
in src/system/RoutesModule/Form/Handler/Route/Base/AbstractEditHandler.php on line 118
in src/system/RoutesModule/Form/Handler/Route/Base/AbstractEditHandler.php on line 255
in src/system/RoutesModule/Form/Handler/Route/Base/AbstractEditHandler.php on line 57
in src/system/RoutesModule/Form/Handler/Common/Base/AbstractEditHandler.php on line 205
in src/system/RoutesModule/Form/Handler/Route/Base/AbstractEditHandler.php on line 118
in src/system/RoutesModule/Form/Handler/Route/Base/AbstractEditHandler.php on line 255
in src/system/RoutesModule/Form/Handler/Route/Base/AbstractEditHandler.php on line 57
Used in output context
in vendor/src/Symfony/Component/HttpFoundation/RedirectResponse.php on line 39
in vendor/src/Symfony/Component/HttpFoundation/RedirectResponse.php on line 86
in vendor/src/Symfony/Component/HttpFoundation/Response.php on line 447
in vendor/src/Symfony/Component/HttpFoundation/Response.php on line 406
Preventing Cross-Site-Scripting Attacks
Cross-Site-Scripting allows an attacker to inject malicious code into your website - in particular Javascript code, and have that code executed with the privileges of a visiting user. This can be used to obtain data, or perform actions on behalf of that visiting user.
In order to prevent this, make sure to escape all user-provided data:
General Strategies to prevent injection
In general, it is advisable to prevent any user-data to reach this point. This can be done by white-listing certain values:
if ( ! in_array($value, array('this-is-allowed', 'and-this-too'), true)) { throw new \InvalidArgumentException('This input is not allowed.'); }For numeric data, we recommend to explicitly cast the data: