Issues (1704)

Branch: master

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.

Bundle/BlogBundle/Manager/ArticleManager.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
namespace Victoire\Bundle\BlogBundle\Manager;
4
5
use Doctrine\ORM\EntityManager;
6
use Victoire\Bundle\BlogBundle\Entity\Article;
7
use Victoire\Bundle\BlogBundle\Entity\Tag;
8
use Victoire\Bundle\BusinessPageBundle\Builder\BusinessPageBuilder;
9
use Victoire\Bundle\BusinessPageBundle\Entity\BusinessPage;
10
use Victoire\Bundle\BusinessPageBundle\Transformer\VirtualToBusinessPageTransformer;
11
use Victoire\Bundle\CoreBundle\Entity\View;
12
use Victoire\Bundle\PageBundle\Entity\PageStatus;
13
use Victoire\Bundle\PageBundle\Helper\PageHelper;
14
use Victoire\Bundle\UserBundle\Model\User;
15
use Victoire\Bundle\ViewReferenceBundle\Connector\ViewReferenceRepository;
16
use Victoire\Bundle\ViewReferenceBundle\Exception\ViewReferenceNotFoundException;
17
18
/**
19
 * Article Manager.
20
 *
21
 * ref. victoire_blog.manager.article.
22
 */
23
class ArticleManager
24
{
25
    private $entityManager;
26
    private $businessPageBuilder;
27
    private $virtualToBusinessPageTransformer;
28
    private $pageHelper;
29
    private $viewReferenceRepo;
30
31
    public function __construct(
0 ignored issues
show
Missing function doc comment
Loading history...
32
        EntityManager $entityManager,
0 ignored issues
show
You have injected the EntityManager via parameter $entityManager. This is generally not recommended as it might get closed and become unusable. Instead, it is recommended to inject the ManagerRegistry and retrieve the EntityManager via getManager() each time you need it.

The EntityManager might become unusable for example if a transaction is rolled back and it gets closed. Let’s assume that somewhere in your application, or in a third-party library, there is code such as the following:

function someFunction(ManagerRegistry $registry) {
    $em = $registry->getManager();
    $em->getConnection()->beginTransaction();
    try {
        // Do something.
        $em->getConnection()->commit();
    } catch (\Exception $ex) {
        $em->getConnection()->rollback();
        $em->close();

        throw $ex;
    }
}

If that code throws an exception and the EntityManager is closed. Any other code which depends on the same instance of the EntityManager during this request will fail.

On the other hand, if you instead inject the ManagerRegistry, the getManager() method guarantees that you will always get a usable manager instance.

Loading history...
33
        BusinessPageBuilder $businessPageBuilder,
34
        VirtualToBusinessPageTransformer $virtualToBusinessPageTransformer,
35
        PageHelper $pageHelper,
36
        ViewReferenceRepository $viewReferenceRepo
37
    ) {
38
        $this->entityManager = $entityManager;
39
        $this->businessPageBuilder = $businessPageBuilder;
40
        $this->virtualToBusinessPageTransformer = $virtualToBusinessPageTransformer;
41
        $this->pageHelper = $pageHelper;
42
        $this->viewReferenceRepo = $viewReferenceRepo;
43
    }
44
45
    /**
46
     * Create Article with its author, tags.
47
     * Create BusinessPage for this Article.
48
     *
49
     * @param Article $article
50
     * @param User    $author
51
     *
52
     * @return BusinessPage
53
     */
54
    public function create(Article $article, User $author)
55
    {
56
        $article->setAuthor($author);
57
58
        /** @var Tag[] $tags */
59
        $tags = $article->getTags();
60
        if (is_array($tags)) {
61
            foreach ($tags as $tag) {
62
                $tag->setBlog($article->getBlog());
63
                $this->entityManager->persist($tag);
64
            }
65
        }
66
67
        //Article has to be persisted before BusinessPage generation
68
        $this->entityManager->persist($article);
69
        $this->entityManager->flush();
70
71
        $page = $this->businessPageBuilder->generateEntityPageFromTemplate(
72
            $article->getTemplate(),
73
            $article,
74
            $this->entityManager
75
        );
76
77
        //Transform VBP into BP
78
        $this->virtualToBusinessPageTransformer->transform($page);
79
        $page->setParent($article->getBlog());
80
81
        $this->entityManager->persist($page);
82
        $this->entityManager->flush();
83
84
        return $page;
85
    }
86
87
    /**
88
     * Update Blog Article settings.
89
     *
90
     * @param Article $article
91
     *
92
     * @throws ViewReferenceNotFoundException
93
     *
94
     * @return View
95
     */
96
    public function updateSettings(Article $article)
97
    {
98
        //Update Tags
99
        /** @var Tag[] $tags */
100
        $tags = $article->getTags();
101
        if (is_array($tags)) {
102
            foreach ($tags as $tag) {
103
                $tag->setBlog($article->getBlog());
104
                $this->entityManager->persist($tag);
105
            }
106
        }
107
108
        //Update BusinessPage
109
        $businessPage = $this->pageHelper->findPageByParameters([
110
            'viewId'   => $article->getTemplate()->getId(),
111
            'entityId' => $article->getId(),
112
        ]);
113
        $template = $article->getTemplate();
114
        $businessPage->setTemplate($template);
115
116
        //Update Page
117
        $page = $this->pageHelper->findPageByParameters([
118
            'viewId'   => $template->getId(),
119
            'entityId' => $article->getId(),
120
        ]);
121
        $page->setName($article->getName());
122
        $page->setSlug($article->getSlug());
123
        $page->setStatus($article->getStatus());
124
125
        $this->entityManager->flush();
126
127
        //Set ViewReference for Page redirection
128
        $viewReference = $this->viewReferenceRepo->getOneReferenceByParameters(
129
            ['viewId' => $page->getId()]
130
        );
131
        $page->setReference($viewReference);
132
133
        return $page;
134
    }
135
136
    /**
137
     * Delete a given Article.
138
     *
139
     * @param Article $article
140
     */
141
    public function delete(Article $article)
142
    {
143
        $bep = $this->pageHelper->findPageByParameters(
144
            [
145
                'templateId' => $article->getTemplate()->getId(),
146
                'entityId'   => $article->getId(),
147
            ]
148
        );
149
        $this->entityManager->remove($bep);
0 ignored issues
show
It seems like $bep defined by $this->pageHelper->findP... => $article->getId())) on line 143 can be null; however, Doctrine\ORM\EntityManager::remove() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
150
151
        $article->setVisibleOnFront(0);
152
        $article->setDeletedAt(new \DateTime());
153
        $article->setStatus(PageStatus::DELETED);
154
155
        $this->entityManager->flush();
156
    }
157
}
158