Issues (55)

Security Analysis    no request data  

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.

models/Option.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 namespace Bedard\Shop\Models;
2
3
use Exception;
4
use Lang;
5
use Model;
6
7
/**
8
 * Option Model.
9
 */
10
class Option extends Model
11
{
12
    use \October\Rain\Database\Traits\Purgeable,
13
        \October\Rain\Database\Traits\Validation;
14
15
    /**
16
     * @var string The database table used by the model.
17
     */
18
    public $table = 'bedard_shop_options';
19
20
    /**
21
     * @var array Default attributes
22
     */
23
    public $attributes = [
24
        'name' => '',
25
        'placeholder' => '',
26
        'sort_order' => 0,
27
    ];
28
29
    /**
30
     * @var array Attribute casting
31
     */
32
    protected $casts = [
33
        'id' => 'integer',
34
    ];
35
36
    /**
37
     * @var array Guarded fields
38
     */
39
    protected $guarded = ['*'];
40
41
    /**
42
     * @var array Fillable fields
43
     */
44
    protected $fillable = [
45
        'name',
46
        'placeholder',
47
        'sort_order',
48
        'value_data',
49
    ];
50
51
    /**
52
     * @var array Purgeable fields
53
     */
54
    public $purgeable = [
55
        'value_data',
56
    ];
57
58
    /**
59
     * @var array Relations
60
     */
61
    public $belongsTo = [
62
        'product' => [
63
            'Bedard\Shop\Models\Product',
64
        ],
65
    ];
66
67
    public $hasMany = [
68
        'values' => [
69
            'Bedard\Shop\Models\OptionValue',
70
            'delete' => true,
71
            'order' => 'sort_order asc',
72
        ],
73
    ];
74
75
    /**
76
     * @var array Validation
77
     */
78
    public $rules = [
79
        'name' => 'required',
80
    ];
81
82
    /**
83
     * After save.
84
     *
85
     * @return void
86
     */
87
    public function afterSave()
88
    {
89
        $this->saveValues();
90
    }
91
92
    /**
93
     * After validate.
94
     *
95
     * @return void
96
     */
97
    public function afterValidate()
98
    {
99
        $this->validateValues();
100
    }
101
102
    /**
103
     * Save related values.
104
     *
105
     * @return void
106
     */
107
    protected function saveValues()
108
    {
109
        $values = $this->getOriginalPurgeValue('value_data') ?: [];
110
111
        if (count($values)) {
112
            foreach ($values as $value) {
113
                $model = $value['id'] !== null
114
                        ? OptionValue::findOrNew($value['id'])
115
                        : new OptionValue;
116
117 View Code Duplication
                if (array_key_exists('_deleted', $value) && $value['_deleted'] && $model->exists()) {
0 ignored issues
show
This code seems to be duplicated across 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...
118
                    // delete the model if it has the _deleted flag
119
                    $model->delete();
120
                } else {
121
                    // otherwise update the model's values
122
                    $model->name = $value['name'];
123
                    $model->option_id = $this->id;
124
                    $model->sort_order = $value['sort_order'];
125
                    $model->save();
126
                }
127
            }
128
        }
129
    }
130
131
    /**
132
     * Validate option values.
133
     *
134
     * @return void
135
     */
136
    protected function validateValues()
137
    {
138
        $names = [];
139
        $values = $this->value_data ?: [];
140
141
        // don't validate deleted values
142
        $nonDeletedValues = array_filter($values, function ($value) {
143
            return ! array_key_exists('_deleted', $value) || ! $value['_deleted'];
144
        });
145
146
        foreach ($nonDeletedValues as $value) {
147
            // validate each value individually
148
            $model = new OptionValue($value);
149
            $model->validate();
150
151
            // ensure that the name is unique to this option
152
            if (in_array($value['name'], $names)) {
153
                throw new Exception(Lang::get('bedard.shop::lang.options.form.values_unique'));
154
            }
155
156
            $names[] = $value['name'];
157
        }
158
159
        // ensure that at least one value was provided
160
        if (count($names) < 1) {
161
            throw new Exception(Lang::get('bedard.shop::lang.options.form.values_required'));
162
        }
163
    }
164
}
165