This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
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 | /* |
||
6 | * This file is part of the Superdesk Web Publisher Content Bundle. |
||
7 | * |
||
8 | * Copyright 2017 Sourcefabric z.ú. and contributors. |
||
9 | * |
||
10 | * For the full copyright and license information, please see the |
||
11 | * AUTHORS and LICENSE files distributed with this source code. |
||
12 | * |
||
13 | * @copyright 2017 Sourcefabric z.ú |
||
14 | * @license http://www.superdesk.org/license |
||
15 | */ |
||
16 | |||
17 | namespace SWP\Bundle\CoreBundle\Controller; |
||
18 | |||
19 | use Doctrine\ORM\NonUniqueResultException; |
||
20 | use SWP\Bundle\CoreBundle\Model\ArticleInterface; |
||
21 | use SWP\Bundle\CoreBundle\Repository\ArticleRepositoryInterface; |
||
22 | use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; |
||
23 | use Symfony\Component\HttpFoundation\RedirectResponse; |
||
24 | use Symfony\Component\HttpFoundation\Request; |
||
25 | use Symfony\Component\Routing\Generator\UrlGeneratorInterface; |
||
26 | use Symfony\Component\Routing\RouterInterface; |
||
27 | |||
28 | class RedirectingController extends AbstractController |
||
29 | { |
||
30 | private $router; |
||
31 | |||
32 | private $articleRepository; |
||
33 | |||
34 | public function __construct(RouterInterface $router, ArticleRepositoryInterface $articleRepository) |
||
35 | { |
||
36 | $this->router = $router; |
||
37 | $this->articleRepository = $articleRepository; |
||
38 | } |
||
39 | |||
40 | public function redirectBasedOnExtraDataAction(Request $request, string $key, string $value): RedirectResponse |
||
41 | { |
||
42 | try { |
||
43 | $existingArticle = $this->articleRepository->getArticleByExtraData($key, $value)->getQuery()->getOneOrNullResult(); |
||
44 | if (null === $existingArticle) { |
||
45 | $existingArticle = $this->articleRepository->getArticleByPackageExtraData($key, $value)->getQuery()->getOneOrNullResult(); |
||
46 | } |
||
47 | } catch (NonUniqueResultException $e) { |
||
48 | $existingArticle = null; |
||
49 | } |
||
50 | |||
51 | if (null === $existingArticle || null === $existingArticle->getRoute()) { |
||
52 | throw $this->createNotFoundException('Article with provided data was not found.'); |
||
53 | } |
||
54 | |||
55 | return $this->redirect($this->generateArticleUrl($request, $existingArticle), 301); |
||
0 ignored issues
–
show
|
|||
56 | } |
||
57 | |||
58 | public function redirectBasedOnSlugAction(Request $request, string $slug): RedirectResponse |
||
59 | { |
||
60 | $existingArticle = $this->articleRepository->findOneBySlug($slug); |
||
61 | if (null === $existingArticle || null === $existingArticle->getRoute()) { |
||
62 | throw $this->createNotFoundException('Article not found.'); |
||
63 | } |
||
64 | |||
65 | return $this->redirect($this->generateArticleUrl($request, $existingArticle), 301); |
||
0 ignored issues
–
show
$existingArticle of type object<SWP\Bundle\Conten...Model\ArticleInterface> is not a sub-type of object<SWP\Bundle\CoreBu...Model\ArticleInterface> . It seems like you assume a child interface of the interface SWP\Bundle\ContentBundle\Model\ArticleInterface to be always present.
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass. Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type. ![]() Security
Cross-Site Scripting
introduced
by
$this->generateArticleUr...uest, $existingArticle) can contain request data and is used in output context(s) leading to a potential security vulnerability.
4 paths for user data to reach this point
1. Path:
$this->parameters['HTTP_AUTHORIZATION'] seems to return tainted data, and $authorizationHeader is assigned
in ServerBag.php on line 59
2. Path:
Read from
$_POST, and $_POST is passed to Request::createRequestFromFactory()
in Request.php on line 285
3. Path:
$this->parameters['PHP_AUTH_USER'] seems to return tainted data, and $headers is assigned
in ServerBag.php on line 40
4. Path:
$this->parameters['PHP_AUTH_PW'] seems to return tainted data, and $headers is assigned
in ServerBag.php on line 41
Used in output context
Preventing Cross-Site-Scripting AttacksCross-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:
// for HTML
$sanitized = htmlentities($tainted, ENT_QUOTES);
// for URLs
$sanitized = urlencode($tainted);
General Strategies to prevent injectionIn 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: $sanitized = (integer) $tainted;
![]() |
|||
66 | } |
||
67 | |||
68 | private function generateArticleUrl(Request $request, ArticleInterface $article): string |
||
69 | { |
||
70 | $parameters = ['slug' => $article->getSlug()]; |
||
71 | if ($request->query->has('amp')) { |
||
72 | $parameters['amp'] = 1; |
||
73 | } |
||
74 | |||
75 | return $this->router->generate($article->getRoute(), $parameters, UrlGeneratorInterface::ABSOLUTE_URL); |
||
0 ignored issues
–
show
$article->getRoute() is of type object<SWP\Bundle\Conten...e\Model\RouteInterface> , but the function expects a string .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
![]() |
|||
76 | } |
||
77 | } |
||
78 |
$this->generateArticleUr...uest, $existingArticle)
can contain request data and is used in output context(s) leading to a potential security vulnerability.4 paths for user data to reach this point
$this->parameters['HTTP_AUTHORIZATION']
seems to return tainted data, and$authorizationHeader
is assigned in ServerBag.php on line 59$this->parameters['HTTP_AUTHORIZATION']
seems to return tainted data, and$authorizationHeader
is assignedin vendor/ServerBag.php on line 59
in vendor/ServerBag.php on line 74
in vendor/ParameterBag.php on line 77
$baseUrl
is assignedin vendor/Request.php on line 1800
$baseUrl
is passed through rtrim()in vendor/Request.php on line 1856
in vendor/Request.php on line 889
in vendor/Request.php on line 892
$request->getBaseUrl()
is passed to RequestContext::setBaseUrl()in vendor/RequestContext.php on line 55
in vendor/RequestContext.php on line 86
in vendor/RequestContext.php on line 74
$url
is assignedin vendor/Generator/UrlGenerator.php on line 279
in vendor/Generator/CompiledUrlGenerator.php on line 56
in vendor/Router.php on line 250
in src/SWP/Bundle/CoreBundle/Controller/RedirectingController.php on line 75
in src/SWP/Bundle/CoreBundle/Controller/RedirectingController.php on line 55
$_POST,
and$_POST
is passed to Request::createRequestFromFactory() in Request.php on line 285$_POST,
and$_POST
is passed to Request::createRequestFromFactory()in vendor/Request.php on line 285
$request
is passed to Request::__construct()in vendor/Request.php on line 1981
$request
is passed to Request::initialize()in vendor/Request.php on line 239
$request
is passed to ParameterBag::__construct()in vendor/Request.php on line 257
in vendor/ParameterBag.php on line 28
in vendor/ParameterBag.php on line 77
$baseUrl
is assignedin vendor/Request.php on line 1800
$baseUrl
is passed through rtrim()in vendor/Request.php on line 1856
in vendor/Request.php on line 889
in vendor/Request.php on line 892
$request->getBaseUrl()
is passed to RequestContext::setBaseUrl()in vendor/RequestContext.php on line 55
in vendor/RequestContext.php on line 86
in vendor/RequestContext.php on line 74
$url
is assignedin vendor/Generator/UrlGenerator.php on line 279
in vendor/Generator/CompiledUrlGenerator.php on line 56
in vendor/Router.php on line 250
in src/SWP/Bundle/CoreBundle/Controller/RedirectingController.php on line 75
in src/SWP/Bundle/CoreBundle/Controller/RedirectingController.php on line 55
$this->parameters['PHP_AUTH_USER']
seems to return tainted data, and$headers
is assigned in ServerBag.php on line 40$this->parameters['PHP_AUTH_USER']
seems to return tainted data, and$headers
is assignedin vendor/ServerBag.php on line 40
$headers
is assignedin vendor/ServerBag.php on line 41
$this->server->getHeaders()
is passed to HeaderBag::__construct()in vendor/Request.php on line 263
$values
is assignedin vendor/HeaderBag.php on line 29
$values
is passed to HeaderBag::set()in vendor/HeaderBag.php on line 30
$values
is passed through array_values(), and$values
is assignedin vendor/HeaderBag.php on line 145
in vendor/HeaderBag.php on line 148
in vendor/HeaderBag.php on line 68
$headers
is assignedin vendor/HeaderBag.php on line 113
$host
is assignedin vendor/Request.php on line 1156
$host
is passed through trim(), andtrim($host)
is passed through preg_replace(), andpreg_replace('/:\\d+$/', '', trim($host))
is passed through strtolower(), and$host
is assignedin vendor/Request.php on line 1164
$request->getHost()
is passed to RequestContext::setHost()in vendor/RequestContext.php on line 58
$host
is passed through strtolower(), and RequestContext::$host is assignedin vendor/RequestContext.php on line 162
in vendor/RequestContext.php on line 150
$host
is assignedin vendor/Generator/UrlGenerator.php on line 221
$schemeAuthority
is assignedin vendor/Generator/UrlGenerator.php on line 272
$url
is assignedin vendor/Generator/UrlGenerator.php on line 279
in vendor/Generator/CompiledUrlGenerator.php on line 56
in vendor/Router.php on line 250
in src/SWP/Bundle/CoreBundle/Controller/RedirectingController.php on line 75
in src/SWP/Bundle/CoreBundle/Controller/RedirectingController.php on line 55
$this->parameters['PHP_AUTH_PW']
seems to return tainted data, and$headers
is assigned in ServerBag.php on line 41$this->parameters['PHP_AUTH_PW']
seems to return tainted data, and$headers
is assignedin vendor/ServerBag.php on line 41
$this->server->getHeaders()
is passed to HeaderBag::__construct()in vendor/Request.php on line 263
$values
is assignedin vendor/HeaderBag.php on line 29
$values
is passed to HeaderBag::set()in vendor/HeaderBag.php on line 30
$values
is passed through array_values(), and$values
is assignedin vendor/HeaderBag.php on line 145
in vendor/HeaderBag.php on line 148
in vendor/HeaderBag.php on line 68
$headers
is assignedin vendor/HeaderBag.php on line 113
$host
is assignedin vendor/Request.php on line 1156
$host
is passed through trim(), andtrim($host)
is passed through preg_replace(), andpreg_replace('/:\\d+$/', '', trim($host))
is passed through strtolower(), and$host
is assignedin vendor/Request.php on line 1164
$request->getHost()
is passed to RequestContext::setHost()in vendor/RequestContext.php on line 58
$host
is passed through strtolower(), and RequestContext::$host is assignedin vendor/RequestContext.php on line 162
in vendor/RequestContext.php on line 150
$host
is assignedin vendor/Generator/UrlGenerator.php on line 221
$schemeAuthority
is assignedin vendor/Generator/UrlGenerator.php on line 272
$url
is assignedin vendor/Generator/UrlGenerator.php on line 279
in vendor/Generator/CompiledUrlGenerator.php on line 56
in vendor/Router.php on line 250
in src/SWP/Bundle/CoreBundle/Controller/RedirectingController.php on line 75
in src/SWP/Bundle/CoreBundle/Controller/RedirectingController.php on line 55
Used in output context
in vendor/Controller/ControllerTrait.php on line 104
in vendor/RedirectResponse.php on line 39
in vendor/RedirectResponse.php on line 92
in vendor/Response.php on line 404
in vendor/Response.php on line 363
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:
For numeric data, we recommend to explicitly cast the data: