Issues (44)

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/Helpers.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 Arrilot\BitrixModels;
4
5
use Arrilot\BitrixModels\Models\BaseBitrixModel;
6
use Illuminate\Support\Collection;
7
8
class Helpers
9
{
10
    /**
11
     * Does the $haystack starts with $needle
12
     *
13
     * @param $haystack
14
     * @param $needle
15
     * @return bool
16
     */
17
    public static function startsWith($haystack, $needle)
18
    {
19
        return strncmp($haystack, $needle, strlen($needle)) === 0;
20
    }
21
    
22
    /**
23
     * @param Collection|BaseBitrixModel[] $primaryModels первичные модели
24
     * @param Collection|BaseBitrixModel[] $relationModels подгруженные связанные модели
25
     * @param string $primaryKey ключ связи в первичной модели
26
     * @param string $relationKey ключ связи в связанной модели
27
     * @param string $relationName название связи в первичной модели
28
     * @param bool $multiple множественная ли это свзязь
29
     */
30
    public static function assocModels($primaryModels, $relationModels, $primaryKey, $relationKey, $relationName, $multiple)
31
    {
32
        $buckets = static::buildBuckets($relationModels, $relationKey, $multiple);
0 ignored issues
show
It seems like $relationModels defined by parameter $relationModels on line 30 can also be of type object<Illuminate\Support\Collection>; however, Arrilot\BitrixModels\Helpers::buildBuckets() does only seem to accept array, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
33
        
34
        foreach ($primaryModels as $i => $primaryModel) {
35
            if ($multiple && is_array($keys = $primaryModel[$primaryKey])) {
36
                $value = [];
37
                foreach ($keys as $key) {
38
                    $key = static::normalizeModelKey($key);
39
                    if (isset($buckets[$key])) {
40
                        $value = array_merge($value, $buckets[$key]);
41
                    }
42
                }
43
            } else {
44
                $key = static::normalizeModelKey($primaryModel[$primaryKey]);
45
                $value = isset($buckets[$key]) ? $buckets[$key] : ($multiple ? [] : null);
46
            }
47
            
48
            $primaryModel->populateRelation($relationName, is_array($value) ? (new Collection($value))->keyBy(function ($item) {return $item->id;}) : $value);
49
        }
50
    }
51
    
52
    /**
53
     * Сгруппировать найденные модели
54
     * @param array $models
55
     * @param string $linkKey
56
     * @param bool $multiple
57
     * @return array
58
     */
59
    protected static function buildBuckets($models, $linkKey, $multiple)
60
    {
61
        $buckets = [];
62
        
63
        foreach ($models as $model) {
64
            $key = $model[$linkKey];
65
            if (is_scalar($key)) {
66
                $buckets[$key][] = $model;
67
            } elseif (is_array($key)){
68
                foreach ($key as $k) {
69
                    $k = static::normalizeModelKey($k);
70
                    $buckets[$k][] = $model;
71
                }
72
            } else {
73
                $key = static::normalizeModelKey($key);
74
                $buckets[$key][] = $model;
75
            }
76
        }
77
        
78
        if (!$multiple) {
79
            foreach ($buckets as $i => $bucket) {
80
                $buckets[$i] = reset($bucket);
81
            }
82
        }
83
        
84
        return $buckets;
85
    }
86
    
87
    /**
88
     * @param mixed $value raw key value.
89
     * @return string normalized key value.
90
     */
91
    protected static function normalizeModelKey($value)
92
    {
93
        if (is_object($value) && method_exists($value, '__toString')) {
94
            // ensure matching to special objects, which are convertable to string, for cross-DBMS relations, for example: `|MongoId`
95
            $value = $value->__toString();
96
        }
97
        
98
        return $value;
99
    }
100
}
101