Issues (302)

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.

examples/Metrica/Management/counters.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
 * User: naxel
4
 * Date: 12.02.14 16:07
5
 */
6
7
use Yandex\Metrica\Management\ManagementClient;
8
9
10
$counters = array();
11
$errorMessage = false;
12
13
//Is auth
14 View Code Duplication
if (isset($_COOKIE['yaAccessToken']) && isset($_COOKIE['yaClientId'])) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
15
    $settings = require_once '../../settings.php';
16
17
    try {
18
        $managementClient = new ManagementClient($_COOKIE['yaAccessToken']);
19
20
        $paramsObj = new \Yandex\Metrica\Management\Models\CountersParams();
21
        $paramsObj
22
            /**
23
             * Тип счетчика. Возможные значения:
24
             * simple ― счетчик создан пользователем в Метрике;
25
             * partner ― счетчик импортирован из РСЯ.
26
             */
27
            ->setType(\Yandex\Metrica\Management\AvailableValues::TYPE_SIMPLE)
28
29
            /**
30
             * Один или несколько дополнительных параметров возвращаемого объекта
31
             */
32
            ->setField('goals,mirrors,grants,filters,operations');
33
34
        /**
35
         * @see http://api.yandex.ru/metrika/doc/beta/management/counters/counters.xml
36
         */
37
        $counters = $managementClient->counters()->getCounters($paramsObj)->getCounters();
38
    } catch (\Exception $ex) {
39
        $errorMessage = $ex->getMessage();
40
        if ($errorMessage === 'PlatformNotAllowed') {
41
            $errorMessage .= '<p>Возможно, у приложения нет прав на доступ к ресурсу. Попробуйте '
42
                . '<a href="' . rtrim(str_replace($_SERVER['DOCUMENT_ROOT'], '', __DIR__), "/") . '/../OAuth/' . '">авторизироваться</a> и повторить.</p>';
43
        }
44
    }
45
}
46
?>
47
<!doctype html>
48
<html lang="en-US">
49
<head>
50
    <meta charset="UTF-8">
51
    <title>Yandex.SDK: Metrica Demo</title>
52
53
    <link rel="stylesheet" href="//yandex.st/bootstrap/3.0.3/css/bootstrap.min.css">
54
    <link href="//netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.css" rel="stylesheet">
55
    <link rel="stylesheet" href="/examples/Disk/css/style.css">
56
57
</head>
58
<body>
59
60
<div class="container">
61
    <div class="jumbotron">
62
        <h2>
63
            <a href="/examples/Metrica"><span class="glyphicon glyphicon-tasks"></span></a>
64
            Пример работы с Яндекс Метрикой
65
        </h2>
66
    </div>
67
    <ol class="breadcrumb">
68
        <li><a href="/examples">Examples</a></li>
69
        <li><a href="/examples/Metrica">Metrica</a></li>
70
        <li class="active">Счетчики</li>
71
    </ol>
72
    <?php
73
    if (!isset($_COOKIE['yaAccessToken']) || !isset($_COOKIE['yaClientId'])) {
74
        ?>
75
        <div class="alert alert-info">
76
            Для просмотра этой страницы вам необходимо авторизироваться.
77
            <a id="goToAuth" href="/examples/OAuth" class="alert-link">Перейти на страницу авторизации</a>.
78
        </div>
79
    <?php
80
    } else {
81
        if ($errorMessage) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $errorMessage of type false|string is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== false instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
82
            ?>
83
            <div class="alert alert-danger"><?= $errorMessage ?></div>
84
        <?php
85
        } else {
86
            ?>
87
            <div>
88
                <h3>Счетчики:</h3>
89
                <table id="countersTable" class="table table-striped table-bordered table-hover">
90
                    <thead>
91
                    <tr>
92
                        <td>ID</td>
93
                        <td>Статус</td>
94
                        <td>Название</td>
95
                        <td>Сайт</td>
96
                        <td>Тип</td>
97
                        <td>Владелец</td>
98
                        <td>Права</td>
99
                        <td>Действия</td>
100
                        <td>Дополнения</td>
101
                    </tr>
102
                    </thead>
103
                    <tbody>
104
                    <?php
105
                    if ($counters instanceof Traversable) {
106
                        foreach ($counters as $counter) {
107
                            ?>
108
                            <tr data-counter-id="<?= $counter->getId() ?>">
109
                                <td><?= $counter->getId() ?></td>
110
                                <td><?= $counter->getCodeStatus() ?></td>
111
                                <td><?= $counter->getName() ?></td>
112
                                <td><?= $counter->getSite() ?></td>
113
                                <td><?= $counter->getType() ?></td>
114
                                <td><?= $counter->getOwnerLogin() ?></td>
115
                                <td><?= $counter->getPermission() ?></td>
116
                                <td style="text-align: center">
117
118
                                    <button type="button"
119
                                            class="btn btn-info showCounter">
120
                                        <span title="Открыть" class="glyphicon glyphicon-eye-open"></span>
121
                                    </button>
122
123
                                    <button type="button"
124
                                            class="btn btn-warning updateCounter">
125
                                        <span title="Изменить"
126
                                              class="glyphicon glyphicon-edit"></span>
127
                                    </button>
128
                                    <button type="button" class="btn btn-danger deleteCounter">
129
                                            <span title="Удалить"
130
                                                  class="glyphicon glyphicon-trash"></span>
131
                                    </button>
132
                                </td>
133
                                <td>
134
                                    <a href="/examples/Metrica/Management/filters.php?counter-id=<?= $counter->getId(
135
                                    ) ?>"
136
                                       class="btn btn-primary">Фильтры</a><br/>
137
                                    <a href="/examples/Metrica/Management/grants.php?counter-id=<?= $counter->getId(
138
                                    ) ?>"
139
                                       class="btn btn-success">Разрешения</a><br/>
140
                                    <a href="/examples/Metrica/Management/operations.php?counter-id=
141
                                       <?= $counter->getId() ?>"
142
                                       class="btn btn-info">Операции</a><br/>
143
                                    <a href="/examples/Metrica/Management/goals.php?counter-id=<?= $counter->getId() ?>"
144
                                       class="btn btn-warning">Цели</a>
145
                                </td>
146
                            </tr>
147
148
                        <?php
149
                        }
150
                    }
151
                    ?>
152
                    </tbody>
153
                </table>
154
                <button id="openAddCounterModal" type="button" class="btn btn-success">
155
                        <span title="Создать счетчик"
156
                              class="glyphicon glyphicon-plus"> Создать счетчик</span>
157
                </button>
158
            </div>
159
        <?php
160
        }
161
    }
162
    ?>
163
</div>
164
165
<!-- Modal -->
166
<div class="modal fade" id="errorModal" tabindex="-1" role="dialog" aria-hidden="true">
167
    <div class="modal-dialog">
168
        <div class="modal-content">
169
            <div class="modal-header">
170
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
171
                <h4 class="modal-title">Ошибка</h4>
172
            </div>
173
            <div class="modal-body">
174
                <div id="errorMessage"></div>
175
            </div>
176
            <div class="modal-footer">
177
                <button type="button" class="btn btn-default" data-dismiss="modal">Закрыть</button>
178
            </div>
179
        </div>
180
    </div>
181
</div>
182
183
<!-- Modal -->
184
<div class="modal fade" id="showCounterModal" tabindex="-1" role="dialog" aria-hidden="true">
185
    <div class="modal-dialog">
186
        <div class="modal-content">
187
            <div class="modal-header">
188
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
189
                <h4 class="modal-title">Просмотр Счетчика</h4>
190
            </div>
191
            <div class="modal-body">
192
                <p><label>ID:</label> <span id="showCounterId"></span></p>
193
194
                <p><label>Статус:</label> <span id="showCounterCodeStatus"></span></p>
195
196
                <p><label>Название:</label> <span id="showCounterName"></span></p>
197
198
                <p><label>Сайт:</label> <span id="showCounterSite"></span></p>
199
200
                <p><label>Тип:</label> <span id="showCounterType"></span></p>
201
202
                <p><label>Владелец:</label> <span id="showCounterOwnerLogin"></span></p>
203
204
                <p><label>Права:</label> <span id="showCounterPermission"></span></p>
205
206
                <div>
207
                    <label for="showCounterCode">Код счетчика для вставки:</label>
208
209
                    <p>
210
                        <textarea style="width: 100%" name="code" id="showCounterCode" cols="85" rows="10"></textarea>
211
                    </p>
212
                </div>
213
            </div>
214
            <div class="modal-footer">
215
                <button type="button" class="btn btn-default" data-dismiss="modal">Закрыть</button>
216
            </div>
217
        </div>
218
    </div>
219
</div>
220
221
222
<!-- Modal -->
223
<div class="modal fade" id="addCounterModal" tabindex="-1" role="dialog" aria-hidden="true">
224
    <div class="modal-dialog">
225
        <div class="modal-content">
226
            <div class="modal-header">
227
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
228
                <h4 class="modal-title">Создание счетчика</h4>
229
            </div>
230
            <div class="modal-body">
231
                <form class="form-horizontal" role="form">
232
                    <div class="form-group">
233
                        <label for="addCounterName" class="col-sm-2 control-label">Название</label>
234
235
                        <div class="col-sm-10">
236
                            <input type="text" class="form-control" id="addCounterName" placeholder="Название">
237
                        </div>
238
                    </div>
239
                    <div class="form-group">
240
                        <label for="addCounterSite" class="col-sm-2 control-label">Домен</label>
241
242
                        <div class="col-sm-10">
243
                            <input type="text" class="form-control" id="addCounterSite" placeholder="Домен">
244
                        </div>
245
                    </div>
246
                </form>
247
            </div>
248
            <div class="modal-footer">
249
                <button type="button" class="btn btn-default" data-dismiss="modal">Закрыть</button>
250
                <button type="button" id="createCounter" class="btn btn-primary">Создать</button>
251
            </div>
252
        </div>
253
    </div>
254
</div>
255
256
257
<!-- Modal -->
258
<div class="modal fade" id="updateCounterModal" tabindex="-1" role="dialog" aria-hidden="true">
259
    <div class="modal-dialog">
260
        <div class="modal-content">
261
            <div class="modal-header">
262
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
263
                <h4 class="modal-title">Редактирование счетчика</h4>
264
            </div>
265
            <div class="modal-body">
266
                <form class="form-horizontal" role="form">
267
                    <input type="hidden" id="updateCounterId">
268
269
                    <div class="form-group">
270
                        <label for="updateCounterName" class="col-sm-2 control-label">Название</label>
271
272
                        <div class="col-sm-10">
273
                            <input type="text" class="form-control" id="updateCounterName" placeholder="Название">
274
                        </div>
275
                    </div>
276
                    <div class="form-group">
277
                        <label for="updateCounterSite" class="col-sm-2 control-label">Домен</label>
278
279
                        <div class="col-sm-10">
280
                            <input type="text" class="form-control" id="updateCounterSite" placeholder="Домен">
281
                        </div>
282
                    </div>
283
                </form>
284
            </div>
285
            <div class="modal-footer">
286
                <button type="button" class="btn btn-default" data-dismiss="modal">Закрыть</button>
287
                <button type="button" id="saveCounter" class="btn btn-primary">Сохранить</button>
288
            </div>
289
        </div>
290
    </div>
291
</div>
292
293
294
<!-- Modal -->
295
<div class="modal fade" id="deleteCounterModal" tabindex="-1" role="dialog" aria-hidden="true">
296
    <div class="modal-dialog">
297
        <div class="modal-content">
298
            <div class="modal-header">
299
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
300
                <h4 class="modal-title">Удалить счетчик?</h4>
301
            </div>
302
            <div class="modal-body">
303
                <input type="hidden" id="deleteCounterId">
304
            </div>
305
            <div class="modal-footer">
306
                <button type="button" class="btn btn-default" data-dismiss="modal">Отмена</button>
307
                <button type="button" id="deleteCounter" class="btn btn-danger">Удалить!</button>
308
            </div>
309
        </div>
310
    </div>
311
</div>
312
313
<script src="http://yandex.st/jquery/2.0.3/jquery.min.js"></script>
314
<script src="http://yandex.st/jquery/cookie/1.0/jquery.cookie.min.js"></script>
315
<script src="http://yandex.st/bootstrap/3.0.3/js/bootstrap.min.js"></script>
316
317
<script>
318
$(function () {
319
320
    $('#goToAuth').click(function (e) {
321
        $.cookie('back', location.href, { expires: 256, path: '/' });
322
    });
323
324
    var $countersTable = $("#countersTable");
325
326
    $countersTable.on('click', '.showCounter', function () {
327
        var $el = $(this);
328
        var counterId = $el.parents('tr').data('counter-id');
329
330
        $.get(
331
            "/examples/Metrica/api.php",
332
            {
333
                method: 'getCounter',
334
                counterId: counterId
335
            },
336
            function (data) {
337
                var response = JSON.parse(data);
338
                if (response.status === 'ok' && response.result !== null) {
339
340
                    $('#showCounterId').text(response.result.id);
341
                    $('#showCounterCodeStatus').text(response.result.code_status);
342
                    $('#showCounterName').text(response.result.name);
343
                    $('#showCounterSite').text(response.result.site);
344
                    $('#showCounterType').text(response.result.type);
345
                    $('#showCounterOwnerLogin').text(response.result.owner_login);
346
                    $('#showCounterPermission').text(response.result.permission);
347
                    $('#showCounterCode').text(response.result.code);
348
349
                    $('#showCounterModal').modal('show');
350
                } else {
351
                    displayError(response.message);
352
                }
353
            }
354
        );
355
    });
356
357
358
    $('#openAddCounterModal').click(function () {
359
        $('form.form-horizontal').get(0).reset();
360
        $('#addCounterModal').modal('show');
361
    });
362
363
    $countersTable.on('click', '.updateCounter', function () {
364
        var $el = $(this);
365
        var counterId = $el.parents('tr').data('counter-id');
366
367
        $.get(
368
            "/examples/Metrica/api.php",
369
            {
370
                method: 'getCounter',
371
                counterId: counterId
372
            },
373
            function (data) {
374
                var response = JSON.parse(data);
375
                if (response.status === 'ok' && response.result !== null) {
376
                    $('#updateCounterId').val(response.result.id);
377
                    $('#updateCounterName').val(response.result.name);
378
                    $('#updateCounterSite').val(response.result.site);
379
380
                    $('#updateCounterModal').modal('show');
381
                } else {
382
                    displayError(response.message);
383
                }
384
            }
385
        );
386
    });
387
388
389
    $countersTable.on('click', '.deleteCounter', function () {
390
        var $el = $(this);
391
        var counterId = $el.parents('tr').data('counter-id');
392
        $('#deleteCounterId').val(counterId);
393
        $('#deleteCounterModal').modal('show');
394
    });
395
396
397
    $('#createCounter').click(function () {
398
        var counterName = $.trim($('#addCounterName').val());
399
        var counterSite = $.trim($('#addCounterSite').val());
400
401
        if (counterName.length === 0 || counterSite.length === 0) {
402
            alert('Заполните поле названия счетчика и/или домен.');
403
        }
404
405
        $.post(
406
            "/examples/Metrica/api.php",
407
            {
408
                method: 'addCounter',
409
                counterSite: counterSite,
410
                counterName: counterName
411
            },
412
            function (data) {
413
                $('#addCounterModal').modal('hide');
414
415
                var response = JSON.parse(data);
416
                if (response.status === 'ok' && response.result !== null) {
417
418
                    var html = '\
419
                            <tr data-counter-id="' + response.result.id + '">\
420
                                <td>' + response.result.id + '</td>\
421
                                <td>' + response.result.code_status + '</td>\
422
                                <td>' + response.result.name + '</td>\
423
                                <td>' + response.result.site + '</td>\
424
                                <td>' + response.result.type + '</td>\
425
                                <td>' + response.result.owner_login + '</td>\
426
                                <td>' + response.result.permission + '</td>\
427
                                <td style="text-align: center">\
428
                                    <button type="button" class="btn btn-info showCounter">\
429
                                        <span title="Открыть" class="glyphicon glyphicon-eye-open"></span>\
430
                                    </button>\
431
                                    <button type="button" class="btn btn-warning updateCounter">\
432
                                        <span title="Изменить" class="glyphicon glyphicon-edit"></span>\
433
                                    </button>\
434
                                    <button type="button" class="btn btn-danger deleteCounter">\
435
                                            <span title="Удалить" class="glyphicon glyphicon-trash "></span>\
436
                                    </button>\
437
                                </td>\
438
                                <td>\
439
                                    <a href="/examples/Metrica/Management/filters.php?counter-id=' + response.result.id + '" class="btn btn-primary">Фильтры</a><br />\
440
                                    <a href="/examples/Metrica/Management/grants.php?counter-id=' + response.result.id + '" class="btn btn-success">Разрешения</a><br />\
441
                                    <a href="/examples/Metrica/Management/operations.php?counter-id=' + response.result.id + '" class="btn btn-info">Операции</a><br />\
442
                                    <a href="/examples/Metrica/Management/goals.php?counter-id=' + response.result.id + '" class="btn btn-warning">Цели</a>\
443
                                </td>\
444
                            </tr>';
445
446
                    $countersTable.find('tbody').append(html);
447
448
449
                } else {
450
                    displayError(response.message);
451
                }
452
            }
453
        );
454
    });
455
456
457
    $('#saveCounter').click(function () {
458
        var counterName = $.trim($('#updateCounterName').val());
459
        var counterSite = $.trim($('#updateCounterSite').val());
460
        var counterId = $.trim($('#updateCounterId').val());
461
462
        if (counterName.length === 0 || counterSite.length === 0) {
463
            alert('Заполните поле названия счетчика и/или домен.');
464
        }
465
466
        $.post(
467
            "/examples/Metrica/api.php",
468
            {
469
                method: 'updateCounter',
470
                counterId: counterId,
471
                counterSite: counterSite,
472
                counterName: counterName
473
            },
474
            function (data) {
475
476
                $('#updateCounterModal').modal('hide');
477
478
                var response = JSON.parse(data);
479
                if (response.status === 'ok' && response.result !== null) {
480
481
                    var html = '\
482
                            <tr data-counter-id="' + response.result.id + '">\
483
                                <td>' + response.result.id + '</td>\
484
                                <td>' + response.result.code_status + '</td>\
485
                                <td>' + response.result.name + '</td>\
486
                                <td>' + response.result.site + '</td>\
487
                                <td>' + response.result.type + '</td>\
488
                                <td>' + response.result.owner_login + '</td>\
489
                                <td>' + response.result.permission + '</td>\
490
                                <td style="text-align: center">\
491
                                    <button type="button" class="btn btn-info showCounter">\
492
                                        <span title="Открыть" class="glyphicon glyphicon-eye-open"></span>\
493
                                    </button>\
494
                                    <button type="button" class="btn btn-warning updateCounter">\
495
                                        <span title="Изменить" class="glyphicon glyphicon-edit"></span>\
496
                                    </button>\
497
                                    <button type="button" class="btn btn-danger deleteCounter">\
498
                                            <span title="Удалить" class="glyphicon glyphicon-trash"></span>\
499
                                    </button>\
500
                                </td>\
501
                                <td>\
502
                                    <a href="/examples/Metrica/Management/filters.php?counter-id=' + response.result.id + '" class="btn btn-primary">Фильтры</a><br />\
503
                                    <a href="/examples/Metrica/Management/grants.php?counter-id=' + response.result.id + '" class="btn btn-success">Разрешения</a><br />\
504
                                    <a href="/examples/Metrica/Management/operations.php?counter-id=' + response.result.id + '" class="btn btn-info">Операции</a><br />\
505
                                    <a href="/examples/Metrica/Management/goals.php?counter-id=' + response.result.id + '" class="btn btn-warning">Цели</a>\
506
                                </td>\
507
                            </tr>';
508
509
                    $("#countersTable").find('tbody>tr').each(function () {
510
                        if ($(this).data('counter-id') == response.result.id) {
511
                            $(this).replaceWith(html);
512
                        }
513
                    });
514
515
                } else {
516
                    displayError(response.message);
517
                }
518
            }
519
        );
520
    });
521
522
523
    $('#deleteCounter').click(function () {
524
525
        var counterId = $.trim($('#deleteCounterId').val());
526
        $.post(
527
            "/examples/Metrica/api.php",
528
            {
529
                method: 'deleteCounter',
530
                counterId: counterId
531
            },
532
            function (data) {
533
534
                $('#deleteCounterModal').modal('hide');
535
536
                var response = JSON.parse(data);
537
                if (response.status === 'ok' && response.result !== null) {
538
539
                    $("#countersTable").find('tbody>tr').each(function () {
540
                        if ($(this).data('counter-id') == response.result.id) {
541
                            $(this).replaceWith('');
542
                        }
543
                    });
544
545
                } else {
546
                    displayError(response.message);
547
                }
548
            }
549
        );
550
    });
551
552
});
553
554
555
/**
556
 * @param message string
557
 */
558
function displayError(message) {
559
    $('#errorMessage').text(message);
560
    $('#errorModal').modal('show');
561
}
562
563
</script>
564
</body>
565
</html>
566