Issues (34)

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.

AggregationHandler/Services/SnapshotService.php (1 issue)

Severity

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 Spiral\Snapshotter\AggregationHandler\Services;
4
5
use Spiral\Core\Service;
6
use Spiral\Debug\SnapshotInterface;
7
use Spiral\Snapshotter\AggregationHandler\Database\IncidentRecord;
8
use Spiral\Snapshotter\AggregationHandler\Database\SnapshotRecord;
9
use Spiral\Snapshotter\AggregationHandler\Database\Sources\SnapshotSource;
10
use Spiral\Snapshotter\AggregationHandler\Database\Sources\IncidentSource;
11
12
class SnapshotService extends Service
13
{
14
    /** @var null|SnapshotSource */
15
    private $source = null;
16
17
    /**
18
     * AggregationService constructor.
19
     *
20
     * @param SnapshotSource $source
21
     */
22
    public function __construct(SnapshotSource $source)
23
    {
24
        $this->source = $source;
25
    }
26
27
    /**
28
     * @return SnapshotSource
29
     */
30
    public function getSource(): SnapshotSource
31
    {
32
        return $this->source;
33
    }
34
35
    /**
36
     * Select or create new Aggregation (you must save entity by yourself).
37
     *
38
     * @param string $hash
39
     * @return SnapshotRecord
40
     */
41
    public function getByHash(string $hash): SnapshotRecord
42
    {
43
        /** @var SnapshotRecord $snapshot */
44
        $snapshot = $this->source->findByHash($hash);
45
        if (empty($snapshot)) {
46
            $snapshot = $this->source->create();
47
            $snapshot->exception_hash = $hash;
48
        }
49
50
        return $snapshot;
51
    }
52
53
    /**
54
     * Count occurrence by intervals.
55
     *
56
     * @param SnapshotRecord $snapshot
57
     * @param IncidentSource $source
58
     * @return array
59
     */
60
    public function countOccurred(SnapshotRecord $snapshot, IncidentSource $source): array
61
    {
62
        $daily = $this->countIntervalOccurred($snapshot, $source, new \DateInterval('P1D'));
63
        $weekly = $this->countIntervalOccurred($snapshot, $source, new \DateInterval('P7D'));
64
        $monthly = $this->countIntervalOccurred($snapshot, $source, new \DateInterval('P1M'));
65
        $yearly = $this->countIntervalOccurred($snapshot, $source, new \DateInterval('P1Y'));
66
67
        return compact('daily', 'weekly', 'monthly', 'yearly');
68
    }
69
70
    /**
71
     * @param SnapshotRecord $aggregation
72
     * @param IncidentSource $source
73
     * @param \DateInterval  $interval
74
     * @return int
75
     */
76
    private function countIntervalOccurred(
77
        SnapshotRecord $aggregation,
78
        IncidentSource $source,
79
        \DateInterval $interval
80
    ): int
81
    {
82
        return $source->findBySnapshot($aggregation)->where(
83
            'time_created',
84
            '>=',
0 ignored issues
show
The call to RecordSelector::where() has too many arguments starting with '>='.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
85
            (new \DateTime('now'))->sub($interval)
86
        )->count();
87
    }
88
89
    /**
90
     * Creates unique hash to allow aggregating snapshots.
91
     *
92
     * @param SnapshotInterface $snapshot
93
     * @return string
94
     */
95
    public static function makeHash(SnapshotInterface $snapshot): string
96
    {
97
        return hash('sha256', $snapshot->getMessage());
98
    }
99
100
    /**
101
     * @param SnapshotRecord $snapshot
102
     */
103
    public function delete(SnapshotRecord $snapshot)
104
    {
105
        $snapshot->archiveLastIncident();
106
        $snapshot->forgetLastIncident();
107
108
        $incidents = $snapshot->getIncidentsHistory();
109
110
        /** @var IncidentRecord $incident */
111
        foreach ($incidents as $incident) {
112
            $incident->delete();
113
        }
114
115
        $snapshot->save();
116
    }
117
}