Issues (40)

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/Middleware/AuthenticationMiddleware.php (1 issue)

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
namespace AdvancedLearning\Oauth2Server\Middleware;
4
5
use AdvancedLearning\Oauth2Server\Exceptions\AuthenticationException;
6
use AdvancedLearning\Oauth2Server\Services\Authenticator;
7
use SilverStripe\Control\Director;
8
use SilverStripe\Control\HTTPRequest;
9
use SilverStripe\Control\HTTPResponse;
10
use SilverStripe\Control\Middleware\HTTPMiddleware;
11
use SilverStripe\Core\Application;
12
use SilverStripe\Core\Injector\Injector;
13
use SilverStripe\ORM\Connect\DatabaseException;
14
use SilverStripe\ORM\DB;
15
use SilverStripe\Security\Member;
16
use SilverStripe\Security\Security;
17
18
/**
19
 * Class ResourceServerMiddleware.
20
 *
21
 * Replacement for @see \League\OAuth2\Server\Middleware\ResourceServerMiddleware
22
 * to make it compatible with SilverStripe.
23
 *
24
 * @package AdvancedLearning\Oauth2Server\Middleware
25
 */
26
class AuthenticationMiddleware implements HTTPMiddleware
27
{
28
    /**
29
     * @var Application
30
     */
31
    protected $application = null;
32
33
    /**
34
     * @var Authenticator
35
     */
36
    protected $authenticator;
37
38
    /**
39
     * Build error control chain for an application
40
     *
41
     * @param Application    $application The SilverStripe Application.
42
     */
43
    public function __construct()
44
    {
45
        $this->authenticator = Injector::inst()->get(Authenticator::class);
46
    }
47
48
    /**
49
     * Process the middleware.
50
     *
51
     * @param HTTPRequest $request The incoming request.
52
     * @param callable    $next    The next middleware.
53
     *
54
     * @return HTTPResponse
55
     */
56
    public function process(HTTPRequest $request, callable $next)
57
    {
58
        // don't authenticate if being run from command line
59
        if (Director::is_cli()) {
60
            return $next($request);
61
        }
62
63
        try {
64
            $request = $this->authenticator->authenticate($request);
65
66
            // set the current user
67
            if ($userID = $request->getHeader('oauth_user_id')) {
68
                Security::setCurrentUser(Member::get()->byID($userID));
0 ignored issues
show
It seems like \SilverStripe\Security\M...r::get()->byID($userID) targeting SilverStripe\ORM\DataList::byID() can also be of type object<SilverStripe\ORM\DataObject>; however, SilverStripe\Security\Security::setCurrentUser() does only seem to accept null|object<SilverStripe\Security\Member>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
69
            }
70
        } catch (AuthenticationException $exception) {
71
            // for middleware do nothing
72
        } catch (DatabaseException $exception) {
73
            // db not ready, ignore
74
        }
75
76
        // Pass the request on to the next responder in the chain
77
        return $next($request);
78
    }
79
}
80