Issues (110)

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/Widgets/BlogCategoriesWidget.php (3 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 SilverStripe\Blog\Widgets;
4
5
use SilverStripe\Blog\Model\Blog;
6
use SilverStripe\Core\Convert;
7
use SilverStripe\Forms\DropdownField;
8
use SilverStripe\Forms\FieldList;
9
use SilverStripe\Forms\NumericField;
10
use SilverStripe\ORM\DataList;
11
use SilverStripe\Widgets\Model\Widget;
12
13
if (!class_exists(Widget::class)) {
14
    return;
15
}
16
17
/**
18
 * @method Blog Blog()
19
 */
20 View Code Duplication
class BlogCategoriesWidget extends Widget
0 ignored issues
show
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
21
{
22
    /**
23
     * @var string
24
     */
25
    private static $title = 'Categories';
26
27
    /**
28
     * @var string
29
     */
30
    private static $cmsTitle = 'Blog Categories';
31
32
    /**
33
     * @var string
34
     */
35
    private static $description = 'Displays a list of blog categories.';
36
37
    /**
38
     * @var array
39
     */
40
    private static $db = [
41
        'Limit' => 'Int',
42
        'Order' => 'Varchar',
43
        'Direction' => 'Varchar',
44
    ];
45
46
    /**
47
     * @var array
48
     */
49
    private static $has_one = [
50
        'Blog' => Blog::class,
51
    ];
52
53
    /**
54
     * @var string
55
     */
56
    private static $table_name = 'BlogCategoriesWidget';
57
58
    /**
59
     * {@inheritdoc}
60
     */
61
    public function getCMSFields()
62
    {
63
        $this->beforeUpdateCMSFields(function (FieldList $fields) {
64
            $fields[] = DropdownField::create(
65
                'BlogID',
66
                _t(__CLASS__ . '.Blog', 'Blog'),
67
                Blog::get()->map()
68
            );
69
70
            $fields[] = NumericField::create(
71
                'Limit',
72
                _t(__CLASS__ . '.Limit', 'Limit'),
73
                0
74
            )
75
                ->setDescription(
76
                    _t(
77
                        __CLASS__ . '.Limit_Description',
78
                        'Limit the number of categories shown by this widget (set to 0 to show all categories).'
79
                    )
80
                )
81
                ->setMaxLength(3);
82
83
            $fields[] = DropdownField::create(
84
                'Order',
85
                _t(__CLASS__ . '.Sort', 'Sort'),
86
                ['Title' => 'Title', 'Created' => 'Created', 'LastEdited' => 'Updated']
87
            )
88
                ->setDescription(
89
                    _t(__CLASS__ . '.Sort_Description', 'Change the order of categories shown by this widget.')
90
                );
91
92
            $fields[] = DropdownField::create(
93
                'Direction',
94
                _t(__CLASS__ . '.Direction', 'Direction'),
95
                ['ASC' => 'Ascending', 'DESC' => 'Descending']
96
            )
97
                ->setDescription(
98
                    _t(
99
                        __CLASS__ . '.Direction_Description',
100
                        'Change the direction of ordering of categories shown by this widget.'
101
                    )
102
                );
103
        });
104
105
        return parent::getCMSFields();
106
    }
107
108
    /**
109
     * @return DataList
110
     */
111
    public function getCategories()
112
    {
113
        $blog = $this->Blog();
114
115
        if (!$blog) {
116
            return [];
0 ignored issues
show
Bug Best Practice introduced by
The return type of return array(); (array) is incompatible with the return type documented by SilverStripe\Blog\Widget...esWidget::getCategories of type SilverStripe\ORM\DataList.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
117
        }
118
119
        $query = $blog->Categories();
120
121
        if ($this->Limit) {
122
            $query = $query->limit(Convert::raw2sql($this->Limit));
0 ignored issues
show
\SilverStripe\Core\Convert::raw2sql($this->Limit) is of type array|string, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
123
        }
124
125
        if ($this->Order && $this->Direction) {
126
            $query = $query->sort(Convert::raw2sql($this->Order), Convert::raw2sql($this->Direction));
127
        }
128
129
        return $query;
130
    }
131
}
132