Issues (4)

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/PdoAssignUserToRole.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
namespace Germania\UserRoles;
3
4
use Psr\Log\LoggerInterface;
5
use Psr\Log\NullLogger;
6
7
/**
8
 * This Callable assigns a User ID to a Role ID.
9
 *
10
 * Example:
11
 *
12
 *     <?php
13
 *     use Germania\UserRoles\PdoAssignUserToRole;
14
 *
15
 *     $pdo    = new PDO( ... );
16
 *     $logger = new Monolog();
17
 *     $table  = 'users_roles_mm';
18
 *
19
 *     $assigner = new PdoAssignUserToRole( $pdo, $logger, $table);
20
 *     $assigner( 42, 1);
21
 *     ?>
22
 *
23
 * @author  Carsten Witt <[email protected]>
24
 */
25
class PdoAssignUserToRole
26
{
27
28
    /**
29
     * Database table
30
     * @var string
31
     */
32
    public $table = "users_roles_mm";
33
34
    /**
35
     * @var PDOStatement
36
     */
37
    public $stmt;
38
39
    /**
40
     * @var LoggerInterface
41
     */
42
    public $logger;
43
44
45
    /**
46
     * @param PDO             $pdo         PDO instance
47
     * @param LoggerInterface $logger      Optional: PSR-3 Logger
48
     * @param string          $table       Optional: Database table name
49
     */
50 10
    public function __construct(\PDO $pdo, LoggerInterface $logger = null, $table = null)
51
    {
52
        // Setup
53 10
        $this->table  = $table ?: $this->table;
54 10
        $this->logger = $logger ?: new NullLogger;
55
56
        // Prepare business
57 10
        $sql = "INSERT INTO {$this->table}
58
        (client_id, role_id)
59 2
        VALUES (:client_id, :role_id)";
60
61 10
        $this->stmt = $pdo->prepare( $sql );
0 ignored issues
show
Documentation Bug introduced by
It seems like $pdo->prepare($sql) of type object<PDOStatement> is incompatible with the declared type object<Germania\UserRoles\PDOStatement> of property $stmt.

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...
62 10
    }
63
64
65
    /**
66
     * @param  int  $user_id
67
     * @param  int  $role_id
68
     *
69
     * @return bool
70
     */
71 10
    public function __invoke( $user_id, $role_id )
72
    {
73
74 10
        $result = $this->stmt->execute([
75 10
            'client_id' => $user_id,
76 8
            'role_id'   => $role_id
77 2
        ]);
78
79
        // Evaluate
80
        $loginfo = [
81 10
            'user_id'   => $user_id,
82 10
            'role_id'   => $role_id,
83 8
            'result'    => $result
84 2
        ];
85
86 10
        if ($result):
87 5
            $this->logger->info("Successfully assigned user to role.", $loginfo);
88 1
        else:
89 5
            $this->logger->warning("Could not assign user to role?!", $loginfo);
90
        endif;
91
92 10
        return $result;
93
    }
94
}
95