Issues (541)

Security Analysis    8 potential vulnerabilities

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

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.
  Cross-Site Scripting (6)
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 (1)
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 (1)
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.

CoreBundle/Controller/RedirectingController.php (4 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
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
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
  1. $this->parameters['HTTP_AUTHORIZATION'] seems to return tainted data, and $authorizationHeader is assigned
    in vendor/ServerBag.php on line 59
  2. ParameterBag::$parameters is assigned
    in vendor/ServerBag.php on line 74
  3. Tainted property ParameterBag::$parameters is read
    in vendor/ParameterBag.php on line 77
  4. ParameterBag::get() returns tainted data, and $baseUrl is assigned
    in vendor/Request.php on line 1800
  5. $baseUrl is passed through rtrim()
    in vendor/Request.php on line 1856
  6. Request::prepareBaseUrl() returns tainted data, and Request::$baseUrl is assigned
    in vendor/Request.php on line 889
  7. Tainted property Request::$baseUrl is read
    in vendor/Request.php on line 892
  8. Request::getBaseUrl() returns tainted data, and $request->getBaseUrl() is passed to RequestContext::setBaseUrl()
    in vendor/RequestContext.php on line 55
  9. RequestContext::$baseUrl is assigned
    in vendor/RequestContext.php on line 86
  10. Tainted property RequestContext::$baseUrl is read
    in vendor/RequestContext.php on line 74
  11. RequestContext::getBaseUrl() returns tainted data, and $url is assigned
    in vendor/Generator/UrlGenerator.php on line 279
  12. UrlGenerator::doGenerate() returns tainted data
    in vendor/Generator/CompiledUrlGenerator.php on line 56
  13. CompiledUrlGenerator::generate() returns tainted data
    in vendor/Router.php on line 250
  14. Router::generate() returns tainted data
    in src/SWP/Bundle/CoreBundle/Controller/RedirectingController.php on line 75
  15. RedirectingController::generateArticleUrl() returns tainted data
    in src/SWP/Bundle/CoreBundle/Controller/RedirectingController.php on line 55
  2. Path: Read from $_POST, and $_POST is passed to Request::createRequestFromFactory() in Request.php on line 285
  1. Read from $_POST, and $_POST is passed to Request::createRequestFromFactory()
    in vendor/Request.php on line 285
  2. $request is passed to Request::__construct()
    in vendor/Request.php on line 1981
  3. $request is passed to Request::initialize()
    in vendor/Request.php on line 239
  4. $request is passed to ParameterBag::__construct()
    in vendor/Request.php on line 257
  5. ParameterBag::$parameters is assigned
    in vendor/ParameterBag.php on line 28
  6. Tainted property ParameterBag::$parameters is read
    in vendor/ParameterBag.php on line 77
  7. ParameterBag::get() returns tainted data, and $baseUrl is assigned
    in vendor/Request.php on line 1800
  8. $baseUrl is passed through rtrim()
    in vendor/Request.php on line 1856
  9. Request::prepareBaseUrl() returns tainted data, and Request::$baseUrl is assigned
    in vendor/Request.php on line 889
  10. Tainted property Request::$baseUrl is read
    in vendor/Request.php on line 892
  11. Request::getBaseUrl() returns tainted data, and $request->getBaseUrl() is passed to RequestContext::setBaseUrl()
    in vendor/RequestContext.php on line 55
  12. RequestContext::$baseUrl is assigned
    in vendor/RequestContext.php on line 86
  13. Tainted property RequestContext::$baseUrl is read
    in vendor/RequestContext.php on line 74
  14. RequestContext::getBaseUrl() returns tainted data, and $url is assigned
    in vendor/Generator/UrlGenerator.php on line 279
  15. UrlGenerator::doGenerate() returns tainted data
    in vendor/Generator/CompiledUrlGenerator.php on line 56
  16. CompiledUrlGenerator::generate() returns tainted data
    in vendor/Router.php on line 250
  17. Router::generate() returns tainted data
    in src/SWP/Bundle/CoreBundle/Controller/RedirectingController.php on line 75
  18. RedirectingController::generateArticleUrl() returns tainted data
    in src/SWP/Bundle/CoreBundle/Controller/RedirectingController.php on line 55
  3. Path: $this->parameters['PHP_AUTH_USER'] seems to return tainted data, and $headers is assigned in ServerBag.php on line 40
  1. $this->parameters['PHP_AUTH_USER'] seems to return tainted data, and $headers is assigned
    in vendor/ServerBag.php on line 40
  2. $headers is assigned
    in vendor/ServerBag.php on line 41
  3. ServerBag::getHeaders() returns tainted data, and $this->server->getHeaders() is passed to HeaderBag::__construct()
    in vendor/Request.php on line 263
  4. $values is assigned
    in vendor/HeaderBag.php on line 29
  5. $values is passed to HeaderBag::set()
    in vendor/HeaderBag.php on line 30
  6. $values is passed through array_values(), and $values is assigned
    in vendor/HeaderBag.php on line 145
  7. HeaderBag::$headers is assigned
    in vendor/HeaderBag.php on line 148
  8. Tainted property HeaderBag::$headers is read
    in vendor/HeaderBag.php on line 68
  9. HeaderBag::all() returns tainted data, and $headers is assigned
    in vendor/HeaderBag.php on line 113
  10. HeaderBag::get() returns tainted data, and $host is assigned
    in vendor/Request.php on line 1156
  11. $host is passed through trim(), and trim($host) is passed through preg_replace(), and preg_replace('/:\\d+$/', '', trim($host)) is passed through strtolower(), and $host is assigned
    in vendor/Request.php on line 1164
  12. Request::getHost() returns tainted data, and $request->getHost() is passed to RequestContext::setHost()
    in vendor/RequestContext.php on line 58
  13. $host is passed through strtolower(), and RequestContext::$host is assigned
    in vendor/RequestContext.php on line 162
  14. Tainted property RequestContext::$host is read
    in vendor/RequestContext.php on line 150
  15. RequestContext::getHost() returns tainted data, and $host is assigned
    in vendor/Generator/UrlGenerator.php on line 221
  16. $schemeAuthority is assigned
    in vendor/Generator/UrlGenerator.php on line 272
  17. $url is assigned
    in vendor/Generator/UrlGenerator.php on line 279
  18. UrlGenerator::doGenerate() returns tainted data
    in vendor/Generator/CompiledUrlGenerator.php on line 56
  19. CompiledUrlGenerator::generate() returns tainted data
    in vendor/Router.php on line 250
  20. Router::generate() returns tainted data
    in src/SWP/Bundle/CoreBundle/Controller/RedirectingController.php on line 75
  21. RedirectingController::generateArticleUrl() returns tainted data
    in src/SWP/Bundle/CoreBundle/Controller/RedirectingController.php on line 55
  4. Path: $this->parameters['PHP_AUTH_PW'] seems to return tainted data, and $headers is assigned in ServerBag.php on line 41
  1. $this->parameters['PHP_AUTH_PW'] seems to return tainted data, and $headers is assigned
    in vendor/ServerBag.php on line 41
  2. ServerBag::getHeaders() returns tainted data, and $this->server->getHeaders() is passed to HeaderBag::__construct()
    in vendor/Request.php on line 263
  3. $values is assigned
    in vendor/HeaderBag.php on line 29
  4. $values is passed to HeaderBag::set()
    in vendor/HeaderBag.php on line 30
  5. $values is passed through array_values(), and $values is assigned
    in vendor/HeaderBag.php on line 145
  6. HeaderBag::$headers is assigned
    in vendor/HeaderBag.php on line 148
  7. Tainted property HeaderBag::$headers is read
    in vendor/HeaderBag.php on line 68
  8. HeaderBag::all() returns tainted data, and $headers is assigned
    in vendor/HeaderBag.php on line 113
  9. HeaderBag::get() returns tainted data, and $host is assigned
    in vendor/Request.php on line 1156
  10. $host is passed through trim(), and trim($host) is passed through preg_replace(), and preg_replace('/:\\d+$/', '', trim($host)) is passed through strtolower(), and $host is assigned
    in vendor/Request.php on line 1164
  11. Request::getHost() returns tainted data, and $request->getHost() is passed to RequestContext::setHost()
    in vendor/RequestContext.php on line 58
  12. $host is passed through strtolower(), and RequestContext::$host is assigned
    in vendor/RequestContext.php on line 162
  13. Tainted property RequestContext::$host is read
    in vendor/RequestContext.php on line 150
  14. RequestContext::getHost() returns tainted data, and $host is assigned
    in vendor/Generator/UrlGenerator.php on line 221
  15. $schemeAuthority is assigned
    in vendor/Generator/UrlGenerator.php on line 272
  16. $url is assigned
    in vendor/Generator/UrlGenerator.php on line 279
  17. UrlGenerator::doGenerate() returns tainted data
    in vendor/Generator/CompiledUrlGenerator.php on line 56
  18. CompiledUrlGenerator::generate() returns tainted data
    in vendor/Router.php on line 250
  19. Router::generate() returns tainted data
    in src/SWP/Bundle/CoreBundle/Controller/RedirectingController.php on line 75
  20. RedirectingController::generateArticleUrl() returns tainted data
    in src/SWP/Bundle/CoreBundle/Controller/RedirectingController.php on line 55

Used in output context

  1. ControllerTrait::redirect() uses RedirectResponse::__construct() ($url)
    in vendor/Controller/ControllerTrait.php on line 104
  2. RedirectResponse::__construct() uses RedirectResponse::setTargetUrl() ($url)
    in vendor/RedirectResponse.php on line 39
  3. RedirectResponse::setTargetUrl() uses Response::setContent() ($content)
    in vendor/RedirectResponse.php on line 92
  4. Response::setContent() uses property Response::$content for writing
    in vendor/Response.php on line 404
  5. Property Response::$content is used in echo
    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:

// for HTML
$sanitized = htmlentities($tainted, ENT_QUOTES);

// for URLs
$sanitized = urlencode($tainted);

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:

$sanitized = (integer) $tainted;
Loading history...
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.

Loading history...
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
  1. $this->parameters['HTTP_AUTHORIZATION'] seems to return tainted data, and $authorizationHeader is assigned
    in vendor/ServerBag.php on line 59
  2. ParameterBag::$parameters is assigned
    in vendor/ServerBag.php on line 74
  3. Tainted property ParameterBag::$parameters is read
    in vendor/ParameterBag.php on line 77
  4. ParameterBag::get() returns tainted data, and $baseUrl is assigned
    in vendor/Request.php on line 1800
  5. $baseUrl is passed through rtrim()
    in vendor/Request.php on line 1856
  6. Request::prepareBaseUrl() returns tainted data, and Request::$baseUrl is assigned
    in vendor/Request.php on line 889
  7. Tainted property Request::$baseUrl is read
    in vendor/Request.php on line 892
  8. Request::getBaseUrl() returns tainted data, and $request->getBaseUrl() is passed to RequestContext::setBaseUrl()
    in vendor/RequestContext.php on line 55
  9. RequestContext::$baseUrl is assigned
    in vendor/RequestContext.php on line 86
  10. Tainted property RequestContext::$baseUrl is read
    in vendor/RequestContext.php on line 74
  11. RequestContext::getBaseUrl() returns tainted data, and $url is assigned
    in vendor/Generator/UrlGenerator.php on line 279
  12. UrlGenerator::doGenerate() returns tainted data
    in vendor/Generator/CompiledUrlGenerator.php on line 56
  13. CompiledUrlGenerator::generate() returns tainted data
    in vendor/Router.php on line 250
  14. Router::generate() returns tainted data
    in src/SWP/Bundle/CoreBundle/Controller/RedirectingController.php on line 75
  15. RedirectingController::generateArticleUrl() returns tainted data
    in src/SWP/Bundle/CoreBundle/Controller/RedirectingController.php on line 65
  2. Path: Read from $_POST, and $_POST is passed to Request::createRequestFromFactory() in Request.php on line 285
  1. Read from $_POST, and $_POST is passed to Request::createRequestFromFactory()
    in vendor/Request.php on line 285
  2. $request is passed to Request::__construct()
    in vendor/Request.php on line 1981
  3. $request is passed to Request::initialize()
    in vendor/Request.php on line 239
  4. $request is passed to ParameterBag::__construct()
    in vendor/Request.php on line 257
  5. ParameterBag::$parameters is assigned
    in vendor/ParameterBag.php on line 28
  6. Tainted property ParameterBag::$parameters is read
    in vendor/ParameterBag.php on line 77
  7. ParameterBag::get() returns tainted data, and $baseUrl is assigned
    in vendor/Request.php on line 1800
  8. $baseUrl is passed through rtrim()
    in vendor/Request.php on line 1856
  9. Request::prepareBaseUrl() returns tainted data, and Request::$baseUrl is assigned
    in vendor/Request.php on line 889
  10. Tainted property Request::$baseUrl is read
    in vendor/Request.php on line 892
  11. Request::getBaseUrl() returns tainted data, and $request->getBaseUrl() is passed to RequestContext::setBaseUrl()
    in vendor/RequestContext.php on line 55
  12. RequestContext::$baseUrl is assigned
    in vendor/RequestContext.php on line 86
  13. Tainted property RequestContext::$baseUrl is read
    in vendor/RequestContext.php on line 74
  14. RequestContext::getBaseUrl() returns tainted data, and $url is assigned
    in vendor/Generator/UrlGenerator.php on line 279
  15. UrlGenerator::doGenerate() returns tainted data
    in vendor/Generator/CompiledUrlGenerator.php on line 56
  16. CompiledUrlGenerator::generate() returns tainted data
    in vendor/Router.php on line 250
  17. Router::generate() returns tainted data
    in src/SWP/Bundle/CoreBundle/Controller/RedirectingController.php on line 75
  18. RedirectingController::generateArticleUrl() returns tainted data
    in src/SWP/Bundle/CoreBundle/Controller/RedirectingController.php on line 65
  3. Path: $this->parameters['PHP_AUTH_USER'] seems to return tainted data, and $headers is assigned in ServerBag.php on line 40
  1. $this->parameters['PHP_AUTH_USER'] seems to return tainted data, and $headers is assigned
    in vendor/ServerBag.php on line 40
  2. $headers is assigned
    in vendor/ServerBag.php on line 41
  3. ServerBag::getHeaders() returns tainted data, and $this->server->getHeaders() is passed to HeaderBag::__construct()
    in vendor/Request.php on line 263
  4. $values is assigned
    in vendor/HeaderBag.php on line 29
  5. $values is passed to HeaderBag::set()
    in vendor/HeaderBag.php on line 30
  6. $values is passed through array_values(), and $values is assigned
    in vendor/HeaderBag.php on line 145
  7. HeaderBag::$headers is assigned
    in vendor/HeaderBag.php on line 148
  8. Tainted property HeaderBag::$headers is read
    in vendor/HeaderBag.php on line 68
  9. HeaderBag::all() returns tainted data, and $headers is assigned
    in vendor/HeaderBag.php on line 113
  10. HeaderBag::get() returns tainted data, and $host is assigned
    in vendor/Request.php on line 1156
  11. $host is passed through trim(), and trim($host) is passed through preg_replace(), and preg_replace('/:\\d+$/', '', trim($host)) is passed through strtolower(), and $host is assigned
    in vendor/Request.php on line 1164
  12. Request::getHost() returns tainted data, and $request->getHost() is passed to RequestContext::setHost()
    in vendor/RequestContext.php on line 58
  13. $host is passed through strtolower(), and RequestContext::$host is assigned
    in vendor/RequestContext.php on line 162
  14. Tainted property RequestContext::$host is read
    in vendor/RequestContext.php on line 150
  15. RequestContext::getHost() returns tainted data, and $host is assigned
    in vendor/Generator/UrlGenerator.php on line 221
  16. $schemeAuthority is assigned
    in vendor/Generator/UrlGenerator.php on line 272
  17. $url is assigned
    in vendor/Generator/UrlGenerator.php on line 279
  18. UrlGenerator::doGenerate() returns tainted data
    in vendor/Generator/CompiledUrlGenerator.php on line 56
  19. CompiledUrlGenerator::generate() returns tainted data
    in vendor/Router.php on line 250
  20. Router::generate() returns tainted data
    in src/SWP/Bundle/CoreBundle/Controller/RedirectingController.php on line 75
  21. RedirectingController::generateArticleUrl() returns tainted data
    in src/SWP/Bundle/CoreBundle/Controller/RedirectingController.php on line 65
  4. Path: $this->parameters['PHP_AUTH_PW'] seems to return tainted data, and $headers is assigned in ServerBag.php on line 41
  1. $this->parameters['PHP_AUTH_PW'] seems to return tainted data, and $headers is assigned
    in vendor/ServerBag.php on line 41
  2. ServerBag::getHeaders() returns tainted data, and $this->server->getHeaders() is passed to HeaderBag::__construct()
    in vendor/Request.php on line 263
  3. $values is assigned
    in vendor/HeaderBag.php on line 29
  4. $values is passed to HeaderBag::set()
    in vendor/HeaderBag.php on line 30
  5. $values is passed through array_values(), and $values is assigned
    in vendor/HeaderBag.php on line 145
  6. HeaderBag::$headers is assigned
    in vendor/HeaderBag.php on line 148
  7. Tainted property HeaderBag::$headers is read
    in vendor/HeaderBag.php on line 68
  8. HeaderBag::all() returns tainted data, and $headers is assigned
    in vendor/HeaderBag.php on line 113
  9. HeaderBag::get() returns tainted data, and $host is assigned
    in vendor/Request.php on line 1156
  10. $host is passed through trim(), and trim($host) is passed through preg_replace(), and preg_replace('/:\\d+$/', '', trim($host)) is passed through strtolower(), and $host is assigned
    in vendor/Request.php on line 1164
  11. Request::getHost() returns tainted data, and $request->getHost() is passed to RequestContext::setHost()
    in vendor/RequestContext.php on line 58
  12. $host is passed through strtolower(), and RequestContext::$host is assigned
    in vendor/RequestContext.php on line 162
  13. Tainted property RequestContext::$host is read
    in vendor/RequestContext.php on line 150
  14. RequestContext::getHost() returns tainted data, and $host is assigned
    in vendor/Generator/UrlGenerator.php on line 221
  15. $schemeAuthority is assigned
    in vendor/Generator/UrlGenerator.php on line 272
  16. $url is assigned
    in vendor/Generator/UrlGenerator.php on line 279
  17. UrlGenerator::doGenerate() returns tainted data
    in vendor/Generator/CompiledUrlGenerator.php on line 56
  18. CompiledUrlGenerator::generate() returns tainted data
    in vendor/Router.php on line 250
  19. Router::generate() returns tainted data
    in src/SWP/Bundle/CoreBundle/Controller/RedirectingController.php on line 75
  20. RedirectingController::generateArticleUrl() returns tainted data
    in src/SWP/Bundle/CoreBundle/Controller/RedirectingController.php on line 65

Used in output context

  1. ControllerTrait::redirect() uses RedirectResponse::__construct() ($url)
    in vendor/Controller/ControllerTrait.php on line 104
  2. RedirectResponse::__construct() uses RedirectResponse::setTargetUrl() ($url)
    in vendor/RedirectResponse.php on line 39
  3. RedirectResponse::setTargetUrl() uses Response::setContent() ($content)
    in vendor/RedirectResponse.php on line 92
  4. Response::setContent() uses property Response::$content for writing
    in vendor/Response.php on line 404
  5. Property Response::$content is used in echo
    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:

// for HTML
$sanitized = htmlentities($tainted, ENT_QUOTES);

// for URLs
$sanitized = urlencode($tainted);

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:

$sanitized = (integer) $tainted;
Loading history...
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);
Loading history...
76
    }
77
}
78