Complex classes like ControllerProvider often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use ControllerProvider, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 42 | class ControllerProvider implements ControllerProviderInterface |
||
| 43 | { |
||
| 44 | |||
| 45 | /** |
||
| 46 | * Generates the not found page. |
||
| 47 | * |
||
| 48 | * @param Application $app |
||
| 49 | * the Silex application |
||
| 50 | * @param string $error |
||
| 51 | * the cause of the not found error |
||
| 52 | * |
||
| 53 | * @return Response |
||
| 54 | * the rendered not found page with the status code 404 |
||
| 55 | */ |
||
| 56 | protected function getNotFoundPage(Application $app, $error) |
||
| 57 | { |
||
| 58 | return new Response($app['twig']->render('@crud/notFound.twig', [ |
||
| 59 | 'crud' => $app['crud'], |
||
| 60 | 'error' => $error, |
||
| 61 | 'crudEntity' => '', |
||
| 62 | 'layout' => $app['crud']->getTemplate('layout', '', '') |
||
| 63 | ]), 404); |
||
| 64 | } |
||
| 65 | |||
| 66 | /** |
||
| 67 | * Postprocesses the entity after modification by handling the uploaded |
||
| 68 | * files and setting the flash. |
||
| 69 | * |
||
| 70 | * @param Application $app |
||
| 71 | * the current application |
||
| 72 | * @param AbstractData $crudData |
||
| 73 | * the data instance of the entity |
||
| 74 | * @param Entity $instance |
||
| 75 | * the entity |
||
| 76 | * @param string $entity |
||
| 77 | * the name of the entity |
||
| 78 | * @param string $mode |
||
| 79 | * whether to 'edit' or to 'create' the entity |
||
| 80 | * |
||
| 81 | * @return null|\Symfony\Component\HttpFoundation\RedirectResponse |
||
| 82 | * the HTTP response of this modification |
||
| 83 | */ |
||
| 84 | protected function modifyFilesAndSetFlashBag(Application $app, AbstractData $crudData, Entity $instance, $entity, $mode) |
||
| 85 | { |
||
| 86 | $id = $instance->get('id'); |
||
| 87 | $request = $app['request_stack']->getCurrentRequest(); |
||
| 88 | $fileHandler = new FileHandler($app['crud.filesystem'], $crudData->getDefinition()); |
||
| 89 | $result = $mode == 'edit' ? $fileHandler->updateFiles($crudData, $request, $instance, $entity) : $fileHandler->createFiles($crudData, $request, $instance, $entity); |
||
| 90 | if (!$result) { |
||
| 91 | return null; |
||
| 92 | } |
||
| 93 | $app['session']->getFlashBag()->add('success', $app['translator']->trans('crudlex.'.$mode.'.success', [ |
||
| 94 | '%label%' => $crudData->getDefinition()->getLabel(), |
||
| 95 | '%id%' => $id |
||
| 96 | ])); |
||
| 97 | return $app->redirect($app['url_generator']->generate('crudShow', ['entity' => $entity, 'id' => $id])); |
||
| 98 | } |
||
| 99 | |||
| 100 | /** |
||
| 101 | * Sets the flashes of a failed entity modification. |
||
| 102 | * |
||
| 103 | * @param Application $app |
||
| 104 | * the current application |
||
| 105 | * @param boolean $optimisticLocking |
||
| 106 | * whether the optimistic locking failed |
||
| 107 | * @param string $mode |
||
| 108 | * the modification mode, either 'create' or 'edit' |
||
| 109 | */ |
||
| 110 | protected function setValidationFailedFlashes(Application $app, $optimisticLocking, $mode) |
||
| 111 | { |
||
| 112 | $app['session']->getFlashBag()->add('danger', $app['translator']->trans('crudlex.'.$mode.'.error')); |
||
| 113 | if ($optimisticLocking) { |
||
| 114 | $app['session']->getFlashBag()->add('danger', $app['translator']->trans('crudlex.edit.locked')); |
||
| 115 | } |
||
| 116 | } |
||
| 117 | |||
| 118 | /** |
||
| 119 | * Validates and saves the new or updated entity and returns the appropriate HTTP |
||
| 120 | * response. |
||
| 121 | * |
||
| 122 | * @param Application $app |
||
| 123 | * the current application |
||
| 124 | * @param AbstractData $crudData |
||
| 125 | * the data instance of the entity |
||
| 126 | * @param Entity $instance |
||
| 127 | * the entity |
||
| 128 | * @param string $entity |
||
| 129 | * the name of the entity |
||
| 130 | * @param boolean $edit |
||
| 131 | * whether to edit (true) or to create (false) the entity |
||
| 132 | * |
||
| 133 | * @return Response |
||
| 134 | * the HTTP response of this modification |
||
| 135 | */ |
||
| 136 | protected function modifyEntity(Application $app, AbstractData $crudData, Entity $instance, $entity, $edit) |
||
| 137 | { |
||
| 138 | $fieldErrors = []; |
||
| 139 | $mode = $edit ? 'edit' : 'create'; |
||
| 140 | $request = $app['request_stack']->getCurrentRequest(); |
||
| 141 | if ($request->getMethod() == 'POST') { |
||
| 142 | $instance->populateViaRequest($request); |
||
| 143 | $validator = new EntityValidator($instance); |
||
| 144 | $validation = $validator->validate($crudData, intval($request->get('version'))); |
||
| 145 | |||
| 146 | $fieldErrors = $validation['errors']; |
||
| 147 | if (!$validation['valid']) { |
||
| 148 | $optimisticLocking = isset($fieldErrors['version']); |
||
| 149 | $this->setValidationFailedFlashes($app, $optimisticLocking, $mode); |
||
| 150 | } else { |
||
| 151 | $modified = $edit ? $crudData->update($instance) : $crudData->create($instance); |
||
| 152 | $response = $modified ? $this->modifyFilesAndSetFlashBag($app, $crudData, $instance, $entity, $mode) : false; |
||
| 153 | if ($response) { |
||
| 154 | return $response; |
||
| 155 | } |
||
| 156 | $app['session']->getFlashBag()->add('danger', $app['translator']->trans('crudlex.'.$mode.'.failed')); |
||
| 157 | } |
||
| 158 | } |
||
| 159 | |||
| 160 | return $app['twig']->render($app['crud']->getTemplate('template', 'form', $entity), [ |
||
| 161 | 'crud' => $app['crud'], |
||
| 162 | 'crudEntity' => $entity, |
||
| 163 | 'crudData' => $crudData, |
||
| 164 | 'entity' => $instance, |
||
| 165 | 'mode' => $mode, |
||
| 166 | 'fieldErrors' => $fieldErrors, |
||
| 167 | 'layout' => $app['crud']->getTemplate('layout', $mode, $entity) |
||
| 168 | ]); |
||
| 169 | } |
||
| 170 | |||
| 171 | /** |
||
| 172 | * Gets the parameters for the redirection after deleting an entity. |
||
| 173 | * |
||
| 174 | * @param Request $request |
||
| 175 | * the current request |
||
| 176 | * @param string $entity |
||
| 177 | * the entity name |
||
| 178 | * @param string $redirectPage |
||
| 179 | * reference, where the page to redirect to will be stored |
||
| 180 | * |
||
| 181 | * @return array<string,string> |
||
| 182 | * the parameters of the redirection, entity and id |
||
| 183 | */ |
||
| 184 | protected function getAfterDeleteRedirectParameters(Request $request, $entity, &$redirectPage) |
||
| 185 | { |
||
| 186 | $redirectPage = 'crudList'; |
||
| 187 | $redirectParameters = ['entity' => $entity]; |
||
| 188 | $redirectEntity = $request->get('redirectEntity'); |
||
| 189 | $redirectId = $request->get('redirectId'); |
||
| 190 | if ($redirectEntity && $redirectId) { |
||
| 191 | $redirectPage = 'crudShow'; |
||
| 192 | $redirectParameters = [ |
||
| 193 | 'entity' => $redirectEntity, |
||
| 194 | 'id' => $redirectId |
||
| 195 | ]; |
||
| 196 | } |
||
| 197 | return $redirectParameters; |
||
| 198 | } |
||
| 199 | |||
| 200 | /** |
||
| 201 | * Builds up the parameters of the list page filters. |
||
| 202 | * |
||
| 203 | * @param Request $request |
||
| 204 | * the current application |
||
| 205 | * @param EntityDefinition $definition |
||
| 206 | * the current entity definition |
||
| 207 | * @param array &$filter |
||
| 208 | * will hold a map of fields to request parameters for the filters |
||
| 209 | * @param boolean $filterActive |
||
| 210 | * reference, will be true if at least one filter is active |
||
| 211 | * @param array $filterToUse |
||
| 212 | * reference, will hold a map of fields to integers (0 or 1) which boolean filters are active |
||
| 213 | * @param array $filterOperators |
||
| 214 | * reference, will hold a map of fields to operators for AbstractData::listEntries() |
||
| 215 | */ |
||
| 216 | protected function buildUpListFilter(Request $request, EntityDefinition $definition, &$filter, &$filterActive, &$filterToUse, &$filterOperators) |
||
| 217 | { |
||
| 218 | foreach ($definition->getFilter() as $filterField) { |
||
| 219 | $type = $definition->getType($filterField); |
||
| 220 | $filter[$filterField] = $request->get('crudFilter'.$filterField); |
||
| 221 | if ($filter[$filterField]) { |
||
| 222 | $filterActive = true; |
||
| 223 | $filterToUse[$filterField] = $filter[$filterField]; |
||
| 224 | $filterOperators[$filterField] = '='; |
||
| 225 | if ($type === 'boolean') { |
||
| 226 | $filterToUse[$filterField] = $filter[$filterField] == 'true' ? 1 : 0; |
||
| 227 | } else if ($type === 'reference') { |
||
| 228 | $filter[$filterField] = ['id' => $filter[$filterField]]; |
||
| 229 | } else if ($type === 'many') { |
||
| 230 | $filter[$filterField] = array_map(function($value) { |
||
| 231 | return ['id' => $value]; |
||
| 232 | }, $filter[$filterField]); |
||
| 233 | $filterToUse[$filterField] = $filter[$filterField]; |
||
| 234 | } else if (in_array($type, ['text', 'multiline', 'fixed'])){ |
||
| 235 | $filterToUse[$filterField] = '%'.$filter[$filterField].'%'; |
||
| 236 | $filterOperators[$filterField] = 'LIKE'; |
||
| 237 | } |
||
| 238 | } |
||
| 239 | } |
||
| 240 | } |
||
| 241 | |||
| 242 | /** |
||
| 243 | * Setups the templates. |
||
| 244 | * |
||
| 245 | * @param Application $app |
||
| 246 | * the Application instance of the Silex application |
||
| 247 | */ |
||
| 248 | 10 | protected function setupTemplates(Application $app) |
|
| 254 | |||
| 255 | /** |
||
| 256 | * Setups the routes. |
||
| 257 | * |
||
| 258 | * @param Application $app |
||
| 259 | * the Application instance of the Silex application |
||
| 260 | * |
||
| 261 | * @return mixed |
||
| 262 | * the created controller factory |
||
| 263 | */ |
||
| 264 | 10 | protected function setupRoutes(Application $app) |
|
| 265 | { |
||
| 266 | |||
| 267 | 10 | $self = $this; |
|
| 268 | $localeAndCheckEntity = function(Request $request, Application $app) use ($self) { |
||
| 269 | $locale = $app['translator']->getLocale(); |
||
| 270 | $app['crud']->setLocale($locale); |
||
| 271 | if (!$app['crud']->getData($request->get('entity'))) { |
||
| 272 | return $self->getNotFoundPage($app, $app['translator']->trans('crudlex.entityNotFound')); |
||
| 273 | } |
||
| 274 | 10 | }; |
|
| 275 | |||
| 276 | 10 | $class = get_class($this); |
|
| 277 | 10 | $factory = $app['controllers_factory']; |
|
| 278 | 10 | $factory->get('/resource/static', $class.'::staticFile')->bind('crudStatic'); |
|
| 279 | 10 | $factory->match('/{entity}/create', $class.'::create')->bind('crudCreate')->before($localeAndCheckEntity, 10); |
|
| 280 | 10 | $factory->get('/{entity}', $class.'::showList')->bind('crudList')->before($localeAndCheckEntity, 10); |
|
| 281 | 10 | $factory->get('/{entity}/{id}', $class.'::show')->bind('crudShow')->before($localeAndCheckEntity, 10); |
|
| 282 | 10 | $factory->match('/{entity}/{id}/edit', $class.'::edit')->bind('crudEdit')->before($localeAndCheckEntity, 10); |
|
| 283 | 10 | $factory->post('/{entity}/{id}/delete', $class.'::delete')->bind('crudDelete')->before($localeAndCheckEntity, 10); |
|
| 284 | 10 | $factory->get('/{entity}/{id}/{field}/file', $class.'::renderFile')->bind('crudRenderFile')->before($localeAndCheckEntity, 10); |
|
| 285 | 10 | $factory->post('/{entity}/{id}/{field}/delete', $class.'::deleteFile')->bind('crudDeleteFile')->before($localeAndCheckEntity, 10); |
|
| 286 | 10 | $factory->get('/setting/locale/{locale}', $class.'::setLocale')->bind('crudSetLocale'); |
|
| 287 | |||
| 288 | 10 | return $factory; |
|
| 289 | } |
||
| 290 | |||
| 291 | /** |
||
| 292 | * Setups i18n. |
||
| 293 | * |
||
| 294 | * @param Application $app |
||
| 295 | * the Application instance of the Silex application |
||
| 296 | */ |
||
| 297 | protected function setupI18n(Application $app) |
||
| 298 | { |
||
| 299 | 10 | $app->before(function(Request $request, Application $app) { |
|
| 300 | $manageI18n = $app['crud']->isManageI18n(); |
||
| 301 | if ($manageI18n) { |
||
| 302 | $locale = $app['session']->get('locale', 'en'); |
||
| 303 | $app['translator']->setLocale($locale); |
||
| 304 | } |
||
| 305 | 10 | }, 1); |
|
| 306 | 10 | } |
|
| 307 | |||
| 308 | /** |
||
| 309 | * Implements ControllerProviderInterface::connect() connecting this |
||
| 310 | * controller. |
||
| 311 | * |
||
| 312 | * @param Application $app |
||
| 313 | * the Application instance of the Silex application |
||
| 314 | * |
||
| 315 | * @return \Silex\ControllerCollection |
||
| 316 | * this method is expected to return the used ControllerCollection instance |
||
| 317 | */ |
||
| 318 | 10 | public function connect(Application $app) |
|
| 325 | |||
| 326 | /** |
||
| 327 | * The controller for the "create" action. |
||
| 328 | * |
||
| 329 | * @param Application $app |
||
| 330 | * the Silex application |
||
| 331 | * @param string $entity |
||
| 332 | * the current entity |
||
| 333 | * |
||
| 334 | * @return Response |
||
| 335 | * the HTTP response of this action |
||
| 336 | */ |
||
| 337 | public function create(Application $app, $entity) |
||
| 345 | |||
| 346 | /** |
||
| 347 | * The controller for the "show list" action. |
||
| 348 | * |
||
| 349 | * @param Request $request |
||
| 350 | * the current request |
||
| 351 | * @param Application $app |
||
| 352 | * the Silex application |
||
| 353 | * @param string $entity |
||
| 354 | * the current entity |
||
| 355 | * |
||
| 356 | * @return Response |
||
| 357 | * the HTTP response of this action or 404 on invalid input |
||
| 358 | */ |
||
| 359 | public function showList(Request $request, Application $app, $entity) |
||
| 405 | |||
| 406 | /** |
||
| 407 | * The controller for the "show" action. |
||
| 408 | * |
||
| 409 | * @param Application $app |
||
| 410 | * the Silex application |
||
| 411 | * @param string $entity |
||
| 412 | * the current entity |
||
| 413 | * @param string $id |
||
| 414 | * the instance id to show |
||
| 415 | * |
||
| 416 | * @return Response |
||
| 417 | * the HTTP response of this action or 404 on invalid input |
||
| 418 | */ |
||
| 419 | public function show(Application $app, $entity, $id) |
||
| 454 | |||
| 455 | /** |
||
| 456 | * The controller for the "edit" action. |
||
| 457 | * |
||
| 458 | * @param Application $app |
||
| 459 | * the Silex application |
||
| 460 | * @param string $entity |
||
| 461 | * the current entity |
||
| 462 | * @param string $id |
||
| 463 | * the instance id to edit |
||
| 464 | * |
||
| 465 | * @return Response |
||
| 466 | * the HTTP response of this action or 404 on invalid input |
||
| 467 | */ |
||
| 468 | public function edit(Application $app, $entity, $id) |
||
| 478 | |||
| 479 | /** |
||
| 480 | * The controller for the "delete" action. |
||
| 481 | * |
||
| 482 | * @param Application $app |
||
| 483 | * the Silex application |
||
| 484 | * @param string $entity |
||
| 485 | * the current entity |
||
| 486 | * @param string $id |
||
| 487 | * the instance id to delete |
||
| 488 | * |
||
| 489 | * @return Response |
||
| 490 | * redirects to the entity list page or 404 on invalid input |
||
| 491 | */ |
||
| 492 | public function delete(Application $app, $entity, $id) |
||
| 522 | |||
| 523 | /** |
||
| 524 | * The controller for the "render file" action. |
||
| 525 | * |
||
| 526 | * @param Application $app |
||
| 527 | * the Silex application |
||
| 528 | * @param string $entity |
||
| 529 | * the current entity |
||
| 530 | * @param string $id |
||
| 531 | * the instance id |
||
| 532 | * @param string $field |
||
| 533 | * the field of the file to render of the instance |
||
| 534 | * |
||
| 535 | * @return Response |
||
| 536 | * the rendered file |
||
| 537 | */ |
||
| 538 | public function renderFile(Application $app, $entity, $id, $field) |
||
| 549 | |||
| 550 | /** |
||
| 551 | * The controller for the "delete file" action. |
||
| 552 | * |
||
| 553 | * @param Application $app |
||
| 554 | * the Silex application |
||
| 555 | * @param string $entity |
||
| 556 | * the current entity |
||
| 557 | * @param string $id |
||
| 558 | * the instance id |
||
| 559 | * @param string $field |
||
| 560 | * the field of the file to delete of the instance |
||
| 561 | * |
||
| 562 | * @return Response |
||
| 563 | * redirects to the instance details page or 404 on invalid input |
||
| 564 | */ |
||
| 565 | public function deleteFile(Application $app, $entity, $id, $field) |
||
| 582 | |||
| 583 | /** |
||
| 584 | * The controller for serving static files. |
||
| 585 | * |
||
| 586 | * @param Request $request |
||
| 587 | * the current request |
||
| 588 | * @param Application $app |
||
| 589 | * the Silex application |
||
| 590 | * |
||
| 591 | * @return Response |
||
| 592 | * redirects to the instance details page or 404 on invalid input |
||
| 593 | */ |
||
| 594 | public function staticFile(Request $request, Application $app) |
||
| 617 | |||
| 618 | /** |
||
| 619 | * The controller for setting the locale. |
||
| 620 | * |
||
| 621 | * @param Request $request |
||
| 622 | * the current request |
||
| 623 | * @param Application $app |
||
| 624 | * the Silex application |
||
| 625 | * @param string $locale |
||
| 626 | * the new locale |
||
| 627 | * |
||
| 628 | * @return Response |
||
| 629 | * redirects to the instance details page or 404 on invalid input |
||
| 630 | */ |
||
| 631 | public function setLocale(Request $request, Application $app, $locale) |
||
| 645 | } |
||
| 646 |
$redirectcan contain request data and is used in output context(s) leading to a potential security vulnerability.8 paths for user data to reach this point
$this->parameters['HTTP_AUTHORIZATION']seems to return tainted data, and$authorizationHeaderis assigned in ServerBag.php on line 62$this->parameters['HTTP_AUTHORIZATION']seems to return tainted data, and$authorizationHeaderis assignedin vendor/ServerBag.php on line 62
in vendor/ServerBag.php on line 77
in vendor/ParameterBag.php on line 84
$resultis assignedin vendor/Request.php on line 817
$redirectis assignedin src/CRUDlex/ControllerProvider.php on line 642
$_POST,and$_POSTis passed to Request::createRequestFromFactory() in Request.php on line 314$_POST,and$_POSTis passed to Request::createRequestFromFactory()in vendor/Request.php on line 314
$requestis passed to Request::__construct()in vendor/Request.php on line 2068
$requestis passed to Request::initialize()in vendor/Request.php on line 255
$requestis passed to ParameterBag::__construct()in vendor/Request.php on line 273
in vendor/ParameterBag.php on line 31
in vendor/ParameterBag.php on line 84
$resultis assignedin vendor/Request.php on line 817
$redirectis assignedin src/CRUDlex/ControllerProvider.php on line 642
$_SERVER,and$serveris assigned in Request.php on line 304$_SERVER,and$serveris assignedin vendor/Request.php on line 304
$serveris passed to Request::createRequestFromFactory()in vendor/Request.php on line 314
$serveris passed to Request::__construct()in vendor/Request.php on line 2068
$serveris passed to Request::initialize()in vendor/Request.php on line 255
$serveris passed to ParameterBag::__construct()in vendor/Request.php on line 278
in vendor/ParameterBag.php on line 31
in vendor/ParameterBag.php on line 84
$resultis assignedin vendor/Request.php on line 817
$redirectis assignedin src/CRUDlex/ControllerProvider.php on line 642
HTTP_CONTENT_LENGTHfrom$_SERVER,and$serveris assigned in Request.php on line 307HTTP_CONTENT_LENGTHfrom$_SERVER,and$serveris assignedin vendor/Request.php on line 307
$serveris passed to Request::createRequestFromFactory()in vendor/Request.php on line 314
$serveris passed to Request::__construct()in vendor/Request.php on line 2068
$serveris passed to Request::initialize()in vendor/Request.php on line 255
$serveris passed to ParameterBag::__construct()in vendor/Request.php on line 278
in vendor/ParameterBag.php on line 31
in vendor/ParameterBag.php on line 84
$resultis assignedin vendor/Request.php on line 817
$redirectis assignedin src/CRUDlex/ControllerProvider.php on line 642
HTTP_CONTENT_TYPEfrom$_SERVER,and$serveris assigned in Request.php on line 310HTTP_CONTENT_TYPEfrom$_SERVER,and$serveris assignedin vendor/Request.php on line 310
$serveris passed to Request::createRequestFromFactory()in vendor/Request.php on line 314
$serveris passed to Request::__construct()in vendor/Request.php on line 2068
$serveris passed to Request::initialize()in vendor/Request.php on line 255
$serveris passed to ParameterBag::__construct()in vendor/Request.php on line 278
in vendor/ParameterBag.php on line 31
in vendor/ParameterBag.php on line 84
$resultis assignedin vendor/Request.php on line 817
$redirectis assignedin src/CRUDlex/ControllerProvider.php on line 642
$server['HTTP_HOST']seems to return tainted data, and$serveris assigned in Request.php on line 380$server['HTTP_HOST']seems to return tainted data, and$serveris assignedin vendor/Request.php on line 380
$serveris assignedin vendor/Request.php on line 428
$serveris assignedin vendor/Request.php on line 429
$serveris passed to Request::createRequestFromFactory()in vendor/Request.php on line 431
$serveris passed to Request::__construct()in vendor/Request.php on line 2068
$serveris passed to Request::initialize()in vendor/Request.php on line 255
$serveris passed to ParameterBag::__construct()in vendor/Request.php on line 278
in vendor/ParameterBag.php on line 31
in vendor/ParameterBag.php on line 84
$resultis assignedin vendor/Request.php on line 817
$redirectis assignedin src/CRUDlex/ControllerProvider.php on line 642
$this->parameters['PHP_AUTH_USER']seems to return tainted data, and$headersis assigned in ServerBag.php on line 43$this->parameters['PHP_AUTH_USER']seems to return tainted data, and$headersis assignedin vendor/ServerBag.php on line 43
$headersis assignedin vendor/ServerBag.php on line 44
$this->server->getHeaders()is passed to HeaderBag::__construct()in vendor/Request.php on line 279
$valuesis assignedin vendor/HeaderBag.php on line 29
$valuesis passed to HeaderBag::set()in vendor/HeaderBag.php on line 30
$valuesis passed through array_values(), and$valuesis assignedin vendor/HeaderBag.php on line 142
in vendor/HeaderBag.php on line 145
in vendor/HeaderBag.php on line 65
$headersis assignedin vendor/HeaderBag.php on line 113
$requestUriis assignedin vendor/Request.php on line 1831
$requestUriis passed to ParameterBag::set()in vendor/Request.php on line 1862
in vendor/ParameterBag.php on line 95
in vendor/ParameterBag.php on line 84
$resultis assignedin vendor/Request.php on line 817
$redirectis assignedin src/CRUDlex/ControllerProvider.php on line 642
$this->parameters['PHP_AUTH_PW']seems to return tainted data, and$headersis assigned in ServerBag.php on line 44$this->parameters['PHP_AUTH_PW']seems to return tainted data, and$headersis assignedin vendor/ServerBag.php on line 44
$this->server->getHeaders()is passed to HeaderBag::__construct()in vendor/Request.php on line 279
$valuesis assignedin vendor/HeaderBag.php on line 29
$valuesis passed to HeaderBag::set()in vendor/HeaderBag.php on line 30
$valuesis passed through array_values(), and$valuesis assignedin vendor/HeaderBag.php on line 142
in vendor/HeaderBag.php on line 145
in vendor/HeaderBag.php on line 65
$headersis assignedin vendor/HeaderBag.php on line 113
$requestUriis assignedin vendor/Request.php on line 1831
$requestUriis passed to ParameterBag::set()in vendor/Request.php on line 1862
in vendor/ParameterBag.php on line 95
in vendor/ParameterBag.php on line 84
$resultis assignedin vendor/Request.php on line 817
$redirectis assignedin src/CRUDlex/ControllerProvider.php on line 642
Used in output context
in vendor/src/Silex/Application.php on line 376
in vendor/RedirectResponse.php on line 39
in vendor/RedirectResponse.php on line 92
in vendor/Response.php on line 399
in vendor/Response.php on line 358
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: