Issues (29)

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/librariesio/ProjectDataProvider.php (3 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
 * Asset Packagist.
4
 *
5
 * @link      https://github.com/hiqdev/asset-packagist
6
 * @package   asset-packagist
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2016-2017, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hiqdev\assetpackagist\librariesio;
12
13
use GuzzleHttp\Psr7\Response;
14
use Yii;
15
use yii\caching\Cache;
16
use yii\data\BaseDataProvider;
17
use yii\di\Instance;
18
use yii\helpers\Json;
19
20
class ProjectDataProvider extends BaseDataProvider
21
{
22
    public $query;
23
    public $platform;
24
25
    /**
26
     * Enable cache to search results, false to disable
27
     * Cache is used to prevent rate limit.
28
     * @see https://libraries.io/api/#rate-limit
29
     * @var string|Cache|false
30
     */
31
    public $cache = 'cache';
32
33
    /**
34
     * @var int number of seconds that search result can remain valid in cache
35
     */
36
    public $cacheDuration = 600;
37
38
    /**
39
     * @var string|LibrariesioRepository
40
     */
41
    public $repository = 'librariesio';
42
43
    /**
44
     * @var int Total count from last request
45
     */
46
    protected $lastTotalCount = 0;
47
48
    public function init()
49
    {
50
        parent::init();
51
52
        if ($this->cache) {
53
            $this->cache = Instance::ensure($this->cache, Cache::className());
0 ignored issues
show
Deprecated Code introduced by
The method yii\base\BaseObject::className() has been deprecated with message: since 2.0.14. On PHP >=5.5, use `::class` instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
54
        }
55
        $this->repository = Instance::ensure($this->repository, LibrariesioRepository::className());
0 ignored issues
show
Deprecated Code introduced by
The method yii\base\BaseObject::className() has been deprecated with message: since 2.0.14. On PHP >=5.5, use `::class` instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
56
    }
57
58
    protected function prepareModels()
59
    {
60
        if (!$this->platform) {
61
            $this->platform = 'bower,npm';
62
        }
63
        if (is_array($this->platform)) {
64
            $this->platform = implode(',', $this->platform);
65
        }
66
67
        $query = [
68
            'q'         => $this->query,
69
            'platforms' => $this->platform,
70
        ];
71
72
        if (($sort = $this->getSort()) !== false) {
73
            foreach ($sort->getOrders() as $sort => $order) {
74
                $query['sort'] = $sort;
75
                $query['order'] = ($order === SORT_ASC) ? 'asc' : 'desc';
76
                break;
77
            }
78
        }
79
80
        if (($pagination = $this->getPagination()) !== false) {
81
            /**
82
             * Not use '$pagination->getPage()' because need define 'totalCount' first
83
             * totalCount is defined after request.
84
             */
85
            $page = (int) Yii::$app->getRequest()->getQueryParam($pagination->pageParam, 1);
86
            if ($page > 1) {
87
                $query['page'] = $page;
88
            }
89
90
            $query['per_page'] = $pagination->getPageSize();
91
        }
92
93
        $cacheKey = [static::className(), 'query' => $query];
0 ignored issues
show
Deprecated Code introduced by
The method yii\base\BaseObject::className() has been deprecated with message: since 2.0.14. On PHP >=5.5, use `::class` instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
94
95
        $items = [];
96
        $totalCount = 0;
97
98
        if ($this->cache && $this->cache->exists($cacheKey)) {
99
            list($totalCount, $items) = $this->cache->get($cacheKey);
100
        } else {
101
            /* @var $response Response */
102
            $response = $this->repository->search($query);
103
104
            if ($response->getStatusCode() !== 200) {
105
                return [];
106
            }
107
108
            $totalCount = (int) $response->getHeaderLine('total');
109
            $items = Json::decode($response->getBody());
110
111
            if ($this->cache) {
112
                $this->cache->set($cacheKey, [$totalCount, $items], $this->cacheDuration);
113
            }
114
        }
115
116
        $this->lastTotalCount = $totalCount;
117
118
        if (($pagination = $this->getPagination()) !== false) {
119
            $pagination->totalCount = $this->lastTotalCount;
120
        }
121
122
        $models = [];
123
124
        foreach ($items as $item) {
125
            $models[] = new Project(['attributes' => $item]);
126
        }
127
128
        return $models;
129
    }
130
131
    /**
132
     * @param Project[] $models
133
     * @return array
134
     */
135
    protected function prepareKeys($models)
136
    {
137
        $keys = [];
138
139
        foreach ($models as $model) {
140
            $keys[] = [
141
                'name'     => $model->name,
142
                'platform' => $model->name,
143
            ];
144
        }
145
146
        return $keys;
147
    }
148
149
    protected function prepareTotalCount()
150
    {
151
        $this->prepare();
152
        return $this->lastTotalCount;
153
    }
154
155
    public function setSort($value)
156
    {
157
        /**
158
         * Override the default attributes to sort.
159
         */
160
        if (is_array($value)) {
161
            $value = array_merge([
162
                'attributes' => [
163
                    'Rank'                        => 'rank',
164
                    'Stars'                       => 'stars',
165
                    'Dependents Count'            => 'dependents_count',
166
                    'Dependent Repos Count'       => 'dependent_repos_count',
167
                    'Latest Release Published At' => 'latest_release_published_at',
168
                    'Created At'                  => 'created_at',
169
                    'Contributions Count'         => 'contributions_count',
170
                ], ], $value);
171
        }
172
173
        parent::setSort($value);
174
    }
175
}
176