Issues (685)

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.

src/I18n/Language.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
namespace App\I18n;
3
4
use Cake\Controller\Controller;
5
use Cake\Core\Configure;
6
use Cake\I18n\I18n;
7
8
class Language
9
{
10
11
    /**
12
     * The Cookie instance.
13
     *
14
     * @var \Cake\Network\Session
15
     */
16
    protected $_session;
17
18
    /**
19
     * The Cookie instance.
20
     *
21
     * @var \Cake\Controller\Component\CookieComponent
22
     */
23
    protected $_cookie;
24
25
    /**
26
     * The Controller instance.
27
     *
28
     * @var \Cake\Controller\Controller
29
     */
30
    protected $_controller;
31
32
    /**
33
     * All locales allowed to be used.
34
     *
35
     * @var array
36
     */
37
    protected $_locales = [];
38
39
    /**
40
     * The locale to be used.
41
     *
42
     * @var string
43
     */
44
    protected $_locale;
45
46
    /**
47
     * Construct method.
48
     *
49
     * @param \Cake\Controller\Controller $controller The controller that was fired.
50
     */
51
    public function __construct(Controller $controller)
52
    {
53
        $this->_controller = $controller;
54
        $this->_session = $controller->request->session();
55
        $this->_cookie = $controller->Cookie;
56
        $this->_locales = Configure::read('I18n.locales');
0 ignored issues
show
Documentation Bug introduced by
It seems like \Cake\Core\Configure::read('I18n.locales') of type * is incompatible with the declared type array of property $_locales.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
57
        $this->_locale = I18n::locale();
58
59
        $this->_cookie->configKey('language', [
60
            'expires' => '+1 year',
61
            'httpOnly' => true
62
        ]);
63
    }
64
65
    /**
66
     * Set the language for the user.
67
     *
68
     * @return void
69
     */
70
    public function setLanguage()
71
    {
72
        if ($this->_controller->Auth->user()) {
73
            //The user has already a valid language defined in the database.
74
            if ($this->_session->read('Auth.User.language') && isset($this->_locales[$this->_session->read('Auth.User.language')])) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->_session->read('Auth.User.language') of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
75
                //If the user has not the cookie, we set the cookie.
76
                if (!$this->_cookie->check('language') || $this->_cookie->read('language') != $this->_session->read('Auth.User.language')) {
77
                    $this->_cookie->write('language', $this->_session->read('Auth.User.language'));
78
                }
79
                //Stock the locale of the user.
80
                $this->_locale = $this->_session->read('Auth.User.language');
81
            }
82
        } else {
83
            //The user has a valid cookie.
84
            if ($this->_cookie->check('language') && isset($this->_locales[$this->_cookie->read('language')])) {
85
                $this->_locale = $this->_cookie->read('language');
86
            }
87
        }
88
89
        //The user want to change his language.
90
        if (!is_null($this->_controller->request->getParam('lang')) && isset($this->_locales[$this->_controller->request->getParam('lang')])) {
91
            //If the user is connected, we need to save the new language in the database and refresh his session.
92
            if ($this->_controller->Auth->user()) {
93
                $this->_controller->loadModel('Users');
94
95
                $user = $this->_controller->Users
96
                    ->find()
97
                    ->where(['id' => $this->_session->read('Auth.User.id')])
98
                    ->first();
99
100
                $user->language = $this->_controller->request->getParam('lang');
101
                $this->_controller->Users->save($user);
102
                $this->_session->write('Auth.User.language', $this->_controller->request->getParam('lang'));
103
            }
104
105
            //Save the new language in the cookie.
106
            $this->_cookie->write('language', $this->_controller->request->getParam('lang'));
107
108
            $this->_locale = $this->_controller->request->getParam('lang');
109
        }
110
111
        //Set the locale.
112
        I18n::locale($this->_locale);
113
    }
114
}
115