Issues (14)

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.

code/PiwikExtension.php (12 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
class PiwikExtension extends Extension
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
4
{
5
6
    /**
7
     * @var string the url to the server, without protocol and trailing slash, e.g. //piwik.foo.com/
8
     */
9
    private static $piwik_server = '//piwik.foo.com/';
0 ignored issues
show
The property $piwik_server is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
10
11
    /**
12
     * @var int the piwik site id
13
     */
14
    private static $piwik_site_id = 0;
0 ignored issues
show
The property $piwik_site_id is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
15
16
    /**
17
     * @var bool Do you want tracking code in dev environments?
18
     */
19
    private static $show_on_dev = false;
0 ignored issues
show
The property $show_on_dev is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
20
21
    /**
22
     * @var bool do you want tracking code in test environments?
23
     */
24
    private static $show_on_test = false;
0 ignored issues
show
The property $show_on_test is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
25
26
    /**
27
     * @var bool we want tracking code in live environments
28
     */
29
    private static $show_on_live = true;
0 ignored issues
show
The property $show_on_live is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
30
31
    /**
32
     * @var bool include tracking code on contentcontrollerInit
33
     */
34
    private static $auto_include = true;
0 ignored issues
show
The property $auto_include is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
35
36
    /**
37
     * @var bool include tracking code automatically in backend, subclasses of LeftAndMain
38
     */
39
    private static $include_in_backend = false;
0 ignored issues
show
The property $include_in_backend is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
40
41
    private static $excluded_controllers = array(
0 ignored issues
show
The property $excluded_controllers is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
42
        'DevelopmentAdmin',
43
        'DevBuildController',
44
        'DatabaseAdmin'
45
    );
46
47
    /**
48
     * includes the piwik tracking code when ContentController initializes...
49
     * @todo: get it working ;)
50
     */
51
    public function onAfterInit(&$controller)
0 ignored issues
show
The parameter $controller is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
52
    {
53
        if ($this->autoInclude() && $js = $this->getPiwik(false)) {
54
            Requirements::customScript($js, 'piwiktrackingcode');
55
        }
56
    }
57
58
    /**
59
     * generates piwik tracking code out of config vars and Piwik.ss template
60
     * @param $wrap wrap inside <script> tags, e.g. for templates
61
     */
62
    public function getPiwik($wrap = true)
63
    {
64
        if (Director::isDev() && !Config::inst()->get('PiwikExtension', 'show_on_dev')) {
65
            return false;
66
        }
67
        if (Director::isTest() && !Config::inst()->get('PiwikExtension', 'show_on_test')) {
68
            return false;
69
        }
70
        if (Director::isLive() && !Config::inst()->get('PiwikExtension', 'show_on_live')) {
71
            return false;
72
        }
73
74
        //used for overwriting defaults in SiteConfig, e.g. for different SiteIDs in a Subsite installation
75
        $currentSiteConfig = Controller::curr()->hasMethod('getSiteConfig')
76
            ? Controller::curr()->getSiteConfig()
0 ignored issues
show
The method getSiteConfig() does not exist on Controller. Did you maybe mean config()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
77
            : SiteConfig::current_site_config();
78
79
80
        $data = array(
81
            'WrapInJsTags' => $wrap,
82
            'URL' => Config::inst()->get('PiwikExtension', 'piwik_server'),
83
            'SiteID' => Config::inst()->get('PiwikExtension', 'piwik_site_id'),
84
            'SiteConfig' => $currentSiteConfig
85
        );
86
87
        return ArrayData::create($data)->renderWith(array('Piwik'));
88
    }
89
90
    /**
91
     * Helper function to define if tracking code should be included automatically
92
     * @return bool
93
     */
94
    public function autoInclude()
95
    {
96
        if (! Config::inst()->get('PiwikExtension', 'auto_include')) {
97
            return false;
98
        }
99
100
        if (Director::is_cli()) {
101
            return false;
102
        }
103
104
        //don't include on dev/build etc...
105
        if ($this->isBlockedController()) {
106
            return false;
107
        }
108
109
        if ($this->isBackend() && !Config::inst()->get('PiwikExtension', 'include_in_backend')) {
0 ignored issues
show
This if statement, and the following return statement can be replaced with return !($this->isBacken...'include_in_backend'));.
Loading history...
110
            return false;
111
        }
112
113
        return true;
114
    }
115
116
117
    /**
118
     * @return bool is the extended controller an instance of LeftAndMain
119
     */
120
    public function isBackend()
121
    {
122
        return Controller::curr() instanceof LeftAndMain;
123
    }
124
125
    /**
126
     * Checks if the current controller is in a list of blocked controllers (e.g. dev/build)
127
     *
128
     * @return mixed
129
     */
130
    public function isBlockedController()
131
    {
132
        return max(array_map(
133
            function($name) {
134
                return Controller::curr() instanceof $name;
135
            },
136
            Config::inst()->get('PiwikExtension', 'excluded_controllers')
137
        ));
138
    }
139
}
140