Issues (88)

Security Analysis    no request data  

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/Configuration.php (4 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 Groundskeeper;
4
5
use Groundskeeper\Tokens\Element;
6
use Groundskeeper\Tokens\Token;
7
use Symfony\Component\OptionsResolver\Options;
8
use Symfony\Component\OptionsResolver\OptionsResolver;
9
10
class Configuration
11
{
12
    const CLEAN_STRATEGY_NONE       = 'none';
13
    const CLEAN_STRATEGY_LENIENT    = 'lenient';
14
    const CLEAN_STRATEGY_STANDARD   = 'standard';
15
    const CLEAN_STRATEGY_AGGRESSIVE = 'aggressive';
16
17
    const OUTPUT_COMPACT = 'compact';
18
    const OUTPUT_PRETTY  = 'pretty';
19
20
    /** @var array */
21
    private $options;
22
23
    /**
24
     * Constructor
25
     */
26 215
    public function __construct(array $options = array())
27
    {
28 215
        $resolver = new OptionsResolver();
29 215
        $this->configureOptions($resolver);
30
31 215
        $this->options = $resolver->resolve($options);
32 206
        $this->setDependentOptions();
33 206
    }
34
35 174
    public function has(string $key) : bool
36
    {
37 174
        return array_key_exists($key, $this->options);
38
    }
39
40 174
    public function get(string $key)
41
    {
42 174
        if (!$this->has($key)) {
43 1
            throw new \InvalidArgumentException('Invalid configuration key: ' . $key);
44
        }
45
46 174
        return $this->options[$key];
47
    }
48
49 6 View Code Duplication
    public function isAllowedElement($element)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
50
    {
51 6
        if ($element instanceof Element) {
52 1
            $element = $element->getName();
53
        }
54
55 6
        $disallowedElementArray = explode(',', $this->options['element-blacklist']);
56
57 6
        return !in_array($element, $disallowedElementArray);
58
    }
59
60 11 View Code Duplication
    public function isAllowedType($type)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
61
    {
62 11
        if ($type instanceof Token) {
63 1
            $type = $type->getType();
64
        }
65
66 11
        $disallowedTypeArray = explode(',', $this->options['type-blacklist']);
67
68 11
        return !in_array($type, $disallowedTypeArray);
69
    }
70
71 215
    protected function configureOptions(OptionsResolver $resolver)
72
    {
73
        // Set default options.
74 215
        $resolver->setDefaults(array(
75 215
            'clean-strategy' => self::CLEAN_STRATEGY_STANDARD,
76 215
            'element-blacklist' => '',
77 215
            'indent-spaces' => 4,
78 215
            'output' => self::OUTPUT_COMPACT,
79 215
            'type-blacklist' => Token::CDATA . ',' . Token::COMMENT
80
        ));
81
82
        // Validation
83
84
        // clean-strategy
85 215
        $resolver->setAllowedTypes('clean-strategy', 'string');
86 215
        $resolver->setAllowedValues(
87 215
            'clean-strategy',
88
            array(
89 215
                self::CLEAN_STRATEGY_NONE,
90 215
                self::CLEAN_STRATEGY_LENIENT,
91 215
                self::CLEAN_STRATEGY_STANDARD,
92 215
                self::CLEAN_STRATEGY_AGGRESSIVE
93
            )
94
        );
95
96
        // element-blacklist
97 215
        $resolver->setAllowedTypes('element-blacklist', 'string');
98 215
        $resolver->setNormalizer(
99 215
            'element-blacklist',
100 215 View Code Duplication
            function (Options $options, $value) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
101 212
                $valueArray = explode(',', $value);
102 212
                $formattedValueArray = array();
103 212
                foreach ($valueArray as $data) {
104 212
                    $formattedValueArray[] = trim(strtolower($data));
105
                }
106
107 212
                return implode(',', $formattedValueArray);
108 215
            }
109
        );
110
111
        // indent-spaces
112 215
        $resolver->setAllowedTypes('indent-spaces', 'int');
113 215
        $resolver->setAllowedValues('indent-spaces', function ($value) {
114 211
                return $value >= 0;
115 215
            }
116
        );
117
118
        // output
119 215
        $resolver->setAllowedTypes('output', 'string');
120 215
        $resolver->setAllowedValues(
121 215
            'output',
122 215
            array(self::OUTPUT_COMPACT, self::OUTPUT_PRETTY)
123
        );
124
125
        // type-blacklist
126 215
        $resolver->setAllowedTypes('type-blacklist', 'string');
127 215
        $resolver->setAllowedValues(
128 215
            'type-blacklist',
129 215
            function ($value) {
130 207
                if ($value == '') {
131 143
                    return true;
132
                }
133
134
                $acceptedValues = array(
135 64
                    Token::CDATA,
136 64
                    Token::COMMENT,
137 64
                    Token::DOCTYPE,
138 64
                    Token::ELEMENT,
139 64
                    Token::PHP,
140 64
                    Token::TEXT
141
                );
142 64
                $valueArray = explode(',', $value);
143 64
                foreach ($valueArray as $val) {
144 64
                    if (array_search(trim(strtolower($val)), $acceptedValues) === false) {
145 64
                        return false;
146
                    }
147
                }
148
149 63
                return true;
150 215
            }
151
        );
152 215
        $resolver->setNormalizer(
153 215
            'type-blacklist',
154 215 View Code Duplication
            function (Options $options, $value) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
155 206
                $valueArray = explode(',', $value);
156 206
                $formattedValueArray = array();
157 206
                foreach ($valueArray as $data) {
158 206
                    $formattedValueArray[] = trim(strtolower($data));
159
                }
160
161 206
                return implode(',', $formattedValueArray);
162 215
            }
163
        );
164 215
    }
165
166 206
    protected function setDependentOptions()
167
    {
168 206
        if ($this->options['output'] === self::OUTPUT_COMPACT) {
169 203
            $this->options['indent-spaces'] = 0;
170
        }
171 206
    }
172
}
173