Issues (180)

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.

code/control/LDAPSecurityController.php (7 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
 * Class LDAPSecurityController
4
 *
5
 * This controller overrides the default Security controller with functionality
6
 * for resetting passwords.
7
 */
8
class LDAPSecurityController extends Security
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
9
{
10
    /**
11
     * @var array
12
     */
13
    private static $allowed_actions = [
0 ignored issues
show
The property $allowed_actions is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
14
        'index',
15
        'lostpassword',
16
        'LostPasswordForm',
17
        'ChangePasswordForm',
18
        'passwordsent'
19
    ];
20
21
    /**
22
     * This static function is *intentionally* overloaded from Security so
23
     * the user accesses this controller and uses the LDAP change password
24
     * form rather than the "standard" one provided by Security.
25
     *
26
     * @param Member $member
27
     * @param $autologinToken
28
     * @return string
29
     */
30
    public static function getPasswordResetLink($member, $autologinToken)
31
    {
32
        $autologinToken = urldecode($autologinToken);
33
        $selfControllerClass = __CLASS__;
34
        $selfController = new $selfControllerClass();
35
        return $selfController->Link('changepassword') . "?m={$member->ID}&t=$autologinToken";
36
    }
37
38
    /**
39
     * Factory method for the lost password form
40
     *
41
     * @return Form Returns the lost password form
42
     */
43
    public function ChangePasswordForm()
44
    {
45
        return Object::create('LDAPChangePasswordForm', $this, 'ChangePasswordForm');
0 ignored issues
show
Bug Best Practice introduced by
The return type of return \Object::create('... 'ChangePasswordForm'); (Object) is incompatible with the return type of the parent method Security::ChangePasswordForm of type Security.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
46
    }
47
48
    public function lostpassword()
49
    {
50
        $controller = $this->getResponseController(_t('LDAPSecurityController.LOSTPASSWORDHEADER', 'Lost password'));
51
52
        // if the controller calls Director::redirect(), this will break early
53
        if (($response = $controller->getResponse()) && $response->isFinished()) {
54
            return $response;
55
        }
56
57
        if (Config::inst()->get('LDAPAuthenticator', 'allow_email_login')==='yes') {
58
            $customisedController = $controller->customise([
59
                'Content' =>
60
                    '<p>' .
61
                    _t(
62
                        'LDAPSecurityController.NOTERESETPASSWORDUSERNAMEOREMAIL',
63
                        'Enter your username or your email address and we will send you a link with which '
64
                        . 'you can reset your password'
65
                    ) .
66
                    '</p>',
67
                'Form' => $this->LostPasswordForm(),
68
            ]);
69
        } else {
70
            $customisedController = $controller->customise([
71
                'Content' =>
72
                    '<p>' .
73
                    _t(
74
                        'LDAPSecurityController.NOTERESETPASSWORDUSERNAME',
75
                        'Enter your username and we will send you a link with which you can reset your password'
76
                    ) .
77
                    '</p>',
78
                'Form' => $this->LostPasswordForm(),
79
            ]);
80
        }
81
82
        //Controller::$currentController = $controller;
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
83
        return $customisedController->renderWith($this->getTemplatesFor('lostpassword'));
84
    }
85
86
    /**
87
     * Factory method for the lost password form
88
     *
89
     * @return Form Returns the lost password form
90
     */
91
    public function LostPasswordForm()
92
    {
93
        $email = new EmailField('Email', _t('Member.EMAIL', 'Email'));
94
        $action = new FormAction('forgotPassword', _t('Security.BUTTONSEND', 'Send me the password reset link'));
95
        return LDAPLoginForm::create($this,
96
            'LostPasswordForm',
97
            new FieldList([$email]),
98
            new FieldList([$action]),
99
            false
100
        );
101
    }
102
103
    /**
104
     * @param null $action
105
     * @return String
106
     */
107
    public function Link($action = null)
108
    {
109
        return Controller::join_links(Director::baseURL(), 'LDAPSecurity', $action);
110
    }
111
112
    /**
113
     * Show the "password sent" page, after a user has requested
114
     * to reset their password.
115
     *
116
     * @param SS_HTTPRequest $request The SS_HTTPRequest for this action.
117
     * @return string Returns the "password sent" page as HTML code.
118
     */
119
    public function passwordsent($request)
120
    {
121
        $controller = $this->getResponseController(_t('Security.LOSTPASSWORDHEADER', 'Lost Password'));
122
123
        // if the controller calls Director::redirect(), this will break early
124
        if (($response = $controller->getResponse()) && $response->isFinished()) {
125
            return $response;
126
        }
127
128
        $username = Convert::raw2xml(rawurldecode($request->param('ID')));
129
130
        $customisedController = $controller->customise([
131
            'Title' => _t('LDAPSecurity.PASSWORDSENTHEADER', "Password reset link sent to '{username}'",
132
                ['username' => $username]),
0 ignored issues
show
array('username' => $username) is of type array<string,array|strin...rname":"array|string"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
133
            'Content' =>
134
                "<p>"
135
                . _t('LDAPSecurity.PASSWORDSENTTEXT',
136
                    "Thank you! A reset link has been sent to '{username}', provided an account exists.",
137
                    ['username' => $username])
0 ignored issues
show
array('username' => $username) is of type array<string,array|strin...rname":"array|string"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
138
                . "</p>",
139
            'Username' => $username
140
        ]);
141
        return $customisedController->renderWith($this->getTemplatesFor('passwordsent'));
142
    }
143
}
144