Issues (89)

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.

Twig/Extension/Generic.php (16 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 DoS\ResourceBundle\Twig\Extension;
4
5
use Sylius\Bundle\SettingsBundle\Templating\Helper\SettingsHelper;
6
use Symfony\Component\DependencyInjection\ContainerInterface;
7
use Symfony\Component\PropertyAccess\PropertyAccess;
8
9
class Generic extends \Twig_Extension
10
{
11
    /**
12
     * @var ContainerInterface
13
     */
14
    protected $container;
15
16
    /**
17
     * @var SettingsHelper
18
     */
19
    protected $settingsHelper;
20
21
    public function __construct(ContainerInterface $container)
22
    {
23
        $this->container = $container;
24
        $this->settingsHelper = $container->get('sylius.templating.helper.settings');
25
    }
26
27
    /**
28
     * @inheritdoc
29
     */
30
    public function getGlobals()
31
    {
32
        return array(
33
        );
34
    }
35
36
    /**
37
     * @inheritdoc
38
     */
39
    public function getFunctions()
40
    {
41
        $self = array('is_safe' => array('all'));
42
43
        return array(
44
            new \Twig_SimpleFunction('d', '\Kint::dump', $self),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFunction has been deprecated with message: to be removed in 3.0

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...
45
            new \Twig_SimpleFunction('e', array($this, 'dumpExit'), $self),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFunction has been deprecated with message: to be removed in 3.0

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...
46
            new \Twig_SimpleFunction('is_string', 'is_string'),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFunction has been deprecated with message: to be removed in 3.0

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...
47
            new \Twig_SimpleFunction('ui_random_string', array($this, 'getRandomString'), $self),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFunction has been deprecated with message: to be removed in 3.0

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...
48
            new \Twig_SimpleFunction('ui_percentage', array($this, 'calculatePercent')),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFunction has been deprecated with message: to be removed in 3.0

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...
49
            new \Twig_SimpleFunction('ui_setting', array($this, 'getSettingsParameter')),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFunction has been deprecated with message: to be removed in 3.0

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...
50
            new \Twig_SimpleFunction('ui_settings', array($this->settingsHelper, 'getSettings')),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFunction has been deprecated with message: to be removed in 3.0

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...
51
            new \Twig_SimpleFunction('ui_param', array($this->container, 'getParameter')),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFunction has been deprecated with message: to be removed in 3.0

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...
52
            new \Twig_SimpleFunction('ui_param_has', array($this->container, 'hasParameter')),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFunction has been deprecated with message: to be removed in 3.0

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...
53
            new \Twig_SimpleFunction('ui_has', array($this->container, 'has')),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFunction has been deprecated with message: to be removed in 3.0

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...
54
            new \Twig_SimpleFunction('ui_obfuscated_email', array($this, 'getObfuscatedEmail')),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFunction has been deprecated with message: to be removed in 3.0

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...
55
            new \Twig_SimpleFunction('ui_property', array($this, 'getContextValue')),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFunction has been deprecated with message: to be removed in 3.0

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...
56
        );
57
    }
58
59
    public function getFilters()
60
    {
61
        //$self = array('is_safe' => array('all'));
0 ignored issues
show
Unused Code Comprehensibility introduced by
63% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
62
63
        return array(
64
            new \Twig_SimpleFilter('is_match', array($this, 'match')),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFilter has been deprecated with message: to be removed in 3.0

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...
65
            new \Twig_SimpleFilter('ui_no_space', array($this, 'cleanWhiteSpace')),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFilter has been deprecated with message: to be removed in 3.0

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...
66
        );
67
    }
68
69
    /**
70
     * @param $key
71
     * @param string $default
72
     *
73
     * @return null|mixed
74
     */
75
    public function getSettingsParameter($key, $default = null)
76
    {
77
        list($alias, $key) = explode('.', $key);
78
79
        $settings = $this->container->get('sylius.templating.helper.settings')
80
            ->getSettings($alias)
81
        ;
82
83
        if (array_key_exists($key, $settings)) {
84
            return $settings[$key];
85
        }
86
87
        return $default;
88
    }
89
90
    public function getRandomString($length = 8)
91
    {
92
        $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
93
        $randomString = '';
94
95
        for ($i = 0; $i < $length; $i++) {
96
            $randomString .= $characters[rand(0, strlen($characters) - 1)];
97
        }
98
99
        return $randomString;
100
    }
101
102
    /**
103
     * @param $total
104
     * @param $pie
105
     *
106
     * @return string
107
     */
108
    public function calculatePercent($total, $pie)
109
    {
110
        if (empty($total)) {
111
            return '0%';
112
        }
113
114
        $total = ($pie / $total) * 100;
115
116
        if (is_float($total)) {
117
            return number_format($total, 1).'%';
118
        }
119
120
        return $total.'%';
121
    }
122
123
    /**
124
     * @param $email
125
     *
126
     * @return string
127
     */
128
    public function getObfuscatedEmail($email)
129
    {
130
        if (false !== $pos = strpos($email, '@')) {
131
            $email = '...'.substr($email, $pos);
132
        }
133
134
        return $email;
135
    }
136
137
    /**
138
     * @param $context
139
     * @param $path
140
     *
141
     * @return mixed
142
     */
143
    public function getContextValue($context, $path)
144
    {
145
        $accessor = PropertyAccess::createPropertyAccessor();
146
147
        return $accessor->getValue($context, $path);
148
    }
149
150
    /**
151
     * @param $string
152
     *
153
     * @return string
154
     */
155
    public function cleanWhiteSpace($string)
156
    {
157
        return preg_replace('/ /', '', $string);
158
    }
159
160
    public function match($subject, $pattern)
161
    {
162
        return preg_match($pattern, $subject);
163
    }
164
165
    public function dumpExit($val)
166
    {
167
        \Kint::dump($val);
168
        exit;
0 ignored issues
show
Coding Style Compatibility introduced by
The method dumpExit() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
169
    }
170
171
    /**
172
     * @api
173
     */
174
    public function getName()
175
    {
176
        return 'ui_generic';
177
    }
178
}
179