Issues (1377)

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.

Twig/Extension/HighchartsTwigExtension.php (1 issue)

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
/**
4
 * This file is part of the highcharts-bundle package.
5
 *
6
 * (c) 2017 WEBEWEB
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace WBW\Bundle\HighchartsBundle\Twig\Extension;
13
14
use Twig\Extension\AbstractExtension;
15
use Twig\TwigFunction;
16
use WBW\Bundle\HighchartsBundle\API\HighchartsChart;
17
use WBW\Bundle\HighchartsBundle\API\HighchartsOptions;
18
use WBW\Bundle\HighchartsBundle\Wrapper\HighchartsWrapper;
19
use WBW\Library\Core\Exception\IO\FileNotFoundException;
20
21
/**
22
 * Highcharts Twig extension.
23
 *
24
 * @author webeweb <https://github.com/webeweb/>
25
 * @package WBW\Bundle\HighchartsBundle\Twig\Extension
26
 * @final
27
 */
28
final class HighchartsTwigExtension extends AbstractExtension {
29
30
    /**
31
     * Service name.
32
     *
33
     * @var string
34
     */
35
    const SERVICE_NAME = "webeweb.bundle.highchartsbundle.twig.extension.highcharts";
36
37
    /**
38
     * Directory.
39
     *
40
     * @var string
41
     */
42
    private $directory;
43
44
    /**
45
     * Environment.
46
     *
47
     * @var string
48
     */
49
    private $environment;
50
51
    /**
52
     * Wrapper.
53
     *
54
     * @var HightchartsWrapper
55
     */
56
    private $wrapper;
57
58
    /**
59
     * Constructor.
60
     *
61
     * @param string $directory The directory.
62
     * @param string $environment The environment.
63
     */
64
    public function __construct($directory, $environment) {
65
        $this->directory   = $directory;
66
        $this->environment = $environment;
67
        $this->wrapper     = new HighchartsWrapper();
0 ignored issues
show
Documentation Bug introduced by
It seems like new \WBW\Bundle\Highchar...per\HighchartsWrapper() of type object<WBW\Bundle\Highch...pper\HighchartsWrapper> is incompatible with the declared type object<WBW\Bundle\Highch...ion\HightchartsWrapper> of property $wrapper.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
68
    }
69
70
    /**
71
     * Get the Twig functions.
72
     *
73
     * @return TwigFunction[] Returns the Twig functions.
74
     */
75
    public function getFunctions() {
76
        return [
77
            new TwigFunction('highchartsChart', [$this, 'highchartsChartFunction'], ['is_safe' => ['html']]),
78
            new TwigFunction('highchartsScript', [$this, 'highchartsScriptFunction'], ['is_safe' => ['html']]),
79
            new TwigFunction('highchartsSetOptions', [$this, 'highchartsSetOptionsFunction'], ['is_safe' => ['html']]),
80
        ];
81
    }
82
83
    /**
84
     * Get the resources directory.
85
     *
86
     * @return string Returns the resources directory.
87
     */
88
    private function getResourcesDirectory() {
89
        return $this->directory . "/Resources";
90
    }
91
92
    /**
93
     * Displays an Highcharts.chart().
94
     *
95
     * @param string $selector The selector.
96
     * @param HighchartsChart $chart The chart.
97
     * @return string Returns the Highcharts.chart().
98
     */
99
    public function highchartsChartFunction($selector, HighchartsChart $chart) {
100
101
        // Initialize the output.
102
        $output   = [];
103
        $output[] = "<script type=\"text/javascript\">\n";
104
        $output[] = "Highcharts.chart('" . $selector . "', ";
105
        if ($this->isDevEnvironment()) {
106
            $output[] = $this->wrapper->unwrap(json_encode($chart, JSON_PRETTY_PRINT));
107
        } else {
108
            $output[] = $this->wrapper->unwrap(json_encode($chart));
109
        }
110
        $output[] = ");\n";
111
        $output[] = "</script>";
112
113
        // Return the output.
114
        return implode("", $output);
115
    }
116
117
    /**
118
     * Displays an Highcharts script.
119
     *
120
     * @param string $script The scriptname.
121
     * @param string $subdirectory The sub directory.
122
     * @return string Returns the Highcharts script.
123
     * @throws FileNotFoundException Throws a file not found exception if the script is not found.
124
     */
125
    public function highchartsScriptFunction($script, $subdirectory = "code") {
126
127
        // Initialize the filename.
128
        $filename = implode("/", ["highcharts-5.0.14", $subdirectory, $script . ".js"]);
129
130
        // Initialize and check the filepath.
131
        $filepath = $this->getResourcesDirectory() . "/public/" . $filename;
132
        if (!file_exists($filepath)) {
133
            throw new FileNotFoundException($filename);
134
        }
135
136
        // Return the output.
137
        return "<script src=\"/bundles/highcharts/" . $filename . "\" type=\"text/javascript\"></script>";
138
    }
139
140
    /**
141
     * Displays an Highcharts.setOptions()
142
     *
143
     * @param HighchartsOptions $options The options.
144
     * @return string Returns the Highcharts.setOptions().
145
     */
146
    public function highchartsSetOptionsFunction(HighchartsOptions $options) {
147
148
        // Initialize the output.
149
        $output   = [];
150
        $output[] = "<script type=\"text/javascript\">\n";
151
        $output[] = "Highcharts.setOptions(";
152
        if ($this->isDevEnvironment()) {
153
            $output[] = $this->wrapper->unwrap(json_encode($options, JSON_PRETTY_PRINT));
154
        } else {
155
            $output[] = $this->wrapper->unwrap(json_encode($options));
156
        }
157
        $output[] = ");\n";
158
        $output[] = "</script>";
159
160
        // Return the output.
161
        return implode("", $output);
162
    }
163
164
    /**
165
     * Determines if the environement is dev.
166
     *
167
     * @return boolean Returns true in case of success, false otherwise.
168
     */
169
    private function isDevEnvironment() {
170
        return $this->environment === "dev";
171
    }
172
173
}
174