Issues (443)

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.

common/models/BaseComment.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
 * @link http://www.writesdown.com/
4
 * @copyright Copyright (c) 2015 WritesDown
5
 * @license http://www.writesdown.com/license/
6
 */
7
8
namespace common\models;
9
10
use Yii;
11
use yii\db\ActiveRecord;
12
13
/**
14
 * This is the model class for table "{{%post_comment}}".
15
 *
16
 * @property integer $id
17
 * @property string $author
18
 * @property string $email
19
 * @property string $url
20
 * @property string $ip
21
 * @property string $date
22
 * @property string $content
23
 * @property string $status
24
 * @property string $agent
25
 * @property integer $parent
26
 * @property integer $user_id
27
 *
28
 * @author  Agiel K. Saputra <[email protected]>
29
 * @since 0.1.0
30
 */
31
abstract class BaseComment extends ActiveRecord
32
{
33
    const STATUS_APPROVED = "approved";
34
    const STATUS_NOT_APPROVED = "unapproved";
35
    const STATUS_TRASHED = "trashed";
36
37
    /**
38
     * @var BaseComment[]
39
     */
40
    public $child;
41
42
    /**
43
     * @return array
44
     */
45
    public function scenarios()
46
    {
47
        $scenarios = parent::scenarios();
48
        $scenarios['reply'] = $scenarios['default'];
49
50
        return $scenarios;
51
    }
52
53
    /**
54
     * @inheritdoc
55
     */
56
    public function rules()
57
    {
58
        return [
59
            [
60
                ['author', 'email'],
61
                'required',
62
                'when' => function () {
63
                    return Option::get('require_name_email') && Yii::$app->user->isGuest ? true : false;
64
                },
65
            ],
66
            ['email', 'filter', 'filter' => 'trim'],
67
            ['email', 'email'],
68
            ['content', 'required'],
69
            ['status', 'default', 'value' => self::STATUS_NOT_APPROVED],
70
            [
71
                'status',
72
                'in',
73
                'range' => [self::STATUS_APPROVED, self::STATUS_NOT_APPROVED, self::STATUS_TRASHED],
74
            ],
75
            [['parent', 'user_id'], 'integer'],
76
            ['parent', 'default', 'value' => 0],
77
            [['author', 'content'], 'string'],
78
            ['date', 'safe'],
79
            [['email', 'ip'], 'string', 'max' => 100],
80
            ['agent', 'string', 'max' => 255],
81
            ['url', 'url'],
82
        ];
83
    }
84
85
    /**
86
     * @inheritdoc
87
     */
88
    public function attributeLabels()
89
    {
90
        return [
91
            'id' => Yii::t('writesdown', 'ID'),
92
            'author' => Yii::t('writesdown', 'Name'),
93
            'email' => Yii::t('writesdown', 'Email'),
94
            'url' => Yii::t('writesdown', 'URL'),
95
            'ip' => Yii::t('writesdown', 'IP'),
96
            'date' => Yii::t('writesdown', 'Date'),
97
            'content' => Yii::t('writesdown', 'Content'),
98
            'status' => Yii::t('writesdown', 'Status'),
99
            'agent' => Yii::t('writesdown', 'Agent'),
100
            'parent' => Yii::t('writesdown', 'Parent'),
101
            'user_id' => Yii::t('writesdown', 'User ID'),
102
        ];
103
    }
104
105
    /**
106
     * @return \yii\db\ActiveQuery
107
     */
108
    public function getCommentPost()
109
    {
110
        return $this->hasOne(Post::className(), ['id' => 'post_id']);
111
    }
112
113
    /**
114
     * Get comment status in array
115
     *
116
     * @return array
117
     */
118
    public function getStatuses()
119
    {
120
        return [
121
            self::STATUS_APPROVED => Yii::t('writesdown', 'Approved'),
122
            self::STATUS_NOT_APPROVED => Yii::t('writesdown', 'Not Approved'),
123
            self::STATUS_TRASHED => Yii::t('writesdown', 'Trashed'),
124
        ];
125
    }
126
127
    /**
128
     * @inheritdoc
129
     */
130
    public function beforeSave($insert)
0 ignored issues
show
beforeSave uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

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

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
131
    {
132
        if (parent::beforeSave($insert)) {
133
            if ($this->isNewRecord) {
134
                if (!Yii::$app->user->isGuest) {
135
                    $this->user_id = Yii::$app->user->id;
136
                    $this->email = Yii::$app->user->identity->email;
137
                    $this->author = Yii::$app->user->identity->display_name;
138
                }
139
                $this->agent = $_SERVER['HTTP_USER_AGENT'];
140
                $this->ip = $_SERVER['REMOTE_ADDR'];
141
                $this->date = date('Y-m-d H:i:s');
142
                $this->status = self::STATUS_APPROVED;
143
                if (Option::get('comment_moderation') && Yii::$app->user->isGuest) {
144
                    if (Option::get('comment_whitelist') && Option::get('require_name_email')) {
145
                        $hasComment = static::find()
146
                            ->andWhere(['email' => $this->email])
147
                            ->andWhere(['status' => self::STATUS_APPROVED])
148
                            ->count();
149
                        if (!$hasComment) {
150
                            $this->status = self::STATUS_NOT_APPROVED;
151
                        }
152
                    } else {
153
                        $this->status = self::STATUS_NOT_APPROVED;
154
                    }
155
                }
156
            }
157
158
            return true;
159
        }
160
161
        return false;
162
    }
163
}
164