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.

frontend/controllers/SiteController.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
 * @link http://www.writesdown.com/
4
 * @copyright Copyright (c) 2015 WritesDown
5
 * @license http://www.writesdown.com/license/
6
 */
7
8
namespace frontend\controllers;
9
10
use common\models\Option;
11
use common\models\Post;
12
use common\models\PostComment;
13
use frontend\models\ContactForm;
14
use Yii;
15
use yii\data\Pagination;
16
use yii\filters\AccessControl;
17
use yii\filters\VerbFilter;
18
use yii\web\Controller;
19
use yii\web\ForbiddenHttpException;
20
use yii\web\NotFoundHttpException;
21
22
/**
23
 * Class SiteController
24
 *
25
 * @author Agiel K. Saputra <[email protected]>
26
 * @since 0.1.0
27
 */
28
class SiteController extends Controller
29
{
30
    /**
31
     * @inheritdoc
32
     */
33 View Code Duplication
    public function behaviors()
0 ignored issues
show
This method 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...
34
    {
35
        return [
36
            'access' => [
37
                'class' => AccessControl::className(),
38
                'only' => ['logout'],
39
                'rules' => [
40
                    [
41
                        'actions' => ['logout'],
42
                        'allow' => true,
43
                        'roles' => ['@'],
44
                    ],
45
                ],
46
            ],
47
            'verbs' => [
48
                'class' => VerbFilter::className(),
49
                'actions' => [
50
                    'logout' => ['post'],
51
                ],
52
            ],
53
        ];
54
    }
55
56
    /**
57
     * @inheritdoc
58
     */
59
    public function actions()
60
    {
61
        return [
62
            'error' => [
63
                'class' => 'yii\web\ErrorAction',
64
            ],
65
            'captcha' => [
66
                'class' => 'yii\captcha\CaptchaAction',
67
                'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
68
            ],
69
        ];
70
    }
71
72
    /**
73
     * Render home page of the site.
74
     *
75
     * @throws \yii\web\NotFoundHttpException
76
     * @return string
77
     */
78
    public function actionIndex()
79
    {
80
        /* @var $post \common\models\Post */
81
82
        $query = Post::find()
83
            ->from(['t' => Post::tableName()])
84
            ->andWhere(['status' => 'publish'])
85
            ->andWhere(['<=', 'date', date('Y-m-d H:i:s')])
86
            ->orderBy(['t.date' => SORT_DESC]);
87
88
        if (Option::get('show_on_front') == 'page' && $frontPage = Option::get('front_page')) {
89
            $render = '/post/view';
90
            $comment = new PostComment();
91
            $query = $query->andWhere(['id' => $frontPage]);
92
            if ($post = $query->one()) {
93
                if (is_file($this->view->theme->basePath . '/post/view-' . $post->postType->slug . '.php')) {
94
                    $render = '/post/view-' . $post->postType->slug;
95
                }
96
97
                return $this->render($render, [
98
                    'post' => $post,
99
                    'comment' => $comment,
100
                ]);
101
            }
102
            throw new NotFoundHttpException(Yii::t('writesdown', 'The requested page does not exist.'));
103
        } else {
104
            if (Option::get('front_post_type') !== 'all') {
105
                $query->innerJoinWith(['postType'])->andWhere(['name' => Option::get('front_post_type')]);
106
            }
107
            $countQuery = clone $query;
108
            $pages = new Pagination([
109
                'totalCount' => $countQuery->count(),
110
                'pageSize' => Option::get('posts_per_page'),
111
            ]);
112
            $query->offset($pages->offset)->limit($pages->limit);
113
            if ($posts = $query->all()) {
114
                return $this->render('index', [
115
                    'posts' => $posts,
116
                    'pages' => isset($pages) ? $pages : null,
117
                ]);
118
            }
119
120
            throw new NotFoundHttpException(Yii::t('writesdown', 'The requested page does not exist.'));
121
        }
122
    }
123
124
    /**
125
     * @return \yii\web\Response
126
     */
127
    public function actionLogout()
128
    {
129
        Yii::$app->user->logout();
130
131
        return $this->goHome();
132
    }
133
134
    /**
135
     * @return string|\yii\web\Response
136
     */
137
    public function actionContact()
138
    {
139
        $model = new ContactForm();
140
141
        if ($model->load(Yii::$app->request->post()) && $model->validate()) {
142
            if ($model->sendEmail(Option::get('admin_email'))) {
143
                Yii::$app->session->setFlash(
144
                    'success',
145
                    'Thank you for contacting us. We will respond to you as soon as possible.'
146
                );
147
            } else {
148
                Yii::$app->session->setFlash('error', 'There was an error sending email.');
149
            }
150
151
            return $this->refresh();
152
        }
153
154
        return $this->render('contact', [
155
            'model' => $model,
156
        ]);
157
    }
158
159
    /**
160
     * Search post by title and content
161
     *
162
     * @param string $s Keyword to search posts.
163
     * @return string
164
     * @throws \yii\web\NotFoundHttpException
165
     */
166
    public function actionSearch($s)
167
    {
168
        $query = Post::find()
169
            ->orWhere(['like', 'title', $s])
170
            ->orWhere(['like', 'content', $s])
171
            ->andWhere(['status' => 'publish'])
172
            ->andWhere(['<=', 'date', date('Y-m-d H:i:s')])
173
            ->orderBy(['date' => SORT_DESC]);
174
        $countQuery = clone $query;
175
        $pages = new Pagination([
176
            'totalCount' => $countQuery->count(),
177
            'pageSize' => Option::get('posts_per_page'),
178
        ]);
179
        $query->offset($pages->offset)->limit($pages->limit);
180
        $posts = $query->all();
181
182
        if ($posts) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $posts of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
183
            return $this->render('/site/search', [
184
                'posts' => $posts,
185
                'pages' => $pages,
186
                's' => $s,
187
            ]);
188
        }
189
190
        throw new NotFoundHttpException(Yii::t('writesdown', 'The requested page does not exist.'));
191
    }
192
193
    /**
194
     * @throws \yii\web\ForbiddenHttpException
195
     */
196
    public function actionForbidden()
197
    {
198
        throw new ForbiddenHttpException(Yii::t('writesdown', 'You are not allowed to perform this action.'));
199
    }
200
201
    /**
202
     * @throws \yii\web\NotFoundHttpException
203
     */
204
    public function actionNotFound()
205
    {
206
        throw new NotFoundHttpException(Yii::t('writesdown', 'The requested page does not exist.'));
207
    }
208
}
209