Issues (5)

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.

code/TogglePaginator.php (5 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
/**
4
 * A GridField component that allows to temporary disable the
5
 * pagination.
6
 *
7
 * It should be included before the GridFieldPaginator component that
8
 * must be present (otherwise this class would be pretty useless).
9
 *
10
 * @package silverstripe-togglepaginator
11
 */
12
class GridFieldTogglePaginator implements GridField_HTMLProvider, GridField_ActionProvider, GridField_DataManipulator
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...
13
{
14
    /**
15
     * The icon to use on the enable pagination button. Can be null.
16
     * @config
17
     */
18
    private static $enable_icon;
0 ignored issues
show
The property $enable_icon 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...
19
20
    /**
21
     * The icon to use on the disable pagination button. Can be null.
22
     * @config
23
     */
24
    private static $disable_icon;
0 ignored issues
show
The property $disable_icon 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
     * Fragment to write the button to.
28
     */
29
    protected $target;
30
31
    /**
32
     * ID of the session data.
33
     */
34
    protected $state_id;
35
36
    /**
37
     * Session data (an associative array).
38
     */
39
    protected $state;
40
41
42
    public function __construct($target = 'buttons-before-right')
43
    {
44
        $this->target = $target;
45
    }
46
47
    /**
48
     * Update $state and $state_id properties.
49
     *
50
     * If the $state array does not exist in the session, create it.
51
     *
52
     * The current implementation is borrowed directly from
53
     * GridField_FormAction::getAttributes() 3.2.0-beta2.
54
     */
55
    protected function updateState($grid)
56
    {
57
        if (isset($this->state_id)) {
58
            return;
59
        }
60
61
        $state = array(
62
            'grid'       => $grid->getName(),
63
            'actionName' => 'toggle',
64
            'active'     => true,
65
        );
66
67
        // Ensure the id doesn't contain only numeric characters
68
        $this->state_id = 'gf_' . substr(md5(serialize($state)), 0, 8);
69
70
        $this->state = Session::get($this->state_id);
71
        if (! is_array($this->state) || ! array_key_exists('active', $this->state)) {
72
            $this->state = $state;
73
            Session::set($this->state_id, $state);
0 ignored issues
show
$state is of type array<string,?,{"grid":"...g","active":"boolean"}>, but the function expects a string.

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...
74
        }
75
    }
76
77
    /**
78
     * Implements the GridField_HTMLProvider interface.
79
     *
80
     * @param  GridField $grid
81
     * @return array
82
     */
83
    public function getHTMLFragments($grid)
84
    {
85
        $this->updateState($grid);
86
87
        $active = $this->state['active'];
88
        $params = http_build_query(array('StateID' => $this->state_id));
89
        $data = new ArrayData(array(
90
            'state' => $active ? 'ui-state-default' : 'ss-ui-alternate ui-state-highlight',
91
            'icon'  => Config::inst()->get(__CLASS__, $active ? 'enable_icon' : 'disable_icon'),
92
            'label' => $active ? _t(__CLASS__ . '.DISABLE', 'Disable') : _t(__CLASS__ . '.ENABLE', 'Enable'),
93
            'name'  => 'action_gridFieldAlterAction?' . $params,
94
            'url'   => $grid->Link(),
95
        ));
96
97
        return array(
98
            $this->target => $data->renderWith(__CLASS__),
99
        );
100
    }
101
102
    /**
103
     * Required by the GridField_ActionProvider interface.
104
     *
105
     * @param  GridField $grid
106
     * @return array
107
     */
108
    public function getActions($grid)
109
    {
110
        return array('toggle');
111
    }
112
113
    /**
114
     * Handle the action.
115
     *
116
     * It swithces the "state" flag and saves the data into a session
117
     * variable for later reuse.
118
     *
119
     * @param  GridField $grid      The subject GridField instance
120
     * @param  string    $action    The action name (lowercase!)
121
     * @param  mixed     $arguments Optional argument(s) for the action
122
     * @param  array     $data      Form data, if relevant
123
     *
124
     * @throws InvalidArgumentException
125
     */
126
    public function handleAction(GridField $grid, $action, $arguments, $data)
127
    {
128
        switch ($action) {
129
130
        case 'toggle':
131
            $this->updateState($grid);
132
            $this->state['active'] = ! $this->state['active'];
133
            Session::set($this->state_id, $this->state);
0 ignored issues
show
$this->state is of type array<string,?,{"active":"boolean"}>, but the function expects a string.

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...
134
            break;
135
136
        default:
137
            throw new InvalidArgumentException(sprintf(
138
                'Action "%s" not understood',
139
                $action
140
            ));
141
        }
142
    }
143
144
    /**
145
     * Required by the GridField_DataManipulator interface.
146
     *
147
     * Disable pagination on the GridFieldPaginator component, if
148
     * required by the current "state" flag. It must be called before
149
     * GridFieldPaginator::getManipulatedData() to take effect, hence
150
     * the requirement that GridFieldTogglePaginator must be added
151
     * before GridFieldPaginator.
152
     *
153
     * @param  GridField $grid
154
     * @return SS_List
155
     */
156
    public function getManipulatedData(GridField $grid, SS_List $list)
157
    {
158
        $this->updateState($grid);
159
        if (! $this->state['active']) {
160
            $grid->getConfig()->getComponentByType('GridFieldPaginator')
161
                ->setItemsPerPage(PHP_INT_MAX);
162
        }
163
        return $list;
164
    }
165
}
166