GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Issues (2)

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.

src/ExternalURLField.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
namespace BurnBright\ExternalURLField;
4
5
use SilverStripe\Forms\TextField;
6
7
/**
8
 * ExternalURLField
9
 *
10
 * Form field for entering, saving, validating external urls.
11
 */
12
class ExternalURLField extends TextField
13
{
14
    /**
15
     * Default configuration
16
     *
17
     * URL validation regular expression was sourced from
18
     * @see https://gist.github.com/dperini/729294
19
     * @var array
20
     */
21
    private static $default_config = array(
22
        'defaultparts' => array(
23
            'scheme' => 'http'
24
        ),
25
        'removeparts' => array(
26
            'scheme' => false,
27
            'user' => true,
28
            'pass' => true,
29
            'host' => false,
30
            'port' => false,
31
            'path' => false,
32
            'query' => false,
33
            'fragment' => false
34
        ),
35
        'html5validation' => true,
36
        'validregex' => '%^(?:(?:https?|ftp)://)(?:\S+(?::\S*)?@|\d{1,3}(?:\.\d{1,3}){3}|(?:(?:[a-z\d\x{00a1}-\x{ffff}]+-?)*[a-z\d\x{00a1}-\x{ffff}]+)(?:\.(?:[a-z\d\x{00a1}-\x{ffff}]+-?)*[a-z\d\x{00a1}-\x{ffff}]+)*(?:\.[a-z\x{00a1}-\x{ffff}]{2,6}))(?::\d+)?(?:[^\s]*)?$%iu'
37
    );
38
39
    /**
40
     * @var array
41
     */
42
    protected $config;
43
44 4
    public function __construct($name, $title = null, $value = null)
45
    {
46 4
        $this->config = $this->config()->default_config;
47
48 4
        parent::__construct($name, $title, $value);
49 4
    }
50
51
    public function Type()
52
    {
53
        return 'url text';
54
    }
55
56
    /**
57
     * @param string $name
58
     * @param mixed $val
59
     */
60 1
    public function setConfig($name, $val = null)
61
    {
62 1
        if (is_array($name) && $val == null) {
63 1
            foreach ($name as $n => $value) {
64 1
                $this->setConfig($n, $value);
65
            }
66
67 1
            return $this;
68
        }
69 1
        if (is_array($this->config[$name])) {
70 1
            if (!is_array($val)) {
71
                user_error("The value for $name must be an array");
72
            }
73 1
            $this->config[$name] = array_merge($this->config[$name], $val);
74 1
        } elseif (isset($this->config[$name])) {
75 1
            $this->config[$name] = $val;
76
        }
77
78 1
        return $this;
79
    }
80
81
    /**
82
     * @param String $name Optional, returns the whole configuration array if empty
83
     * @return mixed|array
84
     */
85 1
    public function getConfig($name = null)
86
    {
87 1
        if ($name) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $name of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
88 1
            return isset($this->config[$name]) ? $this->config[$name] : null;
89
        } else {
90
            return $this->config;
91
        }
92
    }
93
94
    /**
95
     * Set additional attributes
96
     * @return array Attributes
97
     */
98
    public function getAttributes()
99
    {
100
        $attributes = array(
101
            'placeholder' => $this->config['defaultparts']['scheme'] . "://example.com" //example url
102
        );
103
        if ($this->config['html5validation']) {
104
            $attributes += array(
105
                'type' => 'url', //html5 field type
106
                'pattern' => 'https?://.+', //valid urls only
107
            );
108
        }
109
110
        return array_merge(
111
            parent::getAttributes(),
112
            $attributes
113
        );
114
    }
115
116
    /**
117
     * Rebuild url on save
118
     * @param string $url
119
     */
120 2
    public function setValue($url)
121
    {
122 2
        if ($url) {
123 2
            $url = $this->rebuildURL($url);
124
        }
125 2
        parent::setValue($url);
126 2
    }
127
128
    /**
129
     * Add config scheme, if missing.
130
     * Remove the parts of the url we don't want.
131
     * Set any defaults, if missing.
132
     * Remove any trailing slash, and rebuild.
133
     * @return string
134
     */
135 2
    protected function rebuildURL($url)
136
    {
137 2
        $defaults = $this->config['defaultparts'];
138 2
        if (!preg_match('#^[a-zA-Z]+://#', $url)) {
139 2
            $url = $defaults['scheme'] . "://" . $url;
140
        }
141 2
        $parts = parse_url($url);
142 2
        if (!$parts) {
143
            //can't parse url, abort
144 1
            return "";
145
        }
146 2
        foreach ($parts as $part => $value) {
147 2
            if ($this->config['removeparts'][$part] === true) {
148 2
                unset($parts[$part]);
149
            }
150
        }
151
        //set defaults, if missing
152 2
        foreach ($defaults as $part => $default) {
153 2
            if (!isset($parts[$part])) {
154 2
                $parts[$part] = $default;
155
            }
156
        }
157
158 2
        return rtrim(http_build_url($defaults, $parts), "/");
159
    }
160
161
    /**
162
     * Server side validation, using a regular expression.
163
     */
164 1
    public function validate($validator)
165
    {
166 1
        $this->value = trim($this->value);
167 1
        $regex = $this->config['validregex'];
168 1
        if ($this->value && $regex && !preg_match($regex, $this->value)) {
169 1
            $validator->validationError(
170 1
                $this->name,
171 1
                _t('ExternalURLField.VALIDATION', "Please enter a valid URL"),
172 1
                "validation"
173
            );
174 1
            return false;
175
        }
176 1
        return true;
177
    }
178
}
179