Issues (9)

Security Analysis    no request data  

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/http/Controllers/U2fController.php (6 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 namespace Lahaxearnaud\U2f\Http\Controllers;
2
3
use App\Http\Controllers\Controller;
4
use Illuminate\Config\Repository as Config;
5
use Illuminate\Http\Request;
6
use Illuminate\Support\Facades\Auth;
7
use Illuminate\Support\Facades\Event;
8
use Illuminate\Support\Facades\Redirect;
9
use Lahaxearnaud\U2f\U2f as LaravelU2f;
10
11
class U2fController extends Controller
12
{
13
    /**
14
     * @var LaravelU2f
15
     */
16
    protected $u2f;
17
18
    /**
19
     * @var Config
20
     */
21
    protected  $config;
22
23
    /**
24
     * @param LaravelU2f $u2f
25
     * @param Config $config
26
     */
27
    public function __construct(LaravelU2f $u2f, Config $config)
28
    {
29
        $this->u2f = $u2f;
30
        $this->config = $config;
31
    }
32
33
    /**
34
     * @author LAHAXE Arnaud
35
     *
36
     *
37
     * @return mixed
38
     */
39
    public function registerData()
40
    {
41
        list($req, $sigs) = $this->u2f->getRegisterData(Auth::user());
0 ignored issues
show
It seems like \Illuminate\Support\Facades\Auth::user() can be null; however, getRegisterData() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
42
        Event::dispatch('u2f.register.data', [ 'user' => Auth::user() ]);
43
44
        session()->put('u2f.registerData', $req);
45
46
        return view($this->config->get('u2f.register.view'))
0 ignored issues
show
The method with does only exist in Illuminate\View\View, but not in Illuminate\Contracts\View\Factory.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
47
            ->with('currentKeys', $sigs)
48
            ->with('registerData', $req);
49
    }
50
51
    /**
52
     * @author LAHAXE Arnaud
53
     *
54
     *
55
     * @return \Illuminate\Http\RedirectResponse
56
     */
57
    public function register(Request $request)
58
    {
59
        try {
60
            $key = $this->u2f->doRegister(Auth::user(), session('u2f.registerData'), json_decode($request->get('register')));
0 ignored issues
show
It seems like \Illuminate\Support\Facades\Auth::user() can be null; however, doRegister() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
61
            Event::dispatch('u2f.register', [ 'u2fKey' => $key, 'user' => Auth::user() ]);
62
            session()->forget('u2f.registerData');
63
64
            session()->put($this->config->get('u2f.sessionU2fName'), true);
65
66
            if ($this->config->get('u2f.register.postSuccessRedirectRoute')) {
67
68
                return Redirect::route($this->config->get('u2f.register.postSuccessRedirectRoute'));
69
            } else {
70
                return redirect('/');
71
            }
72
73
        } catch (\Exception $e) {
74
75
            return Redirect::route('u2f.register.data');
76
        }
77
    }
78
79
    /**
80
     * @author LAHAXE Arnaud
81
     *
82
     *
83
     * @return mixed
84
     */
85
    public function authData()
86
    {
87
        if ($this->u2f->check()) {
88
89
            return $this->redirectAfterSuccessAuth();
90
        }
91
92
        $req = $this->u2f->getAuthenticateData(Auth::user());
0 ignored issues
show
It seems like \Illuminate\Support\Facades\Auth::user() can be null; however, getAuthenticateData() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
93
        Event::dispatch('u2f.authentication.data', [ 'user' => Auth::user() ]);
94
95
        session()->put('u2f.authenticationData', $req);
96
97
        return view($this->config->get('u2f.authenticate.view'))
0 ignored issues
show
The method with does only exist in Illuminate\View\View, but not in Illuminate\Contracts\View\Factory.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
98
            ->with('authenticationData', $req);
99
    }
100
101
    /**
102
     * @author LAHAXE Arnaud
103
     *
104
     *
105
     * @return mixed
106
     */
107
    public function auth(Request $request)
108
    {
109
        try {
110
            $key = $this->u2f->doAuthenticate(Auth::user(), session('u2f.authenticationData'), json_decode($request->get('authentication')));
0 ignored issues
show
It seems like \Illuminate\Support\Facades\Auth::user() can be null; however, doAuthenticate() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
111
            Event::dispatch('u2f.authentication', [ 'u2fKey' => $key, 'user' => Auth::user() ]);
112
            session()->forget('u2f.authenticationData');
113
114
            return $this->redirectAfterSuccessAuth();
115
116
        } catch (\Exception $e) {
117
            session()->flash('error', $e->getMessage());
118
119
            return Redirect::route('u2f.auth.data');
120
        }
121
    }
122
123
    /**
124
     * @author LAHAXE Arnaud
125
     *
126
     * @return mixed
127
     */
128
    protected function redirectAfterSuccessAuth()
129
    {
130
        if (strlen($this->config->get('u2f.authenticate.postSuccessRedirectRoute'))) {
131
132
            return Redirect::intended($this->config->get('u2f.authenticate.postSuccessRedirectRoute'));
133
        } else {
134
135
            return Redirect::intended('/');
136
        }
137
    }
138
}
139