Issues (13)

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/Jwt/ContentJwt.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
/*
6
 * This file is part of the AppleApnPush package
7
 *
8
 * (c) Vitaliy Zhuk <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code
12
 */
13
14
namespace Apple\ApnPush\Jwt;
15
16
/**
17
 * The JWT token with content for certificate. You can use this certificate, if you save content to database
18
 * or another storage. Before get certificate file, this system create a temporary file certificate
19
 * and returns path to it. After close connection (destruct), the temporary file
20
 * will be removed.
21
 */
22
class ContentJwt implements JwtInterface
23
{
24
    /**
25
     * @var string
26
     */
27
    private $teamId;
28
29
    /**
30
     * @var string
31
     */
32
    private $key;
33
34
    /**
35
     * @var string
36
     */
37
    private $content;
38
39
    /**
40
     * @var string
41
     */
42
    private $tmpDir;
43
44
    /**
45
     * @var string
46
     */
47
    private $certificateFilePath;
48
49
    /**
50
     * Constructor.
51
     *
52
     * @param string $teamId
53
     * @param string $key
54
     * @param string $content
55
     * @param string $tmpDir
56
     */
57
    public function __construct(string $teamId, string $key, string $content, string $tmpDir)
58
    {
59
        $this->teamId = $teamId;
60
        $this->key = $key;
61
        $this->content = $content;
62
        $this->tmpDir = $tmpDir;
63
    }
64
65
    /**
66
     * Implement __destruct
67
     * Remove temporary file
68
     */
69
    public function __destruct()
70
    {
71
        if ($this->certificateFilePath) {
72
            $this->removeTemporaryFile($this->certificateFilePath);
73
        }
74
    }
75
76
    /**
77
     * {@inheritdoc}
78
     */
79
    public function getTeamId(): string
80
    {
81
        return $this->teamId;
82
    }
83
84
    /**
85
     * {@inheritdoc}
86
     */
87
    public function getKey(): string
88
    {
89
        return $this->key;
90
    }
91
92
    /**
93
     * {@inheritdoc}
94
     */
95 View Code Duplication
    public function getPath(): string
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...
96
    {
97
        if ($this->certificateFilePath) {
98
            $this->removeTemporaryFile($this->certificateFilePath);
99
        }
100
101
        $this->certificateFilePath = $this->createTemporaryFile();
102
        \file_put_contents($this->certificateFilePath, $this->content);
103
104
        return $this->certificateFilePath;
105
    }
106
107
    /**
108
     * Create a temporary file
109
     *
110
     * @return string Path to temporary file
111
     *
112
     * @throws \RuntimeException
113
     */
114 View Code Duplication
    private function createTemporaryFile(): string
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...
115
    {
116
        $tmpDir = $this->tmpDir;
117
118
        $tmpFileName = \md5(\uniqid((string) \mt_rand(), true)).'.p8';
119
120
        $tmpFilePath = $tmpDir.'/'.$tmpFileName;
121
122
        $errorCode = $errorMessage = null;
123
124
        \set_error_handler(function ($errCode, $errMessage) use (&$errorCode, &$errorMessage) {
125
            $errorCode = $errCode;
126
            $errorMessage = $errMessage;
127
        });
128
129
        if (!\file_exists($tmpDir)) {
130
            \mkdir($tmpDir, 0600, true);
131
132
            if ($errorCode || $errorMessage) {
133
                \restore_error_handler();
134
135
                // Error create directory
136
                throw new \RuntimeException(sprintf(
137
                    'Can not create temporary directory "%s". Error: %s [%d].',
138
                    $tmpDir,
139
                    $errorMessage ?: 'Undefined',
140
                    $errorCode ?: '0'
141
                ));
142
            }
143
        }
144
145
        \touch($tmpFilePath);
146
147
        if ($errorCode || $errorMessage) {
148
            \restore_error_handler();
149
150
            // Error create file
151
            throw new \RuntimeException(sprintf(
152
                'Can not create temporary certificate file "%s". Error: %s [%d].',
153
                $tmpFilePath,
154
                $errorMessage ?: 'Undefined',
155
                $errorCode ?: '0'
156
            ));
157
        }
158
159
        \restore_error_handler();
160
161
        return $tmpFilePath;
162
    }
163
164
    /**
165
     * Remove temporary file
166
     *
167
     * @param string $filePath
168
     */
169
    private function removeTemporaryFile($filePath): void
170
    {
171
        // Set custom error handler for suppress error
172
        \set_error_handler(function () {
173
        });
174
175
        \unlink($filePath);
176
177
        \restore_error_handler();
178
    }
179
}
180