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/grants.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
 * User: Tanya Kalashnik
4
 * Date: 15.07.14 18:18
5
 */
6
7
use Yandex\Metrica\Management\ManagementClient;
8
9
$grants = array();
10
$errorMessage = false;
11
$counterId = null;
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
18
    try {
19
        $managementClient = new ManagementClient($_COOKIE['yaAccessToken']);
20
21
        if (isset($_GET['counter-id']) && $_GET['counter-id']) {
22
            $counterId = $_GET['counter-id'];
23
            //GET /management/v1/counter/{counterId}/grants;
24
    
25
            /**
26
             * @see http://api.yandex.ru/metrika/doc/beta/management/grants/grants.xml
27
             */
28
            $grants = $managementClient->grants()->getGrants($counterId);
29
        }
30
    } catch (\Exception $ex) {
31
        $errorMessage = $ex->getMessage();
32
        if ($errorMessage === 'PlatformNotAllowed') {
33
            $errorMessage .= '<p>Возможно, у приложения нет прав на доступ к ресурсу. Попробуйте '
34
                . '<a href="' . rtrim(str_replace($_SERVER['DOCUMENT_ROOT'], '', __DIR__), "/") . '/../OAuth/' . '">авторизироваться</a> и повторить.</p>';
35
        }
36
    }
37
}
38
?>
39
<!doctype html>
40
<html lang="en-US">
41
<head>
42
    <meta charset="UTF-8">
43
    <title>Yandex.SDK: Metrica Demo</title>
44
45
    <link rel="stylesheet" href="//yandex.st/bootstrap/3.0.3/css/bootstrap.min.css">
46
    <link href="//netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.css" rel="stylesheet">
47
    <link rel="stylesheet" href="/examples/Disk/css/style.css">
48
49
</head>
50
<body>
51
52
<div class="container">
53
    <div class="jumbotron">
54
        <h2><a href="/examples/Metrica"><span class="glyphicon glyphicon-tasks"></span></a> Пример работы с Яндекс Метрикой</h2>
55
    </div>
56
    <ol class="breadcrumb">
57
        <li><a href="/examples">Examples</a></li>
58
        <li><a href="/examples/Metrica">Metrica</a></li>
59
        <li><a href="/examples/Metrica/Management/counters.php">Счетчики</a></li>
60
        <li class="active">Разрешения</li>
61
    </ol>
62
    <?php
63 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...
64
        ?>
65
        <div class="alert alert-info">
66
            Для просмотра этой страницы вам необходимо авторизироваться.
67
            <a id="goToAuth" href="/examples/OAuth" class="alert-link">Перейти на страницу авторизации</a>.
68
        </div>
69
    <?php
70
    } else {
71
        if ($errorMessage) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $errorMessage of type string|false 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...
72
            ?>
73
            <div class="alert alert-danger"><?= $errorMessage ?></div>
74
        <?php
75
        } else {
76
            ?>
77
            <div>
78
                <h3>Разрешения:</h3>
79
                <table id="grantTable" class="table table-striped table-bordered table-hover">
80
                    <thead>
81
                    <tr>
82
                        <td>Логин пользователя</td>
83
                        <td>Уровень доступа</td>
84
                        <td>Дата предоставления доступа</td>
85
                        <td>Комментарий</td>
86
                    </tr>
87
                    </thead>
88
                    <tbody>
89
                    <?php
90
                    if ($grants instanceof Traversable) {
91
                        foreach ($grants as $grant) {
92
                            ?>
93
                            <tr data-user-login="<?= $grant->getUserLogin() ?>">
94
                                <td><?= $grant->getUserLogin() ?></td>
95
                                <td><?= $grant->getPerm() ?></td>
96
                                <td><?= $grant->getCreatedAt() ?></td>
97
                                <td><?= $grant->getComment() ?></td>
98
                                <td style="text-align: center">
99
100
                                    <button type="button"
101
                                            class="btn btn-info showGrant">
102
                                        <span title="Открыть" class="glyphicon glyphicon-eye-open"></span>
103
                                    </button>
104
105
                                    <button type="button"
106
                                            class="btn btn-warning updateGrant">
107
                                        <span title="Изменить"
108
                                              class="glyphicon glyphicon-edit"></span>
109
                                    </button>
110
                                    <button type="button" class="btn btn-danger deleteGrant">
111
                                            <span title="Удалить"
112
                                                  class="glyphicon glyphicon-trash"></span>
113
                                    </button>
114
                                </td>
115
                            </tr>
116
                        <?php
117
                        }
118
                    }
119
                    ?>
120
                    </tbody>
121
                </table>
122
                <button id="openAddGrantModal" type="button" class="btn btn-success">
123
                        <span title="Создать счетчик"
124
                              class="glyphicon glyphicon-plus"> Создать разрешение</span>
125
                </button>
126
            </div>
127
        <?php
128
        }
129
    }
130
    ?>
131
</div>
132
133
<!-- Modal -->
134
<div class="modal fade" id="errorModal" tabindex="-1" role="dialog" aria-hidden="true">
135
    <div class="modal-dialog">
136
        <div class="modal-content">
137
            <div class="modal-header">
138
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
139
                <h4 class="modal-title">Ошибка</h4>
140
            </div>
141
            <div class="modal-body">
142
                <div id="errorMessage"></div>
143
            </div>
144
            <div class="modal-footer">
145
                <button type="button" class="btn btn-default" data-dismiss="modal">Закрыть</button>
146
            </div>
147
        </div>
148
    </div>
149
</div>
150
151
<!-- Modal -->
152
<div class="modal fade" id="showGrantModal" tabindex="-1" role="dialog" aria-hidden="true">
153
    <div class="modal-dialog">
154
        <div class="modal-content">
155
            <div class="modal-header">
156
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
157
                <h4 class="modal-title">Просмотр разрешения</h4>
158
            </div>
159
            <div class="modal-body">
160
                <p><label>Логин пользователя:</label> <span id="showGrantUserLogin"></span></p>
161
162
                <p><label>Уровень доступа:</label> <span id="showGrantPerm"></span></p>
163
164
                <p><label>Дата предоставления доступа:</label> <span id="showGrantCreateAt"></span></p>
165
166
                <p><label>Комментарий:</label> <span id="showGrantComment"></span></p>
167
            </div>
168
            <div class="modal-footer">
169
                <button type="button" class="btn btn-default" data-dismiss="modal">Закрыть</button>
170
            </div>
171
        </div>
172
    </div>
173
</div>
174
175
176
<!-- Modal -->
177
<div class="modal fade" id="addGrantModal" tabindex="-1" role="dialog" aria-hidden="true">
178
    <div class="modal-dialog">
179
        <div class="modal-content">
180
            <div class="modal-header">
181
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
182
                <h4 class="modal-title">Создание разрешения</h4>
183
            </div>
184
            <div class="modal-body">
185
                <form class="form-horizontal" role="form">
186
                    <div class="form-group">
187
                        <label for="addGrantUserLogin" class="col-sm-2 control-label">Логин пользователя</label>
188
189
                        <div class="col-sm-10">
190
                            <input type="text" class="form-control" id="addGrantUserLogin" placeholder="Логин пользователя">
191
                        </div>
192
                    </div>
193
                    <div class="form-group">
194
                        <label for="addGrantPerm" class="col-sm-2 control-label">Уровень доступа</label>
195
196
                        <div class="col-sm-10">
197
                            <input type="text" class="form-control" id="addGrantPerm" placeholder="Уровень доступа">
198
                        </div>
199
                    </div>
200
                    <div class="form-group">
201
                        <label for="addGrantCreateAt" class="col-sm-2 control-label">Дата предоставления доступа</label>
202
203
                        <div class="col-sm-10">
204
                            <input type="text" class="form-control" id="addGrantCreateAt" placeholder="Дата предоставления доступа">
205
                        </div>
206
                    </div>
207
                    <div class="form-group">
208
                        <label for="addGrantComment" class="col-sm-2 control-label">Комментарий</label>
209
210
                        <div class="col-sm-10">
211
                            <input type="text" class="form-control" id="addGrantComment" placeholder="Комментарий">
212
                        </div>
213
                    </div>
214
                </form>
215
            </div>
216
            <div class="modal-footer">
217
                <button type="button" class="btn btn-default" data-dismiss="modal">Закрыть</button>
218
                <button type="button" id="createGrant" class="btn btn-primary">Создать</button>
219
            </div>
220
        </div>
221
    </div>
222
</div>
223
224
225
<!-- Modal -->
226
<div class="modal fade" id="updateGrantModal" tabindex="-1" role="dialog" aria-hidden="true">
227
    <div class="modal-dialog">
228
        <div class="modal-content">
229
            <div class="modal-header">
230
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
231
                <h4 class="modal-title">Редактирование разрешения</h4>
232
            </div>
233
            <div class="modal-body">
234
                <form class="form-horizontal" role="form">
235
                    <div class="form-group">
236
                        <label for="updateGrantUserLogin" class="col-sm-2 control-label">Логин пользователя</label>
237
238
                        <div class="col-sm-10">
239
                            <input type="text" class="form-control" id="updateGrantUserLogin" placeholder="Логин пользователя">
240
                        </div>
241
                    </div>
242
                    <div class="form-group">
243
                        <label for="updateGrantPerm" class="col-sm-2 control-label">Уровень доступа</label>
244
245
                        <div class="col-sm-10">
246
                            <input type="text" class="form-control" id="updateGrantPerm" placeholder="Уровень доступа">
247
                        </div>
248
                    </div>
249
                    <div class="form-group">
250
                        <label for="updateGrantCreateAt" class="col-sm-2 control-label">Дата предоставления доступа</label>
251
252
                        <div class="col-sm-10">
253
                            <input type="text" class="form-control" id="updateGrantCreateAt" placeholder="Дата предоставления доступа">
254
                        </div>
255
                    </div>
256
                    <div class="form-group">
257
                        <label for="updateGrantComment" class="col-sm-2 control-label">Комментарий</label>
258
259
                        <div class="col-sm-10">
260
                            <input type="text" class="form-control" id="updateGrantComment" placeholder="Комментарий">
261
                        </div>
262
                    </div>
263
                </form>
264
            </div>
265
            <div class="modal-footer">
266
                <button type="button" class="btn btn-default" data-dismiss="modal">Закрыть</button>
267
                <button type="button" id="saveGrant" class="btn btn-primary">Сохранить</button>
268
            </div>
269
        </div>
270
    </div>
271
</div>
272
273
274
<!-- Modal -->
275
<div class="modal fade" id="deleteGrantModal" tabindex="-1" role="dialog" aria-hidden="true">
276
    <div class="modal-dialog">
277
        <div class="modal-content">
278
            <div class="modal-header">
279
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
280
                <h4 class="modal-title">Удалить счетчик?</h4>
281
            </div>
282
            <div class="modal-body">
283
                <input type="hidden" id="deleteGrantUserLogin">
284
            </div>
285
            <div class="modal-footer">
286
                <button type="button" class="btn btn-default" data-dismiss="modal">Отмена</button>
287
                <button type="button" id="deleteGrant" class="btn btn-danger">Удалить!</button>
288
            </div>
289
        </div>
290
    </div>
291
</div>
292
293
<script src="http://yandex.st/jquery/2.0.3/jquery.min.js"></script>
294
<script src="http://yandex.st/jquery/cookie/1.0/jquery.cookie.min.js"></script>
295
<script src="http://yandex.st/bootstrap/3.0.3/js/bootstrap.min.js"></script>
296
297
<script>
298
$(function () {
299
300
    $('#goToAuth').click(function (e) {
301
        $.cookie('back', location.href, { expires: 256, path: '/' });
302
    });
303
304
    var $grantTable = $("#grantTable");
305
306
    $grantTable.on('click', '.showGrant', function () {
307
        var $el = $(this);
308
        var userLogin = $el.parents('tr').data('user-login');
309
        $.get(
310
            "/examples/Metrica/api.php",
311
            {
312
                method: 'getGrant',
313
                userLogin: userLogin,
314
                counterId: <?= $counterId ?>
315
316
            },
317
            function (data) {
318
                var response = JSON.parse(data);
319
                if (response.status === 'ok' && response.result !== null) {
320
321
                    $('#showGrantUserLogin').text(response.result.user_login);
322
                    $('#showGrantPerm').text(response.result.perm);
323
                    $('#showGrantCreateAt').text(response.result.created_at);
324
                    $('#showGrantComment').text(response.result.comment);
325
326
327
                    $('#showGrantModal').modal('show');
328
                } else {
329
                    displayError(response.message);
330
                }
331
            }
332
        );
333
    });
334
335
336
    $('#openAddGrantModal').click(function () {
337
        $('#addGrantModal').modal('show');
338
    });
339
340
    $grantTable.on('click', '.updateGrant', function () {
341
        var $el = $(this);
342
        var userLogin = $el.parents('tr').data('user-login');
343
        $.get(
344
            "/examples/Metrica/api.php",
345
            {
346
                method: 'getGrant',
347
                userLogin: userLogin,
348
                counterId: <?= $counterId ?>
349
            },
350
            function (data) {
351
                var response = JSON.parse(data);
352
                if (response.status === 'ok' && response.result !== null) {
353
                    $('#updateGrantUserLogin').val(response.result.user_login);
354
                    $('#updateGrantPerm').val(response.result.perm);
355
                    $('#updateGrantCreateAt').val(response.result.created_at);
356
                    $('#updateGrantComment').val(response.result.comment);
357
358
                    $('#updateGrantModal').modal('show');
359
                } else {
360
                    displayError(response.message);
361
                }
362
            }
363
        );
364
    });
365
366
367
    $grantTable.on('click', '.deleteGrant', function () {
368
        var $el = $(this);
369
        var userLogin = $el.parents('tr').data('user-login');
370
        $('#deleteGrantUserLogin').val(userLogin);
371
        $('#deleteGrantModal').modal('show');
372
    });
373
374
375
    $('#createGrant').click(function () {
376
        $.post(
377
            "/examples/Metrica/api.php",
378
            {
379
                method: 'addGrant',
380
                userLogin: $('#addGrantUserLogin').val(),
381
                counterId: <?= $counterId ?>,
382
                perm: $('#addGrantPerm').val(),
383
                createdAt: $('#addGrantCreateAt').val(),
384
                comment: $('#addGrantComment').val()
385
            },
386
            function (data) {
387
                $('#addGrantModal').modal('hide');
388
389
                var response = JSON.parse(data);
390
                if (response.status === 'ok' && response.result !== null) {
391
392
                    var html = '\
393
                            <tr data-user-login="' + response.result.user_login + '">\
394
                                <td>' + response.result.user_login + '</td>\
395
                                <td>' + response.result.perm + '</td>\
396
                                <td>' + response.result.created_at + '</td>\
397
                                <td>' + response.result.comment + '</td>\
398
                                <td style="text-align: center">\
399
                                    <button type="button" class="btn btn-info showGrant">\
400
                                        <span title="Открыть" class="glyphicon glyphicon-eye-open"></span>\
401
                                    </button>\
402
                                    <button type="button" class="btn btn-warning updateGrant">\
403
                                        <span title="Изменить" class="glyphicon glyphicon-edit"></span>\
404
                                    </button>\
405
                                    <button type="button" class="btn btn-danger deleteGrant">\
406
                                            <span title="Удалить" class="glyphicon glyphicon-trash "></span>\
407
                                    </button>\
408
                                </td>\
409
                            </tr>';
410
411
                    $grantTable.find('tbody').append(html);
412
413
414
                } else {
415
                    displayError(response.message);
416
                }
417
            }
418
        );
419
    });
420
421
422
    $('#saveGrant').click(function () {
423
        $.post(
424
            "/examples/Metrica/api.php",
425
            {
426
                method: 'updateGrant',
427
                userLogin: $('#updateGrantUserLogin').val(),
428
                counterId: <?= $counterId ?>,
429
                perm: $('#updateGrantPerm').val(),
430
                createdAt: $('#updateGrantCreateAt').val(),
431
                comment: $('#updateGrantComment').val()
432
            },
433
            function (data) {
434
435
                $('#updateGrantModal').modal('hide');
436
437
                var response = JSON.parse(data);
438
                if (response.status === 'ok' && response.result !== null) {
439
440
                    var html = '\
441
                            <tr data-counter-id="' + response.result.id + '">\
442
                                <td>' + response.result.id + '</td>\
443
                                <td>' + response.result.code_status + '</td>\
444
                                <td>' + response.result.name + '</td>\
445
                                <td>' + response.result.site + '</td>\
446
                                <td>' + response.result.owner_login + '</td>\
447
                                <td>' + response.result.type + '</td>\
448
                                <td>' + response.result.permission + '</td>\
449
                                <td style="text-align: center">\
450
                                    <button type="button" class="btn btn-info showGrant">\
451
                                        <span title="Открыть" class="glyphicon glyphicon-eye-open"></span>\
452
                                    </button>\
453
                                    <button type="button" class="btn btn-warning updateGrant">\
454
                                        <span title="Изменить" class="glyphicon glyphicon-edit"></span>\
455
                                    </button>\
456
                                    <button type="button" class="btn btn-danger deleteGrant">\
457
                                            <span title="Удалить" class="glyphicon glyphicon-trash"></span>\
458
                                    </button>\
459
                                </td>\
460
                            </tr>';
461
462
                    $grantTable.find('tbody>tr').each(function () {
463
                        if ($(this).data('counter-id') == response.result.id) {
464
                            $(this).replaceWith(html);
465
                        }
466
                    });
467
468
                } else {
469
                    displayError(response.message);
470
                }
471
            }
472
        );
473
    });
474
475
476
    $('#deleteGrant').click(function () {
477
478
        var userLogin = $.trim($('#deleteGrantUserLogin').val());
479
        $.post(
480
            "/examples/Metrica/api.php",
481
            {
482
                method: 'deleteGrant',
483
                counterId: <?= $counterId ?>,
484
                userLogin: userLogin
485
            },
486
            function (data) {
487
488
                $('#deleteGrantModal').modal('hide');
489
490
                var response = JSON.parse(data);
491
                if (response.status === 'ok' && response.result !== null) {
492
493
                    $grantTable.find('tbody>tr').each(function () {
494
                        if ($(this).data('user-login') == response.result.id) {
495
                            $(this).replaceWith('');
496
                        }
497
                    });
498
499
                } else {
500
                    displayError(response.message);
501
                }
502
            }
503
        );
504
    });
505
506
});
507
508
509
/**
510
 * @param message string
511
 */
512
function displayError(message) {
513
    $('#errorMessage').text(message);
514
    $('#errorModal').modal('show');
515
}
516
517
</script>
518
</body>
519
</html>
520