Issues (102)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  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.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  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.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  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.
  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.
  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.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
  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.
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  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.
  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.
  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.
  Header Injection
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.

models/redis/Token.php (7 issues)

1
<?php
2
3
namespace yrc\models\redis;
4
5
use Base32\Base32;
6
use ncryptf\Token as NcryptfToken;
7
use yrc\redis\ActiveRecord;
8
use Yii;
9
10
/**
11
 * Abstract class for generating and storing tokens
12
 * @property integer $id
13
 * @property integer $user_id
14
 * @property string $access_token
15
 * @property string $refresh_token
16
 * @property string $ikm
17
 * @property string $secret_sign_key
18
 * @property integer $expires_at
19
 */
20
abstract class Token extends ActiveRecord
21
{
22
    /**
23
     * This is our default token lifespan
24
     * @const TOKEN_EXPIRATION_TIME
25
     */
26
    const TOKEN_EXPIRATION_TIME = '+15 minutes';
27
28
    /**
29
     * The refresh token class
30
     */
31
    const REFRESH_TOKEN_CLASS = '\app\models\RefreshToken';
32
33
    /**
34
     * @inheritdoc
35
     */
36
    public function attributes()
37
    {
38
        return [
39
            'id',
40
            'user_id',
41
            'access_token',
42
            'refresh_token',
43
            'ikm',
44
            'secret_sign_kp',
45
            'expires_at'
46
        ];
47
    }
48
49
    /**
50
     * @return sodium_crypto_sign_keypair
0 ignored issues
show
The type yrc\models\redis\sodium_crypto_sign_keypair was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
51
     */
52
    public function getSignKeyPair()
53
    {
54
        $secret = \base64_decode($this->secret_sign_kp);
0 ignored issues
show
Bug Best Practice introduced by
The property secret_sign_kp does not exist on yrc\models\redis\Token. Since you implemented __get, consider adding a @property annotation.
Loading history...
55
        $public = sodium_crypto_sign_publickey_from_secretkey($secret);
56
        return sodium_crypto_sign_keypair_from_secretkey_and_publickey($secret, $public);
0 ignored issues
show
Bug Best Practice introduced by
The expression return sodium_crypto_sig...ickey($secret, $public) returns the type string which is incompatible with the documented return type yrc\models\redis\sodium_crypto_sign_keypair.
Loading history...
57
    }
58
59
    /**
60
     * @return sodium_crypto_sign_publickey
0 ignored issues
show
The type yrc\models\redis\sodium_crypto_sign_publickey was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
61
     */
62
    public function getSignPublicKey()
63
    {
64
        return sodium_crypto_sign_publickey($this->getSignKeyPair());
0 ignored issues
show
Bug Best Practice introduced by
The expression return sodium_crypto_sig...this->getSignKeyPair()) returns the type string which is incompatible with the documented return type yrc\models\redis\sodium_crypto_sign_publickey.
Loading history...
65
    }
66
67
    /**
68
     * Generates a new auth and refresh token pair
69
     * @param int $userId
70
     * @return array
71
     */
72
    public static function generate($userId = null)
73
    {
74
        $model = null;
0 ignored issues
show
The assignment to $model is dead and can be removed.
Loading history...
75
        $signKp = sodium_crypto_sign_keypair();
76
77
        $user = Yii::$app->user->identityClass::findOne(['id' => $userId]);
78
        if ($user === null) {
79
            throw new \yii\base\Exception('Invalid user');
80
        }
81
       
82
        $token = new static;
83
        $token->setAttributes([
84
            'user_id' => $user->id,
85
            'access_token' => \str_replace('=', '', Base32::encode(\random_bytes(32))),
86
            'refresh_token' => (static::REFRESH_TOKEN_CLASS)::create($user),
87
            'ikm' => \base64_encode(\random_bytes(32)),
88
            'secret_sign_kp' => \base64_encode(sodium_crypto_sign_secretkey($signKp)),
89
            'expires_at' => \strtotime(static::TOKEN_EXPIRATION_TIME)
90
        ], false);
91
92
        if ($token->save()) {
93
            return $token;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $token returns the type yrc\models\redis\Token which is incompatible with the documented return type array.
Loading history...
94
        }
95
            
96
        throw new \yii\base\Exception(Yii::t('yrc', 'Token failed to save'));
97
    }
98
99
    /**
100
     * Returns an ncryptf compatible token
101
     *
102
     * @return \ncryptf\Token
103
     */
104
    public function getNcryptfToken()
105
    {
106
        $attributes = $this->getAuthResponse();
107
        return new NcryptfToken(
108
            $attributes['access_token'],
109
            $attributes['refresh_token'],
110
            \base64_decode($attributes['ikm']),
111
            \base64_decode($attributes['signing']),
112
            $attributes['expires_at']
113
        );
114
    }
115
116
    /**
117
     * Helper method to get the auth response data
118
     * @return array
119
     */
120
    public function getAuthResponse()
121
    {
122
        $attributes = $this->getAttributes();
123
        unset($attributes['id']);
124
125
        $attributes['signing'] = $attributes['secret_sign_kp'];
126
        unset($attributes['secret_sign_kp']);
127
        return $attributes;
128
    }
129
}
130