Issues (4714)

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/Intraface/Auth/User.php (4 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
 * Authenticates a user
4
 *
5
 * @package  Intraface
6
 * @author   Lars Olesen <[email protected]>
7
 * @since    0.1.0
8
 * @version  @package-version@
9
 */
10
class Intraface_Auth_User
11
{
12
    private $db;
13
    private $email;
14
    private $password;
15
16
    /**
17
     * Constructor
18
     *
19
     * @param object $db       Databaseobject
20
     * @param string $email    Username
21
     * @param string $password Password
22
     *
23
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
24
     */
25 3
    function __construct(MDB2_Driver_Common $db, $session_id, $email = null, $password = null)
26
    {
27 3
        $this->db         = $db;
28 3
        $this->email      = $email;
29 3
        $this->password   = $password;
30 3
        $this->session_id = $session_id;
0 ignored issues
show
The property session_id does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
31 3
    }
32
33
    /**
34
     * Auth
35
     *
36
     * @return object
37
     */
38 1
    public function auth()
0 ignored issues
show
auth uses the super-global variable $_SESSION which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

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

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
39
    {
40 1
        $result = $this->db->query("SELECT id FROM user WHERE email = ".$this->db->quote($this->email, 'text')." AND password = ".$this->db->quote(md5($this->password), 'text'));
41
42 1
        if (PEAR::isError($result)) {
43
            throw new Exception('result is an error' . $result->getMessage() . $result->getUserInfo());
44
        }
45
46 1
        if ($result->numRows() != 1) {
47
            return false;
48
        }
49 1
        $row = $result->fetchRow(MDB2_FETCHMODE_ASSOC);
50
51 1
        $result = $this->db->exec("UPDATE user SET lastlogin = NOW(), session_id = ".$this->db->quote($this->session_id, 'text')." WHERE id = ". $this->db->quote($row['id'], 'integer'));
52 1
        if (PEAR::isError($result)) {
53
            throw new Exception('could not update user ' . $result->getMessage() . $result->getUserInfo());
54
        }
55
56 1
        $user = new Intraface_User($row['id']);
57 1
        if (!is_object($user) || $user->get('id') != $row['id']) {
58
            throw new Exception('Unable to return a valid user object on login');
59
        }
60
61 1
        $_SESSION['intraface_logged_in_user_id'] = $user->getId();
62
63 1
        return $user;
64
    }
65
66 1
    function isLoggedIn()
67
    {
68 1
        $result = $this->db->query("SELECT id FROM user WHERE session_id = ".$this->db->quote($this->session_id, 'text'));
69 1
        if (PEAR::isError($result)) {
70
            throw new Exception('could not check if user is logged in ' . $result->getUserInfo());
71
        }
72
73 1
        if ($result->numRows() == 0) {
74
            return false;
75
        }
76
77 1
        $row = $result->fetchRow(MDB2_FETCHMODE_ASSOC);
78 1
        return new Intraface_User($row['id']);
79
    }
80
81
    /**
82
     * logout()
83
     *
84
     * @return boolean
85
     */
86 2 View Code Duplication
    public function logout()
0 ignored issues
show
This method seems to be duplicated in 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...
87 2
    {
88
        $result = $this->db->exec("UPDATE user SET session_id = " . $this->db->quote('', 'text') . " WHERE session_id = " . $this->db->quote($this->session_id, 'text'));
89
90
        if (PEAR::isError($result)) {
91
             throw new Exception('could not log user out ' . $result->getUserInfo());
92
        }
93
        return true;
94
    }
95
96
    /**
97
     * Returns an identification string on the user
98
     *
99
     * @return string identification (email)
100
     */
101
    public function getIdentification()
102
    {
103
        return $this->email;
104
    }
105
}
106