Issues (12)

Security Analysis    no request data  

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

  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.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  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.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  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.
  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.
  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.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
  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.
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  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.
  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.
  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.
  Header Injection
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/Twig/CmsPageExtension.php (6 issues)

Labels
Severity
1
<?php
2
3
4
namespace TheCodingMachine\CMS\StaticRegistry\Twig;
5
6
use Barclays\Dao\BaseBlockDao;
0 ignored issues
show
The type Barclays\Dao\BaseBlockDao was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use Barclays\Dao\StaticBlockDao;
0 ignored issues
show
The type Barclays\Dao\StaticBlockDao was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use Barclays\Model\BaseBlock;
0 ignored issues
show
The type Barclays\Model\BaseBlock was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
use Barclays\Model\PageVersion;
0 ignored issues
show
The type Barclays\Model\PageVersion was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
use Barclays\Services\SerializationContext;
0 ignored issues
show
The type Barclays\Services\SerializationContext was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
use TheCodingMachine\CMS\CMSException;
12
use TheCodingMachine\CMS\StaticRegistry\Loaders\Block;
13
use TheCodingMachine\CMS\StaticRegistry\Loaders\Page;
14
use TheCodingMachine\CMS\StaticRegistry\Registry\BlockRegistry;
15
use TheCodingMachine\CMS\StaticRegistry\Registry\PageRegistry;
16
use TheCodingMachine\TDBM\UncheckedOrderBy;
0 ignored issues
show
The type TheCodingMachine\TDBM\UncheckedOrderBy was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
17
18
class CmsPageExtension extends \Twig_Extension
19
{
20
    /**
21
     * @var PageRegistry
22
     */
23
    private $pageRegistry;
24
    /**
25
     * @var BlockRegistry
26
     */
27
    private $blockRegistry;
28
    /**
29
     * @var string
30
     */
31
    private $rootUrl;
32
33
    public function __construct(PageRegistry $pageRegistry, BlockRegistry $blockRegistry, string $rootUrl)
34
    {
35
        $this->pageRegistry = $pageRegistry;
36
        $this->blockRegistry = $blockRegistry;
37
        $this->rootUrl = '/'.trim($rootUrl, '/').'/';
38
        if ($this->rootUrl === '//') {
39
            $this->rootUrl = '/';
40
        }
41
    }
42
43
    /**
44
     * Returns a list of functions to add to the existing list.
45
     *
46
     * @return \Twig_Function[]
47
     */
48
    public function getFunctions()
49
    {
50
        return [
51
            new \Twig_Function('cmsBlocksById', [$this, 'getCmsBlocksById']),
52
            new \Twig_Function('cmsPagesByTag', [$this, 'getCmsPagesByTag']),
53
            new \Twig_Function('cmsBlocksByTag', [$this, 'getCmsBlocksByTag']),
54
            new \Twig_Function('cmsPageByUrl', [$this, 'getCmsPageByUrl']),
55
            new \Twig_Function('url', [$this, 'getUrl']),
56
        ];
57
    }
58
59
    /**
60
     * @return Block[]
61
     */
62
    public function getCmsBlocksById(string $blockId): array
63
    {
64
        $blocks = $this->blockRegistry->getBlocks($blockId);
65
66
        return $blocks;
67
    }
68
69
    /**
70
     * @param string $tag
71
     * @param null|string $domain
72
     * @param string $orderBy One of the properties of the context. For instance, if you set this to 'date', it means you should add a "date" key to your context it you want to sort upon it.
73
     * @param string $direction
74
     * @param int|null $limit
75
     * @param int|null $offset
76
     * @return Page[]
77
     * @throws CMSException
78
     */
79
    public function getCmsPagesByTag(string $tag, ?string $domain = null, ?string $orderBy = null, string $direction = 'desc', int $limit = null, int $offset = null): array
80
    {
81
        if (!\in_array($direction, ['asc', 'desc'], true)) {
82
            throw new CMSException("Error while using getCmsPagesByTag. The fourth parameter (direction) must be either 'asc' or 'desc'.");
83
        }
84
85
        $pages = $this->pageRegistry->findPagesByTag($tag, $domain);
86
87
        if ($orderBy !== null) {
88
            usort($pages, function(Page $page1, Page $page2) use ($orderBy, $direction) {
89
                if ($direction === 'asc') {
90
                    return ($page1->getContext()[$orderBy] ?? null) <=> ($page2->getContext()[$orderBy] ?? null);
91
                } else {
92
                    return ($page2->getContext()[$orderBy] ?? null) <=> ($page1->getContext()[$orderBy] ?? null);
93
                }
94
            });
95
        }
96
97
        if ($limit !== null || $offset !== null) {
98
            $pages = \array_slice($pages, $offset, $limit);
99
        }
100
101
        return $pages;
102
    }
103
104
    /**
105
     * @param string $tag
106
     * @param string $orderBy One of the properties of the context. For instance, if you set this to 'date', it means you should add a "date" key to your context it you want to sort upon it.
107
     * @param string $direction
108
     * @param int|null $limit
109
     * @param int|null $offset
110
     * @return Block[]
111
     * @throws CMSException
112
     */
113
    public function getCmsBlocksByTag(string $tag, ?string $orderBy = null, string $direction = 'desc', int $limit = null, int $offset = null): array
114
    {
115
        if (!\in_array($direction, ['asc', 'desc'], true)) {
116
            throw new CMSException("Error while using getCmsBlocksByTag. The third parameter (direction) must be either 'asc' or 'desc'.");
117
        }
118
119
        $blocks = $this->blockRegistry->findBlocksByTag($tag);
120
121
        if ($orderBy !== null) {
122
            usort($blocks, function(Block $block1, Block $block2) use ($orderBy, $direction) {
123
                if ($direction === 'asc') {
124
                    return ($block1->getContext()[$orderBy] ?? null) <=> ($block2->getContext()[$orderBy] ?? null);
125
                } else {
126
                    return ($block2->getContext()[$orderBy] ?? null) <=> ($block1->getContext()[$orderBy] ?? null);
127
                }
128
            });
129
        }
130
131
        if ($limit !== null || $offset !== null) {
132
            $blocks = \array_slice($blocks, $offset, $limit);
133
        }
134
135
        return $blocks;
136
    }
137
138
    /**
139
     * @return Page
140
     */
141
    public function getCmsPageByUrl(string $url, string $domain = null): Page
142
    {
143
        return $this->pageRegistry->getPage($url, $domain ?: '<any>');
144
    }
145
146
    /**
147
     * Prepends the URL with the "base" url.
148
     *
149
     * @param string|null $url
150
     * @return string|null
151
     */
152
    public function getUrl(string $url = null): ?string
153
    {
154
        if ($url === null) {
155
            return null;
156
        }
157
        $isAbsolute = parse_url($url, PHP_URL_SCHEME) !== null;
158
        if ($isAbsolute) {
159
            return $url;
160
        } else {
161
            return $this->rootUrl.ltrim($url, '/');
162
        }
163
    }
164
}
165