Issues (5)

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/Session.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
declare(strict_types=1);
4
5
namespace Chubbyphp\Session;
6
7
use Psr\Http\Message\ServerRequestInterface as Request;
8
use Psr\Log\LoggerInterface;
9
use Psr\Log\NullLogger;
10
use PSR7Sessions\Storageless\Http\SessionMiddleware;
11
use PSR7Sessions\Storageless\Session\SessionInterface as PSR7Session;
12
13
final class Session implements SessionInterface
14
{
15
    /**
16
     * @var LoggerInterface
17
     */
18
    private $logger;
19
20
    /**
21
     * @param LoggerInterface $logger
22
     */
23 9
    public function __construct(LoggerInterface $logger = null)
24
    {
25 9
        $this->logger = $logger ?? new NullLogger();
26 9
    }
27
28
    /**
29
     * @param Request $request
30
     * @param string  $key
31
     *
32
     * @return bool
33
     */
34 6 View Code Duplication
    public function has(Request $request, string $key): bool
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...
35
    {
36 6
        $exists = $this->getSession($request)->has($key);
37
38 6
        $this->logger->info('session: has key {key}, exists {exists}', ['key' => $key, 'exists' => $exists]);
39
40 6
        return $exists;
41
    }
42
43
    /**
44
     * @param Request $request
45
     * @param string  $key
46
     *
47
     * @return mixed
48
     */
49 4 View Code Duplication
    public function get(Request $request, string $key)
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...
50
    {
51 4
        $value = json_decode((string) $this->getSession($request)->get($key), true);
52
53 4
        $this->logger->info('session: get key {key}, exists {exists}', ['key' => $key, 'exists' => (bool) $value]);
54
55 4
        return $value;
56
    }
57
58
    /**
59
     * @param Request $request
60
     * @param string  $key
61
     * @param mixed   $value
62
     */
63 2
    public function set(Request $request, string $key, $value)
64
    {
65 2
        $this->logger->info('session: set key {key}', ['key' => $key]);
66
67 2
        $this->getSession($request)->set($key, json_encode($value));
68 2
    }
69
70
    /**
71
     * @param Request $request
72
     * @param string  $key
73
     */
74 2
    public function remove(Request $request, string $key)
75
    {
76 2
        $this->logger->info('session: remove key {key}', ['key' => $key]);
77
78 2
        $this->getSession($request)->remove($key);
79 2
    }
80
81
    /**
82
     * @param Request      $request
83
     * @param FlashMessage $flashMessage
84
     */
85 1
    public function addFlash(Request $request, FlashMessage $flashMessage)
86
    {
87 1
        $this->set($request, self::FLASH_KEY, $flashMessage);
88 1
    }
89
90
    /**
91
     * @param Request $request
92
     *
93
     * @return FlashMessage|null
94
     */
95 2
    public function getFlash(Request $request)
96
    {
97 2
        if (!$this->has($request, self::FLASH_KEY)) {
98 1
            return null;
99
        }
100
101 1
        $data = $this->get($request, self::FLASH_KEY);
102 1
        $this->remove($request, self::FLASH_KEY);
103
104 1
        return new FlashMessage($data[FlashMessage::JSON_KEY_TYPE], $data[FlashMessage::JSON_KEY_MESSAGE]);
105
    }
106
107
    /**
108
     * @param Request $request
109
     *
110
     * @return PSR7Session
111
     */
112 9
    private function getSession(Request $request): PSR7Session
113
    {
114 9
        return $request->getAttribute(SessionMiddleware::SESSION_ATTRIBUTE);
115
    }
116
}
117