Issues (2366)

Branch: master

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/Eccube/Application/ApplicationTrait.php (13 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 Eccube\Application;
4
5
use Eccube\Event\TemplateEvent;
6
use Monolog\Logger;
7
use Symfony\Component\Form\FormBuilder;
8
use Symfony\Component\HttpFoundation\Response;
9
use Symfony\Component\HttpFoundation\StreamedResponse;
10
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
11
use Symfony\Component\Security\Core\User\UserInterface;
12
13
/**
14
 * TODO Traitが使えるようになったら不要になる
15
 */
16
class ApplicationTrait extends \Silex\Application
17
{
18
    /**
0 ignored issues
show
Doc comment for parameter "$message" missing
Loading history...
Doc comment for parameter "$namespace" missing
Loading history...
19
     * Application Shortcut Methods
20 7
     */
21
    public function addSuccess($message, $namespace = 'front')
22
    {
23 7
        $this['session']->getFlashBag()->add('eccube.' . $namespace . '.success', $message);
0 ignored issues
show
Concat operator must not be surrounded by spaces
Loading history...
24
    }
25 2
26
    public function addError($message, $namespace = 'front')
0 ignored issues
show
Missing function doc comment
Loading history...
27
    {
28 2
        $this['session']->getFlashBag()->add('eccube.' . $namespace . '.error', $message);
0 ignored issues
show
Concat operator must not be surrounded by spaces
Loading history...
29
    }
30
31
    public function addDanger($message, $namespace = 'front')
0 ignored issues
show
Missing function doc comment
Loading history...
32
    {
33
        $this['session']->getFlashBag()->add('eccube.' . $namespace . '.danger', $message);
0 ignored issues
show
Concat operator must not be surrounded by spaces
Loading history...
34
    }
35 1
36
    public function addWarning($message, $namespace = 'front')
0 ignored issues
show
Missing function doc comment
Loading history...
37
    {
38 1
        $this['session']->getFlashBag()->add('eccube.' . $namespace . '.warning', $message);
0 ignored issues
show
Concat operator must not be surrounded by spaces
Loading history...
39
    }
40
41
    public function addInfo($message, $namespace = 'front')
0 ignored issues
show
Missing function doc comment
Loading history...
42
    {
43
        $this['session']->getFlashBag()->add('eccube.' . $namespace . '.info', $message);
0 ignored issues
show
Concat operator must not be surrounded by spaces
Loading history...
44
    }
45
46
    public function addRequestError($message, $namespace = 'front')
0 ignored issues
show
Missing function doc comment
Loading history...
47
    {
48
        $this['session']->getFlashBag()->set('eccube.' . $namespace . '.request.error', $message);
0 ignored issues
show
Concat operator must not be surrounded by spaces
Loading history...
49
    }
50
51
    public function clearMessage()
52
    {
53
        $this['session']->getFlashBag()->clear();
54
    }
55
56
    public function deleteMessage()
57
    {
58
        $this->clearMessage();
59
        $this->addWarning('admin.delete.warning', 'admin');
60
    }
61
62
    public function setLoginTargetPath($targetPath, $namespace = null)
63
    {
64
        if (is_null($namespace)) {
65
            $this['session']->getFlashBag()->set('eccube.login.target.path', $targetPath);
66
        } else {
67
            $this['session']->getFlashBag()->set('eccube.' . $namespace . '.login.target.path', $targetPath);
68
        }
69
    }
70
71
    public function isAdminRequest()
72
    {
73
        return isset($this['admin']) ? $this['admin'] : null;
74
    }
75
76
    public function isFrontRequest()
77
    {
78
        return isset($this['front']) ? $this['front'] : null;
79
    }
80
81
    /*
82
     * 注意!以下コードはSilexのコードのコピーなので触らないコト
83
     *
84
     * 以下のコードの著作権について
85
     *
86
     * (c) Fabien Potencier <[email protected]>
87
     *
88
     * For the full copyright and license information, please view the silex
89
     * LICENSE file that was distributed with this source code.
90
     */
91
92
    /** FormTrait */
93
    /**
94
     * Creates and returns a form builder instance
95
     *
96
     * @param mixed $data The initial data for the form
97
     * @param array $options Options for the form
98
     *
99
     * @return FormBuilder
100
     */
101 2
    public function form($data = null, array $options = array())
102
    {
103
        return $this['form.factory']->createBuilder('form', $data, $options);
104 2
    }
105
106
    /** MonologTrait */
107
    /**
108
     * Adds a log record.
109
     *
110
     * @param string $message The log message
111
     * @param array $context The log context
112
     * @param int $level The logging level
113
     *
114
     * @return bool Whether the record has been processed
115
     */
116
    public function log($message, array $context = array(), $level = Logger::INFO)
117
    {
118
        return $this['monolog']->addRecord($level, $message, $context);
119
    }
120
121
    /** SecurityTrait */
122
    /**
123
     * Gets a user from the Security context.
124
     *
125
     * @return mixed
126
     *
127
     * @see TokenInterface::getUser()
128
     *
129
     */
130 1
    public function user()
131
    {
132
        return $this['user'];
133 1
    }
134
135
    /**
136
     * Encodes the raw password.
137
     *
138
     * @param UserInterface $user A UserInterface instance
139
     * @param string $password The password to encode
140
     *
141
     * @return string The encoded password
142
     *
143
     * @throws \RuntimeException when no password encoder could be found for the user
144
     */
145 4
    public function encodePassword(UserInterface $user, $password)
146
    {
147
        return $this['security.encoder_factory']->getEncoder($user)->encodePassword($password, $user->getSalt());
148 4
    }
149
150
    /**
151
     * Checks if the attributes are granted against the current authentication token and optionally supplied object.
152
     *
153
     * @param mixed $attributes
154
     * @param mixed $object
155
     *
156
     * @return bool
157
     *
158
     * @throws AuthenticationCredentialsNotFoundException when the token storage has no authentication token.
159 10
     */
160
    public function isGranted($attributes, $object = null)
161
    {
162 10
        return $this['security.authorization_checker']->isGranted($attributes, $object);
163
    }
164
165
    /** SwiftmailerTrait */
166
    /**
167
     * Sends an email.
168
     *
169
     * @param \Swift_Message $message A \Swift_Message instance
170
     * @param array $failedRecipients An array of failures by-reference
171
     *
172
     * @return int The number of sent messages
173
     */
174
    public function mail(\Swift_Message $message, &$failedRecipients = null)
175
    {
176
        return $this['mailer']->send($message, $failedRecipients);
177
    }
178
179
    /** TranslationTrait */
180
    /**
181
     * Translates the given message.
182
     *
183
     * @param string $id The message id
184
     * @param array $parameters An array of parameters for the message
185
     * @param string $domain The domain for the message
186
     * @param string $locale The locale
187
     *
188
     * @return string The translated string
189
     */
190
    public function trans($id, array $parameters = array(), $domain = 'messages', $locale = null)
191
    {
192
        return $this['translator']->trans($id, $parameters, $domain, $locale);
193
    }
194
195
    /**
196
     * Translates the given choice message by choosing a translation according to a number.
197
     *
198
     * @param string $id The message id
199
     * @param int $number The number to use to find the indice of the message
200
     * @param array $parameters An array of parameters for the message
201
     * @param string $domain The domain for the message
202
     * @param string $locale The locale
203
     *
204
     * @return string The translated string
205
     */
206
    public function transChoice($id, $number, array $parameters = array(), $domain = 'messages', $locale = null)
207
    {
208 35
        return $this['translator']->transChoice($id, $number, $parameters, $domain, $locale);
209
    }
210
211
    /** TwigTrait */
212 35
    /**
213
     * Renders a view and returns a Response.
214
     *
215
     * To stream a view, pass an instance of StreamedResponse as a third argument.
216
     *
217 34
     * @param string $view The view name
218
     * @param array $parameters An array of parameters to pass to the view
219
     * @param Response $response A Response instance
220
     *
221 1
     * @return Response A Response instance
222
     */
223 35
    public function render($view, array $parameters = array(), Response $response = null)
224 34
    {
225
        $twig = $this['twig'];
226
227
        // twigファイルのソースコードを読み込み, 文字列化.
228
        $source = $twig->getLoader()->getSource($view);
229
230
        // イベントの実行.
231
        // プラグインにはテンプレートファイル名、文字列化されたtwigファイル、パラメータを渡す
232
        $event = new TemplateEvent($view, $source, $parameters, $response);
233
234 15
        $eventName = $view;
235
        if ($this->isAdminRequest()) {
236
            // 管理画面の場合、event名に「Admin/」を付ける
237 15
            $eventName = 'Admin/' . $view;
238
        }
239
        $this['monolog']->debug('Template Event Name : ' . $eventName);
240
241
        $this['eccube.event.dispatcher']->dispatch($eventName, $event);
242
243
        if ($response instanceof StreamedResponse) {
244
            $response->setCallback(function () use ($twig, $view, $parameters) {
245
                $twig->display($view, $parameters);
246
            });
247
        } else {
248 1
            if (null === $response) {
249
                $response = new Response();
250
            }
251 1
252
            // プラグインで変更された文字列から, テンプレートオブジェクトを生成
253
            $template = $twig->createTemplate($event->getSource());
254
255
            // レンダリング実行.
256
            $content = $template->render($event->getParameters());
257
            $response->setContent($content);
258
        }
259
260
        return $response;
261 28
    }
262
263
    /**
264 28
     * Renders a view.
265
     *
266
     * @param string $view The view name
267
     * @param array $parameters An array of parameters to pass to the view
268
     *
269
     * @return string The rendered view
270
     */
271
    public function renderView($view, array $parameters = array())
272
    {
273
        return $this['twig']->render($view, $parameters);
274
    }
275
276
    /** UrlGeneratorTrait */
277
    /**
278
     * Generates a path from the given parameters.
279
     *
280
     * @param string $route The name of the route
281
     * @param mixed $parameters An array of parameters
282
     *
283
     * @return string The generated path
284
     */
285
    public function path($route, $parameters = array())
286
    {
287
        return $this['url_generator']->generate($route, $parameters, UrlGeneratorInterface::ABSOLUTE_PATH);
288
    }
289
290
    /**
291
     * Generates an absolute URL from the given parameters.
292
     *
293
     * @param string $route The name of the route
294
     * @param mixed $parameters An array of parameters
295
     *
296
     * @return string The generated URL
297
     */
298
    public function url($route, $parameters = array())
299
    {
300
        return $this['url_generator']->generate($route, $parameters, UrlGeneratorInterface::ABSOLUTE_URL);
301
    }
302
}
303