Issues (34)

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/Traits/WithSearchableEncryptedAttribute.php (1 issue)

Labels
Severity

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 Bytesfield\KeyManager\Traits;
4
5
use Illuminate\Database\Eloquent\Builder;
6
use ParagonIE\CipherSweet\BlindIndex;
7
use ParagonIE\CipherSweet\CipherSweet;
8
use ParagonIE\CipherSweet\EncryptedField;
9
10
trait WithSearchableEncryptedAttribute
11
{
12
    protected EncryptedField $encryptedField;
0 ignored issues
show
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_STRING, expecting T_FUNCTION or T_CONST
Loading history...
13
14
    /**
15
     * Initialize the trait by setting up the searchable encryption algorithm.
16
     *
17
     * @throws \ParagonIE\CipherSweet\Exception\BlindIndexNameCollisionException
18
     * @throws \ParagonIE\CipherSweet\Exception\CryptoOperationException
19
     *
20
     * @return void
21
     */
22
    protected function initializeWithSearchableEncryptedAttribute(): void
23
    {
24
        $encryptedField = new EncryptedField(
25
            app(CipherSweet::class),
26
            $this->getTable(),
27
            $this->getEncryptedColumn()
28
        );
29
30
        $this->encryptedField = $encryptedField->addBlindIndex(
31
            new BlindIndex($this->getBlindIndexName(), [], 256, true)
32
        );
33
    }
34
35
    /**
36
     * Encrypts a value.
37
     *
38
     * @param string $value
39
     *
40
     * @return string
41
     */
42
    protected function encrypt(string $value): string
43
    {
44
        return $this->encryptedField->encryptValue($value);
45
    }
46
47
    /**
48
     * Decrypts a value.
49
     *
50
     * @param string $value
51
     *
52
     * @return string
53
     */
54
    protected function decrypt(string $value): string
55
    {
56
        return $this->encryptedField->decryptValue($value);
57
    }
58
59
    /**
60
     * Generates a build index hash using the value of the encrypted column.
61
     *
62
     * @throws \ParagonIE\CipherSweet\Exception\BlindIndexNotFoundException
63
     * @throws \ParagonIE\CipherSweet\Exception\CryptoOperationException
64
     * @throws \SodiumException
65
     *
66
     * @return string
67
     */
68
    protected function blindIndexValue(): string
69
    {
70
        return $this->getBlindIndexValueFor(
71
            (string) $this->getAttribute($this->getEncryptedColumn())
72
        );
73
    }
74
75
    /**
76
     * Generate a build index hash based on provided string value.
77
     *
78
     * @param string $string
79
     *
80
     * @throws \ParagonIE\CipherSweet\Exception\BlindIndexNotFoundException
81
     * @throws \ParagonIE\CipherSweet\Exception\CryptoOperationException
82
     * @throws \SodiumException
83
     *
84
     * @return string
85
     */
86
    protected function getBlindIndexValueFor(string $string): string
87
    {
88
        return $this->encryptedField->getBlindIndex($string, $this->getBlindIndexName());
89
    }
90
91
    /**
92
     * Query model by the build index hash of the provided value.
93
     *
94
     * @param \Illuminate\Database\Eloquent\Builder $query
95
     * @param string $value
96
     *
97
     * @throws \ParagonIE\CipherSweet\Exception\BlindIndexNotFoundException
98
     * @throws \ParagonIE\CipherSweet\Exception\CryptoOperationException
99
     * @throws \SodiumException
100
     *
101
     * @return \Illuminate\Database\Eloquent\Builder
102
     */
103
    public function scopeWhereBlindIndex(Builder $query, string $value): Builder
104
    {
105
        return $query->where($this->getBlindIndexColumn(), $this->getBlindIndexValueFor($value));
106
    }
107
108
    /**
109
     * Get the name of the build index. e.g api_keys_encrypted_hash_blind_index.
110
     *
111
     * @return string
112
     */
113
    protected function getBlindIndexName(): string
114
    {
115
        return $this->getTable().'_'.$this->getBlindIndexColumn().'_blind_index';
116
    }
117
118
    /**
119
     * Get the name of the attribute/column whose value is to be encrypted.
120
     *
121
     * @return string
122
     */
123
    protected function getEncryptedColumn(): string
124
    {
125
        return $this->encrypted ?? 'encrypted';
126
    }
127
128
    /**
129
     * Get the name of the attribute/column which is to be used to build and access the build index hash.
130
     *
131
     * @return string
132
     */
133
    protected function getBlindIndexColumn(): string
134
    {
135
        return $this->blindIndex ?? 'encrypted_hash';
136
    }
137
}
138