Issues (6)

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/Lock.php (6 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
* Vperyod Simple Lock
4
*
5
* PHP version 5
6
*
7
* Copyright (C) 2016 Jake Johns
8
*
9
* This software may be modified and distributed under the terms
10
* of the MIT license.  See the LICENSE file for details.
11
*
12
* @category  Session
13
* @package   Vperyod\SimpleLock
14
* @author    Jake Johns <[email protected]>
15
* @copyright 2016 Jake Johns
16
* @license   http://jnj.mit-license.org/2016 MIT License
17
* @link      http://jakejohns.net
18
 */
19
20
namespace Vperyod\SimpleLock;
21
22
use Psr\Http\Message\ServerRequestInterface as Request;
23
24
/**
25
 * Lock
26
 *
27
 * @category Session
28
 * @package  Vperyod\SimpleLock
29
 * @author   Jake Johns <[email protected]>
30
 * @license  http://jnj.mit-license.org/ MIT License
31
 * @link     https://github.com/vperyod/vperyod.simple-lock
32
 */
33
class Lock
34
{
35
    /**
36
     * Cookie
37
     *
38
     * @var array
39
     *
40
     * @access protected
41
     */
42
    protected $cookie;
43
44
    /**
45
     * Session key for lock status
46
     *
47
     * @var string
48
     *
49
     * @access protected
50
     */
51
    protected $key = 'vperyod/simplelock:unlocked';
52
53
    /**
54
     * Session key for intent
55
     *
56
     * @var string
57
     *
58
     * @access protected
59
     */
60
    protected $intent = 'vperyod/simplelock:intent';
61
62
    /**
63
     * Create a session lock
64
     *
65
     * @access public
66
     */
67 2
    public function __construct()
68
    {
69 2
        $this->session();
70 2
    }
71
72
    /**
73
     * Unlock a session
74
     *
75
     * @return void
76
     *
77
     * @access public
78
     */
79 1
    public function unlock()
0 ignored issues
show
unlock 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...
80
    {
81 1
        $_SESSION[$this->key] = true;
82 1
    }
83
84
    /**
85
     * Lock a session
86
     *
87
     * @return void
88
     *
89
     * @access public
90
     */
91 1
    public function lock()
0 ignored issues
show
Using PHP4-style constructors that are named like the class is not recommend; better use the more explicit __construct method.
Loading history...
lock 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...
92
    {
93 1
        $_SESSION[$this->key] = false;
94 1
    }
95
96
    /**
97
     * Set intent
98
     *
99
     * @param Request $request intended request
100
     *
101
     * @return void
102
     *
103
     * @access public
104
     */
105 1
    public function setIntent(Request $request)
0 ignored issues
show
setIntent 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...
106
    {
107 1
        $_SESSION[$this->intent] = $request;
108 1
    }
109
110
    /**
111
     * Get and clear intent
112
     *
113
     * @return null | Request
114
     *
115
     * @access public
116
     */
117 1
    public function getIntent()
0 ignored issues
show
getIntent 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...
118
    {
119 1
        if (isset($_SESSION[$this->intent])) {
120 1
            $intent = $_SESSION[$this->intent];
121 1
            unset($_SESSION[$this->intent]);
122 1
            return $intent;
123
        }
124 1
        return null;
125
    }
126
127
    /**
128
     * Is session unlocked?
129
     *
130
     * @return bool
131
     *
132
     * @access public
133
     */
134 1
    public function isUnlocked()
0 ignored issues
show
isUnlocked 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...
135
    {
136 1
        return isset($_SESSION[$this->key])
137 1
            && true === $_SESSION[$this->key];
138
    }
139
140
    /**
141
     * Resume session
142
     *
143
     * @return bool
144
     *
145
     * @access protected
146
     */
147 2
    protected function session()
148
    {
149 2
        return (session_id() !== '') ?: session_start();
150
    }
151
}
152