Issues (42)

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/GridFieldRecordHighlighter.php (2 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\GridFieldAddOns;
4
5
use SilverStripe\Core\Convert;
6
use SilverStripe\View\Requirements;
7
use SilverStripe\Forms\GridField\GridField;
8
use SilverStripe\Forms\GridField\GridField_ColumnProvider;
9
10
class GridFieldRecordHighlighter implements GridField_ColumnProvider
11
{
12
13
    protected $alerts;
14
15
    function __construct($alerts)
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
16
    {
17
        $this->alerts = $alerts;
18
    }
19
20
    /**
21
     * Add extra fields to the column list
22
     *
23
     * @param GridField $gridField
24
     * @param array - List reference of all column names.
25
     */
26
    public function augmentColumns($gridField, &$columns)
27
    {
28
29
        array_unshift($columns, 'Alerts');
30
    }
31
32
    /**
33
     * List of handled columns
34
     *
35
     * @param GridField $gridField
36
     * @return array
37
     */
38
    public function getColumnsHandled($gridField)
39
    {
40
41
        return array('Alerts');
42
    }
43
44
    /**
45
     * Set titles for the column header
46
     *
47
     * @param GridField $gridField
48
     * @param string $columnName
49
     * @return array - Map of arbitrary metadata identifiers to their values.
50
     */
51
    public function getColumnMetadata($gridField, $columnName)
52
    {
53
54
        return array('title' => '');
55
    }
56
57
    /**
58
     * Return a formfield for the extra field column or an edit button for the actions column
59
     *
60
     * @param  GridField $gridField
61
     * @param  DataObject $record - Record displayed in this row
62
     * @param  string $columnName
63
     * @return string - HTML for the column. Return NULL to skip.
64
     */
65
    public function getColumnContent($gridField, $record, $columnName)
66
    {
67
68
        Requirements::javascript('i-lateral/silverstripe-gridfield-addons:javascript/GridFieldRecordHighlighter.js');
69
        Requirements::css('i-lateral/silverstripe-gridfield-addons:css/GridFieldRecordHighlighter.css');
70
71
        $alerts = $this->getAlerts($record);
72
73
        $content = array();
74
        foreach ($alerts as $alert) {
75
            if ($alert['status'] === 'alert') {
76
                $icon_class = "font-icon-attention";
77
            } elseif ($alert['status'] == 'info') {
78
                $icon_class = "font-icon-info-circled";
79
            } else {
80
                $icon_class = null;
81
            }
82
            $content[] = "<span class=\"ss-gridfield-alert {$icon_class}\" title=\"{$alert['message']}\"></span>";
83
        }
84
        
85
        return implode($content);
86
    }
87
88
    /**
89
     * Generate HTML attributes for each individual cells as selectors for CSS and JS
90
     *
91
     * @param  GridField $gridField
92
     * @param  DataObject $record displayed in this row
93
     * @param  string $columnName
94
     * @return array
95
     */
96
    public function getColumnAttributes($gridField, $record, $columnName)
97
    {
98
99
        $attr = array();
100
101
        foreach ($this->getAlerts($record) as $alert) {
102
            if ($alert['status'] == 'alert') {
103
                $attr = array('class' => 'ss-gridfield-highlight', 'data-highlight-status' => 'error');
104
            } elseif (empty($attr)) {
105
                $attr = array('class' => 'ss-gridfield-highlight', 'data-highlight-status' => 'highlight');
106
            }
107
        }
108
109
        return $attr;
110
    }
111
112
    function getAlerts($record)
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
113
    {
114
115
        $alerts = array();
116
117
        foreach ($this->alerts as $getter => $rule) {
118
            $actualvalue = $record->hasField($getter) ? $record->$getter : $record->$getter();
119
            foreach ($rule['patterns'] as $nominalvalue => $return) {
120
                if (($rule['comparator'] == 'equal' &&          $actualvalue == $nominalvalue) ||
121
                    ($rule['comparator'] == 'equalstrict' &&    $actualvalue === $nominalvalue) ||
122
                    ($rule['comparator'] == 'unequal' &&        $actualvalue != $nominalvalue) ||
123
                    ($rule['comparator'] == 'unequalstrict' &&  $actualvalue !== $nominalvalue) ||
124
                    ($rule['comparator'] == 'greater' &&        $actualvalue > $nominalvalue) ||
125
                    ($rule['comparator'] == 'greaterorequal' && $actualvalue >= $nominalvalue) ||
126
                    ($rule['comparator'] == 'less' &&           $actualvalue < $nominalvalue) ||
127
                    ($rule['comparator'] == 'lessorequal' &&    $actualvalue <= $nominalvalue) ||
128
                    ($rule['comparator'] == 'beginwith' &&      strtolower(substr($actualvalue, 0, strlen($nominalvalue))) == strtolower($nominalvalue)) ||
129
                    ($rule['comparator'] == 'endwith' &&        strtolower(substr($actualvalue, -1 * strlen($nominalvalue))) == strtolower($nominalvalue)) ||
130
                    ($rule['comparator'] == 'contain' &&        stripos($actualvalue, $nominalvalue) !== false) ||
131
                    ($rule['comparator'] == 'regex' &&          preg_match($nominalvalue, $actualvalue))
132
                ) {
133
                    $alerts[$getter] = array(
134
                        'status' => $return['status'],
135
                        'message' => sprintf($return['message'], Convert::raw2xml($nominalvalue), Convert::raw2xml($actualvalue)),
136
                    );
137
                    break;
138
                }
139
            }
140
        }
141
142
        return $alerts;
143
    }
144
}
145