Issues (27)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  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.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  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.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  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.
  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.
  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.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
  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.
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  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.
  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.
  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.
  Header Injection
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/TestCase/Cert.php (3 issues)

Labels
Severity
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\Module\monitor\TestCase;
6
7
use SimpleSAML\Module\monitor\State;
8
use SimpleSAML\Module\monitor\TestData;
9
use SimpleSAML\Module\monitor\TestResult;
10
11
use function abs;
12
use function array_key_exists;
13
use function intval;
14
15
class Cert extends \SimpleSAML\Module\monitor\TestCaseFactory
16
{
17
    /** @var array */
18
    private array $certInfo = [];
19
20
    /** @var integer */
21
    private int $expiration;
22
23
    /** @var integer|null */
24
    private ?int $certExpirationWarning = null;
25
26
27
    /**
28
     * @var \SimpleSAML\Module\monitor\TestData $testData
29
     *
30
     * @return void
31
     */
32
    protected function initialize(TestData $testData): void
33
    {
34
        $this->setCategory($testData->getInputItem('category'));
0 ignored issues
show
It seems like $testData->getInputItem('category') can also be of type null; however, parameter $category of SimpleSAML\Module\monito...eFactory::setCategory() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

34
        $this->setCategory(/** @scrutinizer ignore-type */ $testData->getInputItem('category'));
Loading history...
35
        $this->setCertInfo($testData->getInputItem('certData'));
0 ignored issues
show
It seems like $testData->getInputItem('certData') can also be of type null; however, parameter $certInfo of SimpleSAML\Module\monito...ase\Cert::setCertInfo() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

35
        $this->setCertInfo(/** @scrutinizer ignore-type */ $testData->getInputItem('certData'));
Loading history...
36
        $this->setCertExpirationWarning($testData->getInputItem('certExpirationWarning'));
0 ignored issues
show
It seems like $testData->getInputItem('certExpirationWarning') can also be of type null; however, parameter $certExpirationWarning of SimpleSAML\Module\monito...CertExpirationWarning() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

36
        $this->setCertExpirationWarning(/** @scrutinizer ignore-type */ $testData->getInputItem('certExpirationWarning'));
Loading history...
37
38
        parent::initialize($testData);
39
    }
40
41
42
    /**
43
     * @return string
44
     */
45
    public function getSubject(): string
46
    {
47
        $certInfo = $this->getCertInfo();
48
        if (
49
            isset($certInfo['subject'])
50
            && !empty($certInfo['subject'])
51
            && array_key_exists('CN', $certInfo['subject'])
52
        ) {
53
            return 'CN=' . $certInfo['subject']['CN'];
54
        } elseif (isset($certInfo['serialNumber'])) {
55
            return 'SN=' . $certInfo['serialNumber'];
56
        } else {
57
            return 'UNKNOWN';
58
        }
59
    }
60
61
62
    /**
63
     * @param array $certInfo
64
     *
65
     * @return void
66
     */
67
    protected function setCertInfo(array $certInfo): void
68
    {
69
        $this->certInfo = $certInfo;
70
    }
71
72
73
    /**
74
     * @return array
75
     */
76
    protected function getCertInfo(): array
77
    {
78
        return $this->certInfo;
79
    }
80
81
82
    /**
83
     * @param int $certExpirationWarning
84
     *
85
     * @return void
86
     */
87
    protected function setCertExpirationWarning(int $certExpirationWarning): void
88
    {
89
        $this->certExpirationWarning = $certExpirationWarning;
90
    }
91
92
93
    /**
94
     * @return int|null
95
     */
96
    protected function getCertExpirationWarning(): ?int
97
    {
98
        return $this->certExpirationWarning;
99
    }
100
101
102
    /**
103
     * @return int
104
     */
105
    protected function getExpiration(): int
106
    {
107
        return $this->expiration;
108
    }
109
110
111
    /**
112
     * @param integer $expiration
113
     *
114
     * @return void
115
     */
116
    private function setExpiration(int $expiration): void
117
    {
118
        $this->expiration = $expiration;
119
    }
120
121
122
    /**
123
     * @return void
124
     */
125
    protected function calculateExpiration(): void
126
    {
127
        $certInfo = $this->getCertInfo();
128
        $expiration = intval(($certInfo['validTo_time_t'] - time()) / 86400);
129
        $this->setExpiration($expiration);
130
    }
131
132
133
    /**
134
     * @return void
135
     */
136
    public function invokeTest(): void
137
    {
138
        $this->calculateExpiration();
139
140
        $threshold = $this->getCertExpirationWarning();
141
        $expiration = $this->getExpiration();
142
143
        $days = abs($expiration);
144
        $daysStr = $days . ' ' . (($days === 1) ? 'day' : 'days');
145
146
        $testResult = new TestResult($this->getCategory(), $this->getSubject());
147
148
        if ($expiration < 0) {
149
            $testResult->setState(State::ERROR);
150
            $testResult->setMessage('Certificate has expired ' . $daysStr . ' ago');
151
        } elseif ($expiration <= $threshold) {
152
            $testResult->setState(State::WARNING);
153
            $testResult->setMessage('Certificate will expire in ' . $daysStr);
154
        } else {
155
            $testResult->setState(State::OK);
156
            $testResult->setMessage('Certificate valid for another ' . $daysStr);
157
        }
158
159
        $testResult->addOutput($expiration, 'expiration');
160
        $this->setTestResult($testResult);
161
    }
162
}
163