Issues (129)

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.

Model/Auth/AccessToken.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
3
namespace Fousky\Component\iDoklad\Model\Auth;
4
5
use Fousky\Component\iDoklad\Exception\InvalidResponseException;
6
use Fousky\Component\iDoklad\Model\iDokladAbstractModel;
7
use Fousky\Component\iDoklad\Model\iDokladModelInterface;
8
use Fousky\Component\iDoklad\Util\ResponseUtil;
9
use Psr\Http\Message\ResponseInterface;
10
11
/**
12
 * @author Lukáš Brzák <[email protected]>
13
 */
14
class AccessToken extends iDokladAbstractModel implements \Serializable
15
{
16
    /** @var string $token */
17
    protected $token;
18
19
    /** @var int $expires */
20
    protected $expires;
21
22
    /** @var string $type */
23
    protected $type;
24
25
    /** @var \DateTime $requestedAt */
26
    protected $requestedAt;
27
28
    /**
29
     * @param string    $token       access token string
30
     * @param int       $expires     expires in seconds
31
     * @param string    $type        access token type
32
     * @param \DateTime $requestedAt token requested at some time
33
     */
34
    public function __construct(
35
        string $token,
36
        int $expires,
37
        string $type,
38
        \DateTime $requestedAt
39
    ) {
40
        $this->token = $token;
41
        $this->expires = $expires;
42
        $this->type = $type;
43
        $this->requestedAt = $requestedAt;
44
    }
45
46
    /**
47
     * @param array $data
48
     *
49
     * @throws \InvalidArgumentException
50
     *
51
     * @return AccessToken
52
     */
53
    public static function create(array $data): self
54
    {
55
        if (!array_key_exists('token', $data) ||
56
            !array_key_exists('expires', $data) ||
57
            !array_key_exists('type', $data) ||
58
            !array_key_exists('requestedAt', $data)
59
        ) {
60
            throw new \InvalidArgumentException(sprintf('Invalid argument 1 \$data for %s', __METHOD__));
61
        }
62
63
        return new self(
64
            $data['token'],
65
            $data['expires'],
66
            $data['type'],
67
            new \DateTime($data['requestedAt'])
68
        );
69
    }
70
71
    /**
72
     * @return string
73
     */
74
    public function getToken(): string
75
    {
76
        return $this->token;
77
    }
78
79
    /**
80
     * @return int
81
     */
82
    public function getExpires(): int
83
    {
84
        return $this->expires;
85
    }
86
87
    /**
88
     * @return string
89
     */
90
    public function getType(): string
91
    {
92
        return $this->type;
93
    }
94
95
    /**
96
     * @return bool
97
     */
98
    public function isExpired(): bool
99
    {
100
        return new \DateTime() > (clone $this->requestedAt)->modify(sprintf('+%d second', $this->expires));
101
    }
102
103
    /**
104
     * @return string
105
     */
106
    public function serialize(): string
107
    {
108
        return serialize([
109
            $this->token,
110
            $this->expires,
111
            $this->type,
112
            $this->requestedAt,
113
        ]);
114
    }
115
116
    /**
117
     * @param string $serialized
118
     */
119
    public function unserialize($serialized)
120
    {
121
        list(
122
            $this->token,
123
            $this->expires,
124
            $this->type,
125
            $this->requestedAt
126
        ) = unserialize($serialized, ['allowed_classes' => [self::class]]);
127
    }
128
129
    /**
130
     * @param ResponseInterface $response
131
     *
132
     * @throws InvalidResponseException
133
     * @throws \RuntimeException
134
     *
135
     * @return iDokladModelInterface
136
     */
137
    public static function createFromResponse(ResponseInterface $response): iDokladModelInterface
138
    {
139
        $result = (array) ResponseUtil::handle($response);
140
141 View Code Duplication
        if (!is_array($result) ||
0 ignored issues
show
This code seems to be duplicated across 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...
142
            !array_key_exists('access_token', $result) ||
143
            !array_key_exists('expires_in', $result) ||
144
            !array_key_exists('token_type', $result)
145
        ) {
146
            throw new InvalidResponseException();
147
        }
148
149
        return new self(
150
            $result['access_token'],
151
            $result['expires_in'],
152
            $result['token_type'],
153
            new \DateTime()
154
        );
155
    }
156
}
157