Issues (73)

Security Analysis    no request data  

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.

code/controllers/SlackStatusController.php (7 issues)

1
<?php
2
3
4
/**
5
 * Class SlackStatusController
6
 *
7
 */
8
class SlackStatusController extends Controller
0 ignored issues
show
The type Controller was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
{
10
    private static $allowed_actions = [
11
        'usercount',
12
        'badge'
13
    ];
14
15
    /**
16
     * @return int
17
     * @throws ValidationException
18
     */
19
    public function usercount()
20
    {
21
        /** @var SiteConfig $config */
22
        $config = SiteConfig::current_site_config();
0 ignored issues
show
The type SiteConfig was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
23
        // Break if there is a configuration error
24
        if (!$config->SlackURL || !$config->SlackToken || !$config->SlackChannel) {
25
            return '';
0 ignored issues
show
Bug Best Practice introduced by
The expression return '' returns the type string which is incompatible with the documented return type integer.
Loading history...
26
        }
27
        $params = $this->getRequestParams($config);
28
29
        return $this->getStatus($config, $params);
30
    }
31
32
    /**
33
     * @return SS_HTTPResponse
34
     * @throws ValidationException
35
     */
36
    public function badge()
37
    {
38
        $config = SiteConfig::current_site_config();
39
        $params = $this->getRequestParams($config);
40
        $count = $this->getStatus($config, $params);
41
        list($width, $pos) = $this->getSVGSettings($count);
42
43
        $body = $this->renderWith('SVGTemplate', ['Count' => $count, 'Width' => $width, 'Pos' => $pos]);
44
        $response = new SS_HTTPResponse($body);
0 ignored issues
show
The type SS_HTTPResponse was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
45
        $response->addHeader('Content-Type', 'image/svg+xml');
46
47
        return $response;
48
    }
49
50
51
    protected function getRequestParams($config)
52
    {
53
        return [
54
            'token'   => $config->SlackToken,
55
            'type'    => 'post',
56
            'channel' => $config->SlackChannel,
57
            'scope'   => 'identify,read,post,client',
58
        ];
59
    }
60
61
    /**
62
     * @param SiteConfig $config
63
     * @param array $params
64
     * @return int
65
     * @throws ValidationException
66
     */
67
    public function getStatus($config, $params = [])
68
    {
69
        /** @var SlackUserCount $count */
70
        $count = SlackUserCount::get()->first();
71
        // To limit the amount of API requests, only update the count
72
        // once every 3 hours
73
        if ($count) {
74
            $dateTime = SS_Datetime::create();
0 ignored issues
show
The type SS_Datetime was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
75
            $dateTime->setValue($count->LastEdited);
76
            $diff = explode(' ', $dateTime->TimeDiffIn('hours'));
77
            if ($diff[0] < 3) {
78
                return $count->UserCount;
79
            }
80
        } else {
81
            $count = SlackUserCount::create();
82
        }
83
84
        return $this->getSlackCount($config, $params, $count);
85
    }
86
87
    /**
88
     * @param SiteConfig $config
89
     * @param array $params
90
     * @param SlackUserCount $count
91
     * @return int
92
     * @throws \ValidationException
93
     */
94
    protected function getSlackCount($config, $params, $count)
95
    {
96
        list($url, $service) = $this->getRestfulService($config);
97
98
        $response = $service->request($url, 'POST', $params);
99
        $result = Convert::json2array($response->getBody());
0 ignored issues
show
The type Convert was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
100
101
        return $this->validateResponse($count, $result);
102
    }
103
104
    /**
105
     * @param $count
106
     * @return array
107
     */
108
    public function getSVGSettings($count)
109
    {
110
        if ($count < 100) {
111
            $width = 25;
112
            $pos = 60;
113
        } elseif ($count < 1000) {
114
            $width = 35;
115
            $pos = 65;
116
        } else {
117
            $width = 45;
118
            $pos = 70;
119
        }
120
121
        return [$width, $pos];
122
    }
123
124
    /**
125
     * @param $config
126
     * @return array
127
     */
128
    public function getRestfulService($config)
129
    {
130
        $now = time();
131
        $baseURL = $config->SlackURL;
132
        $baseURL = (substr($baseURL, -1) === '/') ? $baseURL : $baseURL . '/';
133
        $url = 'api/channels.info?t=' . $now;
134
135
        /** @var RestfulService $service with an _uncached_ response */
136
        $service = RestfulService::create($baseURL, 0);
0 ignored issues
show
The type RestfulService was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
137
138
        return array($url, $service);
139
    }
140
141
    /**
142
     * @param SlackUserCount $count
143
     * @param array $result
144
     * @return int
145
     */
146
    public function validateResponse($count, $result)
147
    {
148
        if (isset($result['ok']) && $result['ok']) {
149
            $userCount = count($result['channel']['members']);
150
            $count->UserCount = $userCount;
151
            $count->write();
152
153
            return $userCount;
154
        }
155
156
        return 0;
157
    }
158
}
159