Issues (24)

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/User/HTMLForm/EditUserForm.php (2 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
namespace Oenstrom\User\HTMLForm;
4
5
use \Anax\HTMLForm\FormModel;
6
use \Anax\DI\DIInterface;
7
use \Oenstrom\User\User;
8
9
/**
10
 * Form to update an user.
11
 */
12
class EditUserForm extends FormModel
13
{
14
    /**
15
     * @var User $user the user being edited.
16
     */
17
    public $user;
18
19
20
21
    /**
22
     * Constructor injects with DI container.
23
     *
24
     * @param Anax\DI\DIInterface $di a service container
25
     */
26 3
    public function __construct(DIInterface $di, $id)
27
    {
28 3
        parent::__construct($di);
29 3
        $this->user = $this->hasItemDetails($id);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->hasItemDetails($id) of type boolean is incompatible with the declared type object<Oenstrom\User\User> of property $user.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
30 3
        $this->form->create(
31
            [
32 3
                "id" => __CLASS__,
33 3
                "legend" => "Redigera användare",
34 3
                "use_fieldset" => false,
35 3
                "wrapper-element" => "div",
36 3
                "br-after-label" => false,
37 3
            ],
38
            [
39
                "username" => [
40 3
                    "label" => "Användarnamn",
41 3
                    "label-class" => "mdl-textfield__label",
42 3
                    "wrapper-class" => "mdl-textfield mdl-js-textfield mdl-textfield--floating-label",
43 3
                    "class" => "mdl-textfield__input",
44 3
                    "type" => "text",
45 3
                    "value" => $this->user->username,
46 3
                    "validation" => ["not_empty"],
47 3
                ],
48
                "email" => [
49 3
                    "label" => "E-postadress",
50 3
                    "label-class" => "mdl-textfield__label",
51 3
                    "wrapper-class" => "mdl-textfield mdl-js-textfield mdl-textfield--floating-label",
52 3
                    "class" => "mdl-textfield__input",
53 3
                    "type" => "text",
54 3
                    "value" => $this->user->email,
55 3
                    "validation" => ["email", "not_empty"],
56 3
                ],
57
58
                "new-password" => [
59 3
                    "label" => "Nytt lösenord",
60 3
                    "label-class" => "mdl-textfield__label",
61 3
                    "wrapper-class" => "mdl-textfield mdl-js-textfield mdl-textfield--floating-label",
62 3
                    "class" => "mdl-textfield__input",
63 3
                    "type" => "password",
64 3
                ],
65
66
                "new-password-again" => [
67 3
                    "label" => "Nytt lösenord igen",
68 3
                    "label-class" => "mdl-textfield__label",
69 3
                    "wrapper-class" => "mdl-textfield mdl-js-textfield mdl-textfield--floating-label",
70 3
                    "class" => "mdl-textfield__input",
71 3
                    "type" => "password",
72 3
                    "validation" => ["match" => "new-password"],
73 3
                ],
74
75
                "submit" => [
76 3
                    "class" => "mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--accent",
77 3
                    "type" => "submit",
78 3
                    "value" => "Uppdatera",
79 3
                    "callback" => [$this, "callbackSubmit"]
80 3
                ],
81
            ]
82 3
        );
83 3
    }
84
85
86
87
    /**
88
     * Get details on item to load form with.
89
     *
90
     * @param integer $id get details on user with id.
91
     *
92
     * @return boolean true if okey, false if something went wrong.
93
     */
94 3
    public function hasItemDetails($id)
95
    {
96 3
        $user = $this->di->get("user");
97 3
        $user->find("id", $id);
98 3
        return $user;
99
    }
100
101
102
103
    /**
104
     * Callback for submit-button which should return true if it could
105
     * carry out its work and false if something failed.
106
     *
107
     * @return boolean true if okey, false if something went wrong.
108
     */
109 1
    public function callbackSubmit()
110
    {
111 1
        $username       = $this->form->value("username");
112 1
        $email          = $this->form->value("email");
113 1
        $password       = $this->form->value("new-password");
114 1
        $isOldEmail     = $this->user->email === $email;
115 1
        $isOldUsername  = $this->user->username === $username;
116
117 1
        $user = $this->di->get("user");
118
119 1
        if (!$isOldUsername && $user->usernameExists($username) !== null) {
120
            $this->form->addOutput("Användarnamnet är upptaget.", "error");
121
            $this->di->get("response")->redirect("user/admin/users/update/{$this->user->id}");
122
            return false;
123
        }
124
125 1 View Code Duplication
        if (!$isOldEmail && $user->emailExists($email) !== null) {
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...
126
            $this->form->addOutput("E-postadressen är upptagen.", "error");
127
            $this->di->get("response")->redirect("user/admin/users/update/{$this->user->id}");
128
            return false;
129
        }
130
131 1
        if ($password != "") {
132
            $this->user->setPassword($password);
133
        }
134
135 1
        $this->user->username = $username;
136 1
        $this->user->email = $email;
137 1
        $this->user->save();
138 1
        $this->form->addOutput("Användaren har uppdaterats.", "success");
139 1
        $this->di->get("response")->redirect("user/admin/users/update/{$this->user->id}");
140 1
    }
141
}
142