Issues (222)

Security Analysis    not enabled

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/DependencyInjection/Modules/Common.php (3 issues)

Labels
Severity
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * Copyright (C) 2020-2025 Iain Cambridge
7
 *
8
 * This program is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE as published by
10
 * the Free Software Foundation, either version 2.1 of the License, or
11
 * (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU Lesser General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20
 */
21
22
namespace Parthenon\DependencyInjection\Modules;
23
24
use DocRaptor\Doc;
25
use Mpdf\Mpdf;
26
use Parthenon\Common\Exception\MissingDependencyException;
27
use Parthenon\Common\Exception\ParameterNotSetException;
28
use Parthenon\Common\RequestHandler\RequestHandlerInterface;
29
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
30
use Symfony\Component\Config\Definition\Builder\NodeBuilder;
31
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
32
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
33
use Symfony\Component\Config\FileLocator;
34
use Symfony\Component\DependencyInjection\ContainerBuilder;
35
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
36
37
final class Common implements ModuleConfigurationInterface
38
{
39
    public function addConfig(NodeBuilder $nodeBuilder): void
40
    {
41
        $nodeBuilder->arrayNode('common')
42
            ->children()
43
                ->scalarNode('site_url')->end()
44
                ->arrayNode('elasticsearch')
0 ignored issues
show
The method arrayNode() does not exist on Symfony\Component\Config...der\NodeParentInterface. It seems like you code against a sub-type of Symfony\Component\Config...der\NodeParentInterface such as Symfony\Component\Config...ion\Builder\NodeBuilder. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

44
                ->/** @scrutinizer ignore-call */ arrayNode('elasticsearch')
Loading history...
45
                    ->children()
46
                        ->arrayNode('hosts')->scalarPrototype()->end()->end()
47
                        ->scalarNode('connection_type')->end()
48
                        ->scalarNode('cloud_id')->end()
49
                        ->scalarNode('api_key')->end()
50
                        ->scalarNode('api_id')->end()
51
                        ->scalarNode('basic_username')->end()
52
                        ->scalarNode('basic_password')->end()
53
                    ->end()
54
                ->end()
55
                ->arrayNode('pdf')
56
                    ->children()
57
                        ->scalarNode('generator')->end()
58
                        ->arrayNode('mpdf')
59
                            ->children()
60
                                ->scalarNode('tmp_dir')->defaultValue('/tmp')->end()
61
                            ->end()
62
                        ->end()
63
                        ->arrayNode('docraptor')
64
                            ->children()
65
                                ->scalarNode('api_key')->end()
66
                            ->end()
67
                        ->end()
68
                        ->arrayNode('wkhtmltopdf')
69
                            ->children()
70
                                ->scalarNode('bin')->defaultValue('/usr/bin/wkhtmltopdf')->end()
71
                            ->end()
72
                        ->end()
73
                    ->end()
74
                ->end()
75
            ->end()
76
            ->fixXmlConfig('uploaders')
77
            ->append($this->getUploadersNode())
78
        ->end();
79
    }
80
81
    public function handleDefaultParameters(ContainerBuilder $container): void
82
    {
83
        $container->setParameter('parthenon_common_site_url', 'http://localhost');
84
        $container->setParameter('parthenon_common_pdf_wkhtmltopdf_bin', '');
85
        $container->setParameter('parthenon_common_pdf_docraptor_api_key', '');
86
        $container->setParameter('parthenon_common_uploaders', []);
87
    }
88
89
    public function handleConfiguration(array $config, ContainerBuilder $container): void
90
    {
91
        $container->registerForAutoconfiguration(RequestHandlerInterface::class)->addTag('parthenon.common.request_handler');
92
93
        $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../../Resources/config'));
94
        $loader->load('services/common.xml');
95
96
        if (!isset($config['common'])) {
97
            return;
98
        }
99
100
        $container->setParameter('parthenon_common_site_url', $config['common']['site_url'] ?? '');
101
102
        $config = $this->configureUploader($config, $container);
103
        $config = $this->configurePdf($config, $container, $loader);
104
105
        $this->configureElasticsearch($config, $container);
106
    }
107
108
    private function getUploadersNode(): NodeDefinition
109
    {
110
        $treeBuilder = new TreeBuilder('uploader');
111
        $node = $treeBuilder->getRootNode();
112
113
        /** @var ArrayNodeDefinition $uploaderNode */
114
        $uploaderNode = $node
115
            ->requiresAtLeastOneElement()
0 ignored issues
show
The method requiresAtLeastOneElement() does not exist on Symfony\Component\Config...\Builder\NodeDefinition. It seems like you code against a sub-type of Symfony\Component\Config...\Builder\NodeDefinition such as Symfony\Component\Config...der\ArrayNodeDefinition. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

115
            ->/** @scrutinizer ignore-call */ requiresAtLeastOneElement()
Loading history...
116
            ->useAttributeAsKey('name')
117
            ->prototype('array');
118
119
        $uploaderNode
120
            ->children()
121
                ->scalarNode('provider')->end()
122
                ->scalarNode('naming_strategy')->end()
0 ignored issues
show
The method scalarNode() does not exist on Symfony\Component\Config...der\NodeParentInterface. It seems like you code against a sub-type of Symfony\Component\Config...der\NodeParentInterface such as Symfony\Component\Config...ion\Builder\NodeBuilder. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

122
                ->/** @scrutinizer ignore-call */ scalarNode('naming_strategy')->end()
Loading history...
123
                ->scalarNode('url')->end()
124
                ->arrayNode('local')
125
                    ->children()
126
                        ->scalarNode('path')->end()
127
                    ->end()
128
                ->end()
129
                ->arrayNode('s3')
130
                    ->children()
131
                        ->scalarNode('key')->end()
132
                        ->scalarNode('secret')->end()
133
                        ->scalarNode('region')->end()
134
                        ->scalarNode('endpoint')->end()
135
                        ->scalarNode('bucket_name')->end()
136
                        ->scalarNode('version')->end()
137
                        ->scalarNode('visibility')->end()
138
                    ->end()
139
                ->end()
140
            ->end();
141
142
        return $node;
143
    }
144
145
    private function configureElasticsearch(array $config, ContainerBuilder $container): void
146
    {
147
        if (isset($config['common']['elasticsearch'])) {
148
            $elasticsearchConfig = $config['common']['elasticsearch'];
149
150
            $definition = $container->getDefinition('parthenon.common.elasticsearch.config');
151
152
            if (isset($elasticsearchConfig['connection_type'])) {
153
                $definition->addMethodCall('setConnectionType', [$elasticsearchConfig['connection_type']]);
154
            }
155
156
            if (isset($elasticsearchConfig['hosts'])) {
157
                $definition->addMethodCall('setHosts', [$elasticsearchConfig['hosts']]);
158
            }
159
160
            if (isset($elasticsearchConfig['api_id'])) {
161
                $definition->addMethodCall('setApiId', [$elasticsearchConfig['api_id']]);
162
            }
163
164
            if (isset($elasticsearchConfig['api_key'])) {
165
                $definition->addMethodCall('setApiKey', [$elasticsearchConfig['api_key']]);
166
            }
167
168
            if (isset($elasticsearchConfig['basic_username'])) {
169
                $definition->addMethodCall('setBasicUsername', [$elasticsearchConfig['basic_username']]);
170
            }
171
172
            if (isset($elasticsearchConfig['basic_password'])) {
173
                $definition->addMethodCall('setBasicPassword', [$elasticsearchConfig['basic_password']]);
174
            }
175
            $container->setDefinition('parthenon.common.elasticsearch.config', $definition);
176
        }
177
    }
178
179
    /**
180
     * @throws ParameterNotSetException
181
     */
182
    private function configurePdf(array $config, ContainerBuilder $container, XmlFileLoader $loader): array
183
    {
184
        if (isset($config['common']['pdf']['generator']) && 'docraptor' === $config['common']['pdf']['generator']) {
185
            if (!class_exists(Doc::class)) {
186
                throw new MissingDependencyException('To use docraptor you need to have the docraptor/docraptor package installed. Do composer require docraptor/docraptor.');
187
            }
188
189
            if (!isset($config['common']['pdf']['docraptor']) || !$config['common']['pdf']['docraptor']['api_key']) {
190
                throw new ParameterNotSetException('When pdf generator is docraptor you need to set parthenon.common.pdf.docraptor.api_key');
191
            }
192
            $container->setParameter('parthenon_common_pdf_docraptor_api_key', $config['common']['pdf']['docraptor']['api_key']);
193
194
            $loader->load('services/common/pdf/docraptor.xml');
195
        } elseif (isset($config['common']['pdf']['generator']) && 'mpdf' === $config['common']['pdf']['generator']) {
196
            if (!class_exists(Mpdf::class)) {
197
                throw new MissingDependencyException('To use mpdf you need to have the mpdf/mpdf package installed. Do composer require mpdf/mpdf.');
198
            }
199
200
            if (!isset($config['common']['pdf']['mpdf'])) {
201
                $dir = '/tmp/';
202
            } else {
203
                $dir = $config['common']['pdf']['mpdf']['tmp_dir'] ?? '/tmp';
204
            }
205
            $container->setParameter('parthenon.common.pdf.mpdf.tmp_dir', $dir);
206
            $loader->load('services/common/pdf/mpdf.xml');
207
        } elseif (isset($config['common']['pdf']['generator']) && 'wkhtmltopdf' === $config['common']['pdf']['generator']) {
208
            if (!class_exists(\Knp\Snappy\Pdf::class)) {
209
                throw new MissingDependencyException('To use wkhtmltopdf you need to have the knplabs/knp-snappy. Do composer require knplabs/knp-snappy.');
210
            }
211
212
            $container->setParameter('parthenon_common_pdf_wkhtmltopdf_bin', $config['common']['pdf']['wkhtmltopdf']['bin']);
213
            $loader->load('services/common/pdf/wkhtmltopdf.xml');
214
        }
215
216
        return $config;
217
    }
218
219
    private function configureUploader(array $config, ContainerBuilder $container): array
220
    {
221
        if (isset($config['common']['uploader']) && is_array($config['common']['uploader'])) {
222
            $container->setParameter('parthenon_common_uploaders', $config['common']['uploader']);
223
        }
224
225
        return $config;
226
    }
227
}
228