Issues (3887)

Security Analysis    not enabled

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.

LayoutBundle/EventListener/LayoutListener.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
namespace Oro\Bundle\LayoutBundle\EventListener;
4
5
use Symfony\Component\HttpFoundation\Response;
6
use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent;
7
8
use Oro\Component\Layout\Layout;
9
use Oro\Component\Layout\LayoutContext;
10
use Oro\Component\Layout\LayoutManager;
11
use Oro\Component\Layout\ContextInterface;
12
use Oro\Component\Layout\Exception\LogicException;
13
14
use Oro\Bundle\LayoutBundle\Request\LayoutHelper;
15
use Oro\Bundle\LayoutBundle\Annotation\Layout as LayoutAnnotation;
16
17
/**
18
 * The LayoutListener class handles the @Layout annotation.
19
 */
20
class LayoutListener
21
{
22
    /**
23
     * @var LayoutHelper
24
     */
25
    protected $layoutHelper;
26
27
    /**
28
     * @var LayoutManager
29
     */
30
    protected $layoutManager;
31
32
    /**
33
     * @param LayoutHelper $layoutHelper
34
     * @param LayoutManager $layoutManager
35
     */
36
    public function __construct(LayoutHelper $layoutHelper, LayoutManager $layoutManager)
37
    {
38
        $this->layoutHelper = $layoutHelper;
39
        $this->layoutManager = $layoutManager;
40
    }
41
42
    /**
43
     * Renders the layout and initializes the content of a new response object
44
     * with the rendered layout.
45
     *
46
     * @param GetResponseForControllerResultEvent $event
47
     *
48
     * @throws LogicException if @Layout annotation is used in incorrect way
49
     */
50
    public function onKernelView(GetResponseForControllerResultEvent $event)
51
    {
52
        $request = $event->getRequest();
53
54
        $layoutAnnotation = $this->layoutHelper->getLayoutAnnotation($request);
55
        if (!$layoutAnnotation) {
56
            return;
57
        }
58
        if ($request->attributes->get('_template')) {
59
            throw new LogicException(
60
                'The @Template() annotation cannot be used together with the @Layout() annotation.'
61
            );
62
        }
63
64
        $parameters = $event->getControllerResult();
65
        if (is_array($parameters)) {
66
            $context = new LayoutContext();
67
            foreach ($parameters as $key => $value) {
68
                $context->set($key, $value);
69
            }
70
            $this->configureContext($context, $layoutAnnotation);
71
            $layout = $this->getLayout($context, $layoutAnnotation);
72
        } elseif ($parameters instanceof ContextInterface) {
73
            $this->configureContext($parameters, $layoutAnnotation);
74
            $layout = $this->getLayout($parameters, $layoutAnnotation);
75
        } elseif ($parameters instanceof Layout) {
76
            if (!$layoutAnnotation->isEmpty()) {
77
                throw new LogicException(
78
                    'The empty @Layout() annotation must be used when '
79
                    . 'the controller returns an instance of "Oro\Component\Layout\Layout".'
80
                );
81
            }
82
            $layout = $parameters;
83
        } else {
84
            return;
85
        }
86
87
        $response = new Response();
88
        $response->setContent($layout->render());
89
        $event->setResponse($response);
90
    }
91
92
    /**
93
     * Get the layout and add parameters to the layout context.
94
     *
95
     * @param ContextInterface $context
96
     * @param LayoutAnnotation $layoutAnnotation
97
     *
98
     * @return Layout
99
     */
100
    protected function getLayout(ContextInterface $context, LayoutAnnotation $layoutAnnotation)
101
    {
102
        $layoutBuilder = $this->layoutManager->getLayoutBuilder();
103
        // TODO discuss adding root automatically
104
        $layoutBuilder->add('root', null, 'root');
105
106
        $blockThemes = $layoutAnnotation->getBlockThemes();
107
        if (!empty($blockThemes)) {
108
            $layoutBuilder->setBlockTheme($blockThemes);
0 ignored issues
show
It seems like $blockThemes defined by $layoutAnnotation->getBlockThemes() on line 106 can also be of type array; however, Oro\Component\Layout\Lay...erface::setBlockTheme() does only seem to accept string|array<integer,string>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
109
        }
110
111
        return $layoutBuilder->getLayout($context);
112
    }
113
114
    /**
115
     * Configures the layout context.
116
     *
117
     * @param ContextInterface $context
118
     * @param LayoutAnnotation $layoutAnnotation
119
     */
120
    protected function configureContext(ContextInterface $context, LayoutAnnotation $layoutAnnotation)
121
    {
122
        $action = $layoutAnnotation->getAction();
123
        if (!empty($action)) {
124
            $currentAction = $context->getOr('action');
125
            if (empty($currentAction)) {
126
                $context->set('action', $action);
127
            }
128
        }
129
        $theme = $layoutAnnotation->getTheme();
130
        if (!empty($theme)) {
131
            $currentTheme = $context->getOr('theme');
132
            if (empty($currentTheme)) {
133
                $context->set('theme', $theme);
134
            }
135
        }
136
137
        $vars = $layoutAnnotation->getVars();
138
        if (!empty($vars)) {
139
            $context->getResolver()->setRequired($vars);
140
        }
141
    }
142
}
143