Issues (159)

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.

src/Controller/TreeController.php (3 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 Sonata Project package.
7
 *
8
 * (c) Thomas Rabaix <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Sonata\DoctrinePHPCRAdminBundle\Controller;
15
16
use Doctrine\Bundle\PHPCRBundle\ManagerRegistry;
17
use PHPCR\Util\PathHelper;
18
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
19
use Symfony\Component\HttpFoundation\JsonResponse;
20
use Symfony\Component\HttpFoundation\Request;
21
use Symfony\Component\HttpFoundation\Response;
22
23
/**
24
 * A controller to render the tree block.
25
 */
26
class TreeController extends Controller
0 ignored issues
show
Deprecated Code introduced by
The class Symfony\Bundle\Framework...e\Controller\Controller has been deprecated with message: since Symfony 4.2, use "Symfony\Bundle\FrameworkBundle\Controller\AbstractController" instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
27
{
28
    /**
29
     * @var string
30
     */
31
    private $template = '@SonataDoctrinePHPCRAdmin/Tree/tree.html.twig';
32
33
    /**
34
     * @var \PHPCR\SessionInterface
35
     */
36
    private $session;
37
    /**
38
     * @var array
39
     */
40
    private $treeConfiguration;
41
42
    /**
43
     * @param string $sessionName
44
     * @param array  $treeConfiguration     same structure as defined in Configuration
45
     * @param string $defaultRepositoryName The name of the default resource repository
46
     * @param string $template
47
     */
48
    public function __construct(
49
        ManagerRegistry $manager,
50
        $sessionName,
51
        array $treeConfiguration,
52
        $defaultRepositoryName,
53
        $template = null
54
    ) {
55
        if ($template) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $template of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
56
            $this->template = $template;
57
        }
58
59
        $this->session = $manager->getConnection($sessionName);
0 ignored issues
show
Documentation Bug introduced by
It seems like $manager->getConnection($sessionName) of type object<Doctrine\Persistence\ObjectManager> is incompatible with the declared type object<PHPCR\SessionInterface> of property $session.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
60
        if (null === $treeConfiguration['repository_name']) {
61
            $treeConfiguration['repository_name'] = $defaultRepositoryName;
62
        }
63
        $this->treeConfiguration = $treeConfiguration;
64
    }
65
66
    /**
67
     * Renders a tree, passing the routes for each of the admin types (document types)
68
     * to the view.
69
     *
70
     * @return Response
71
     */
72
    public function treeAction(Request $request)
73
    {
74
        $root = $request->attributes->get('root');
75
76
        return $this->render($this->template, [
77
            'root_node' => $root,
78
            'routing_defaults' => $this->treeConfiguration['routing_defaults'],
79
            'repository_name' => $this->treeConfiguration['repository_name'],
80
            'reorder' => $this->treeConfiguration['reorder'],
81
            'move' => $this->treeConfiguration['move'],
82
            'sortable_by' => $this->treeConfiguration['sortable_by'],
83
        ]);
84
    }
85
86
    /**
87
     * Reorder $moved (child of $parent) before or after $target.
88
     *
89
     * @return Response
90
     */
91
    public function reorderAction(Request $request)
92
    {
93
        $parentPath = $request->get('parent');
94
        $dropedAtPath = $request->get('dropped');
95
        $targetPath = $request->get('target');
96
        $position = $request->get('position');
97
98
        if (null === $parentPath || null === $dropedAtPath || null === $targetPath) {
99
            return new JsonResponse(['Parameters parent, dropped and target has to be set to reorder.'], Response::HTTP_BAD_REQUEST);
100
        }
101
102
        if (\in_array($position, ['over', 'child'], true)) {
103
            return new JsonResponse(['Can not reorder when dropping into a collection.'], Response::HTTP_BAD_REQUEST);
104
        }
105
106
        $before = 'before' === $position;
107
        $parentNode = $this->session->getNode($parentPath);
108
        $targetName = PathHelper::getNodeName($targetPath);
109
        if (!$before) {
110
            $nodesIterator = $parentNode->getNodes();
111
            $nodesIterator->rewind();
112
            while ($nodesIterator->valid()) {
113
                if ($nodesIterator->key() === $targetName) {
114
                    break;
115
                }
116
                $nodesIterator->next();
117
            }
118
            $targetName = null;
119
            if ($nodesIterator->valid()) {
120
                $nodesIterator->next();
121
                if ($nodesIterator->valid()) {
122
                    $targetName = $nodesIterator->key();
123
                }
124
            }
125
        }
126
        $parentNode->orderBefore($targetName, PathHelper::getNodeName($dropedAtPath));
127
        $this->session->save();
128
129
        return new Response('', Response::HTTP_NO_CONTENT);
130
    }
131
}
132