Issues (236)

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.

traits/UserTrait.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
/**
4
 *  _   __ __ _____ _____ ___  ____  _____
5
 * | | / // // ___//_  _//   ||  __||_   _|
6
 * | |/ // /(__  )  / / / /| || |     | |
7
 * |___//_//____/  /_/ /_/ |_||_|     |_|
8
 * @link https://vistart.me/
9
 * @copyright Copyright (c) 2016 - 2017 vistart
10
 * @license https://vistart.me/license/
11
 */
12
13
namespace rhosocial\base\models\traits;
14
15
use Yii;
16
use yii\base\InvalidParamException;
17
18
/**
19
 * Assemble PasswordTrait, RegistrationTrait and IdentityTrait into UserTrait.
20
 * This trait can only be used in the class extended from [[BaseEntityModel]],
21
 * [[BaseMongoEntityModel]], [[BaseRedisEntityModel]], or any other classes used
22
 * [[EntityTrait]].
23
 * This trait implements two methods `create()` and `findOneOrCreate()`.
24
 * Please read the notes of methods and used traits for further detailed usage.
25
 *
26
 * @version 1.0
27
 * @author vistart <[email protected]>
28
 */
29
trait UserTrait
30
{
31
    use PasswordTrait,
32
        RegistrationTrait,
33
        IdentityTrait;
34
35
    /**
36
     * Create new entity model associated with current user. The model to be created
37
     * must be extended from [[BaseBlameableModel]], [[BaseMongoBlameableModel]],
38
     * [[BaseRedisBlameableModel]], or any other classes used [[BlameableTrait]].
39
     * if $config does not specify `hostClass` property, self will be assigned to.
40
     * @param string $className Full qualified class name.
41
     * @param array $config name-value pairs that will be used to initialize
42
     * the object properties.
43
     * @param boolean $loadDefault Determines whether loading default values
44
     * after entity model created.
45
     * Notice! The [[\yii\mongodb\ActiveRecord]] and [[\yii\redis\ActiveRecord]]
46
     * does not support loading default value. If you want to assign properties
47
     * with default values, please define the `default` rule(s) for properties in
48
     * `rules()` method and return them by yourself if you don't specified them in config param.
49
     * @param boolean $skipIfSet whether existing value should be preserved.
50
     * This will only set defaults for attributes that are `null`.
51
     * @return [[$className]] new model created with specified configuration.
52
     *//*
53
    public function create($className, $config = [], $loadDefault = true, $skipIfSet = true)
54
    {
55
        if (!isset($config['hostClass'])) {
56
            $config['hostClass'] = static::class;
57
        }
58
        if (isset($config['class'])) {
59
            unset($config['class']);
60
        }
61
        $entity = new $className($config);
62
        $entity->setHost($this);
63
        if ($loadDefault && method_exists($entity, 'loadDefaultValues')) {
64
            $entity->loadDefaultValues($skipIfSet);
65
        }
66
        return $entity;
67
    }
68
    
69
    /**
70
     * This method is only used for overriding [[removeSelf()]] in [[TimestampTrait]].
71
     * @see deregister()
72
     * @return boolean
73
     */
74 4
    public function removeSelf()
75
    {
76 4
        return $this->deregister();
77
    }
78
79
    /**
80
     * Get all rules with current user properties.
81
     * @return array all rules.
82
     */
83 292
    public function rules()
84
    {
85 292
        return array_merge(
86 292
            parent::rules(),
87 292
            $this->getPasswordHashRules(),
88 292
            $this->getPasswordResetTokenRules(),
89 292
            $this->getSourceRules(),
90 292
            $this->getStatusRules(),
91 292
            $this->getAuthKeyRules(),
92 292
            $this->getAccessTokenRules()
93
        );
94
    }
95
    
96
    /**
97
     * Check whether the user is valid.
98
     * @param static $user User instance. The current logged-in user is automatically
0 ignored issues
show
The type UserTrait for parameter $user is a trait, and thus cannot be used for type-hinting in PHP. Maybe consider adding an interface and use that for type-hinting?
Loading history...
99
     * used if a user is logged in and this parameter is null.
100
     * @return static|false if current user is valid, it return as is, otherwise
101
     * false returned.
102
     * @throws InvalidParamException if the current user is not logged in and
103
     * the user is not a valid instance.
104
     */
105 2
    public static function isValid($user)
106
    {
107 2
        if (Yii::$app instanceof \yii\web\Application && !Yii::$app->user->isGuest)
108
        {
109 1
            return Yii::$app->user->identity;
110
        }
111 1
        if (!($user instanceof static)) {
112 1
            return false;
113
        }
114
        return $user->find()->guid($user)->exists() ? $user : false;
0 ignored issues
show
It seems like find() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
115
    }
116
}
117