Issues (13)

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/localstorage/index.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
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 72 and the first side effect is on line 37.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/**
3
 * Copyright (c) 2014 Yubico AB
4
 * All rights reserved.
5
 *
6
 * Redistribution and use in source and binary forms, with or without
7
 * modification, are permitted provided that the following conditions are
8
 * met:
9
 *
10
 *   * Redistributions of source code must retain the above copyright
11
 *     notice, this list of conditions and the following disclaimer.
12
 *
13
 *   * Redistributions in binary form must reproduce the above
14
 *     copyright notice, this list of conditions and the following
15
 *     disclaimer in the documentation and/or other materials provided
16
 *     with the distribution.
17
 *
18
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
 */
30
31
/**
32
 * This is a minimal example of U2F registration and authentication.
33
 * The data that has to be stored between registration and authentication
34
 * is stored in browser localStorage, so there's nothing real-world
35
 * about this.
36
 */
37
require_once('../../src/u2flib_server/U2F.php');
38
$scheme = isset($_SERVER['HTTPS']) ? "https://" : "http://";
39
$u2f = new u2flib_server\U2F($scheme . $_SERVER['HTTP_HOST']);
40
?>
41
<html>
42
<head>
43
    <title>PHP U2F Demo</title>
44
45
    <script src="../assets/u2f-api.js"></script>
46
47
    <script>
48
        function addRegistration(reg) {
49
            var existing = localStorage.getItem('u2fregistration');
50
            var regobj = JSON.parse(reg);
51
            var data = null;
52
            if(existing) {
53
                data = JSON.parse(existing);
54
                if(Array.isArray(data)) {
55
                    for (var i = 0; i < data.length; i++) {
56
                        if(data[i].keyHandle === regobj.keyHandle) {
57
                            data.splice(i,1);
58
                            break;
59
                        }
60
                    }
61
                    data.push(regobj);
62
                } else {
63
                    data = null;
64
                }
65
            }
66
            if(data == null) {
67
                data = [regobj];
68
            }
69
            localStorage.setItem('u2fregistration', JSON.stringify(data));
70
        }
71
        <?php
72
        function fixupArray($data) {
73
            $ret = array();
74
            $decoded = json_decode($data);
75
            foreach ($decoded as $d) {
76
                $ret[] = json_encode($d);
77
            }
78
            return $ret;
79
        }
80
        if($_SERVER['REQUEST_METHOD'] === 'POST') {
81
            if(isset($_POST['startRegister'])) {
82
                $regs = json_decode($_POST['registrations']) ? : array();
83
                list($data, $reqs) = $u2f->getRegisterData($regs);
84
                echo "var request = " . json_encode($data) . ";\n";
85
                echo "var signs = " . json_encode($reqs) . ";\n";
86
        ?>
87
        setTimeout(function() {
88
            console.log("Register: ", request);
89
            u2f.register([request], signs, function(data) {
90
                var form = document.getElementById('form');
91
                var reg = document.getElementById('doRegister');
92
                var req = document.getElementById('request');
93
                console.log("Register callback", data);
94
                if(data.errorCode) {
95
                    alert("registration failed with errror: " + data.errorCode);
96
                    return;
97
                }
98
                reg.value=JSON.stringify(data);
99
                req.value=JSON.stringify(request);
100
                form.submit();
101
            });
102
        }, 1000);
103
        <?php
104
            } else if($_POST['doRegister']) {
105
                try {
106
                    $data = $u2f->doRegister(json_decode($_POST['request']), json_decode($_POST['doRegister']));
107
                    echo "var registration = '" . json_encode($data) . "';\n";
108
        ?>
109
        addRegistration(registration);
110
        alert("registration successful!");
111
        <?php
112
                } catch(u2flib_server\Error $e) {
0 ignored issues
show
The class u2flib_server\Error does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
113
                    echo "alert('error:" . $e->getMessage() . "');\n";
114
                }
115
            } else if(isset($_POST['startAuthenticate'])) {
116
                $regs = json_decode($_POST['registrations']);
117
                $data = $u2f->getAuthenticateData($regs);
118
                echo "var registrations = " . $_POST['registrations'] . ";\n";
119
                echo "var request = " . json_encode($data) . ";\n";
120
        ?>
121
        setTimeout(function() {
122
            console.log("sign: ", request);
123
            u2f.sign(request, function(data) {
124
                var form = document.getElementById('form');
125
                var reg = document.getElementById('doAuthenticate');
126
                var req = document.getElementById('request');
127
                var regs = document.getElementById('registrations');
128
                console.log("Authenticate callback", data);
129
                reg.value=JSON.stringify(data);
130
                req.value=JSON.stringify(request);
131
                regs.value=JSON.stringify(registrations);
132
                form.submit();
133
            });
134
        }, 1000);
135
        <?php
136
            } else if($_POST['doAuthenticate']) {
137
                $reqs = json_decode($_POST['request']);
138
                $regs = json_decode($_POST['registrations']);
139
                try {
140
                    $data = $u2f->doAuthenticate($reqs, $regs, json_decode($_POST['doAuthenticate']));
141
                    echo "var registration = '" . json_encode($data) . "';\n";
142
                    echo "addRegistration(registration);\n";
143
                    echo "alert('Authentication successful, counter:" . $data->counter . "');\n";
144
                } catch(u2flib_server\Error $e) {
0 ignored issues
show
The class u2flib_server\Error does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
145
                    echo "alert('error:" . $e->getMessage() . "');\n";
146
                }
147
            }
148
        }
149
        ?>
150
    </script>
151
152
</head>
153
<body>
154
<form method="POST" id="form">
155
    <button name="startRegister" type="submit">Register</button>
156
    <input type="hidden" name="doRegister" id="doRegister"/>
157
    <button name="startAuthenticate" type="submit" id="startAuthenticate">Authenticate</button>
158
    <input type="hidden" name="doAuthenticate" id="doAuthenticate"/>
159
    <input type="hidden" name="request" id="request"/>
160
    <input type="hidden" name="registrations" id="registrations"/>
161
</form>
162
163
<p>
164
    <span id="registered">0</span> Authenticators currently registered.
165
</p>
166
167
<script>
168
    var reg = localStorage.getItem('u2fregistration');
169
    var auth = document.getElementById('startAuthenticate');
170
    if(reg == null) {
171
        auth.disabled = true;
172
    } else {
173
        var regs = document.getElementById('registrations');
174
        decoded = JSON.parse(reg);
175
        if(!Array.isArray(decoded)) {
176
            auth.disabled = true;
177
        } else {
178
            regs.value = reg;
179
            console.log("set the registrations to : ", reg);
180
            var regged = document.getElementById('registered');
181
            regged.innerHTML = decoded.length;
182
        }
183
    }
184
</script>
185
</body>
186
</html>
187