Issues (9)

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/PdoStorage.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
namespace Germania\PermanentAuth;
3
4
use Germania\PermanentAuth\Exceptions\DuplicateSelectorException;
5
use Germania\PermanentAuth\Exceptions\StorageException;
6
use Psr\Log\LoggerInterface;
7
use Psr\Log\NullLogger;
8
9
/**
10
 * This Callable stores a persistent login for a given User ID with selector, token hash and expiration date.
11
 *
12
 * If a selector exists, a `DuplicateSelectorException` will be thrown.
13
 * If the insert statement execution fails, a `StorageException` will be thrown.
14
 */
15
class PdoStorage
16
{
17
18
    /**
19
     * @var string
20
     */
21
    public $table     = "auth_logins";
22
23
    /**
24
     * @var PDOStatement
25
     */
26
    public $avoid_stmt;
27
28
    /**
29
     * @var PDOStatement
30
     */
31
    public $insert_stmt;
32
33
    /**
34
     * @var LoggerInterface
35
     */
36
    public $logger;
37
38
39
40
    /**
41
     * @param \PDO             $pdo    PDO instance
42
     * @param LoggerInterface  $logger Optional: PSR-3 Logger
43
     * @param string           $table  Optional: Custom table name, default: `auth_logins`
44
     */
45 30
    public function __construct( \PDO $pdo, LoggerInterface $logger = null, $table = null )
46
    {
47
48 30
        $this->table  = $table ?: $this->table;
49 30
        $this->logger = $logger ?: new NullLogger;
50
51
52
        // ------------------------------------------
53
        // 1. Prepare avoid duplicates statement
54
        // ------------------------------------------
55
        $avoid_duplicate_sql = "SELECT selector
56 30
        FROM  {$this->table}
57
        WHERE selector = :selector
58 6
        LIMIT 1";
59
60 30
        $this->avoid_stmt = $pdo->prepare($avoid_duplicate_sql);
0 ignored issues
show
Documentation Bug introduced by
It seems like $pdo->prepare($avoid_duplicate_sql) of type object<PDOStatement> is incompatible with the declared type object<Germania\PermanentAuth\PDOStatement> of property $avoid_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...
61
62
63
        // ------------------------------------------
64
        // 2. Prepare Insert statements
65
        // ------------------------------------------
66 30
        $insert_sql = "INSERT INTO {$this->table} (
67
          user_id,
68
          selector,
69
          token_hash,
70
          valid_until
71
        ) VALUES (
72
          :user_id,
73
          :selector,
74
          :token_hash,
75
          :valid_until
76 6
        )";
77
78 30
        $this->insert_stmt = $pdo->prepare( $insert_sql );
0 ignored issues
show
Documentation Bug introduced by
It seems like $pdo->prepare($insert_sql) of type object<PDOStatement> is incompatible with the declared type object<Germania\PermanentAuth\PDOStatement> of property $insert_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...
79
80
81 30
    }
82
83
    /**
84
     * @param  int       $user_id     User ID
85
     * @param  string    $selector    Cookie selector
86
     * @param  string    $token_hash  Token hash
87
     * @param  \DateTime $valid_until Valid until DateTime
88
     *
89
     * @return boolean
90
     *
91
     * @throws StorageException if Insert Statement executions returns FALSE.
92
     */
93 20
    public function __invoke($user_id, $selector, $token_hash, \DateTime $valid_until)
94
    {
95
96
        // ------------------------------------------
97
        // 1. Find out if selector already exists
98
        // ------------------------------------------
99 20
        $way_clear = $this->avoid_stmt->execute([':selector' => $selector]);
100 20
        if (!$way_clear) {
101 5
            throw new StorageException("Could not check if selector is existing.");
102
        }
103 15
        if ($this->avoid_stmt->fetchColumn()) {
104 5
            throw new DuplicateSelectorException;
105
        }
106
107
        // ------------------------------------------
108
        // 2. Insert
109
        // ------------------------------------------
110
111 10
        $result = $this->insert_stmt->execute([
112 10
            ':user_id'          => $user_id,
113 10
            ':selector'         => $selector,
114 10
            ':token_hash'       => $token_hash,
115 10
            ':valid_until'      => $valid_until->format('Y-m-d H:i:s')
116 2
        ]);
117
118
119 10
        if ($result) :
120 5
            $this->logger->info("Stored in database", [
121 5
                'user_id'  => $user_id,
122 4
                'selector' => $selector
123 1
            ]);
124 1
        else:
125 5
            $error_info = $this->insert_stmt->errorInfo();
126 5
            $this->logger->error('Could not store persistent login', [
127 5
                'user_id'    => $user_id,
128 5
                'selector'   => $selector,
129 4
                'stmt_error' => $error_info
130 1
            ]);
131
132 5
            throw new StorageException("Could not store persistent login on server: " . implode("/", $error_info));
133
        endif;
134
135 5
        return true;
136
    }
137
138
139
}
140