Issues (211)

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.

src/Jobs/CleanupJob.php (5 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
namespace Symbiote\QueuedJobs\Jobs;
4
5
use SilverStripe\Core\Config\Config;
6
use SilverStripe\ORM\DB;
7
use SilverStripe\ORM\FieldType\DBDatetime;
8
use Symbiote\QueuedJobs\Services\AbstractQueuedJob;
9
use Symbiote\QueuedJobs\Services\QueuedJob;
10
11
/**
12
 * An queued job to clean out the QueuedJobDescriptor Table
13
 * which often gets too full
14
 *
15
 * @author Andrew Aitken-Fincham <[email protected]>
16
 */
17
class CleanupJob extends AbstractQueuedJob implements QueuedJob
18
{
19
20
    /**
21
     * How we will determine "stale"
22
     * Possible values: age, number
23
     * @config
24
     * @var string
25
     */
26
    private static $cleanup_method = "age";
0 ignored issues
show
The property $cleanup_method is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
27
28
    /**
29
     * Value associated with cleanupMethod
30
     * age => days, number => integer
31
     * @config
32
     * @var integer
33
     */
34
    private static $cleanup_value = 30;
0 ignored issues
show
The property $cleanup_value is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
35
36
    /**
37
     * Which JobStatus values are OK to be deleted
38
     * @config
39
     * @var array
40
     */
41
    private static $cleanup_statuses = array(
0 ignored issues
show
The property $cleanup_statuses is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
42
        "Complete",
43
        "Broken",
44
        // "Initialising",
45
        // "Running",
46
        // "New",
47
        // "Paused",
48
        // "Cancelled",
49
        // "Waiting",
50
    );
51
52
    /**
53
     * Check whether is enabled or not for BC
54
     * @config
55
     * @var boolean
56
     */
57
    private static $is_enabled = false;
0 ignored issues
show
The property $is_enabled is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
58
59
    /**
60
     * Required because we aren't extending object
61
     * @return Config_ForClass
62
     */
63
    public function config()
64
    {
65
        return Config::forClass(get_called_class());
66
    }
67
68
    /**
69
     * Defines the title of the job
70
     * @return string
71
     */
72
    public function getTitle()
73
    {
74
        return _t(
75
            'CleanupJob.Title',
76
            "Clean up old jobs from the database"
77
        );
78
    }
79
80
    /**
81
     * Set immediacy of job
82
     * @return int
83
     */
84
    public function getJobType()
85
    {
86
        $this->totalSteps = '1';
0 ignored issues
show
Documentation Bug introduced by
The property $totalSteps was declared of type integer, but '1' is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
87
        return QueuedJob::IMMEDIATE;
88
    }
89
90
    /**
91
     * Clear out stale jobs based on the cleanup values
92
     */
93
    public function process()
94
    {
95
        $statusList = implode('\', \'', $this->config()->cleanup_statuses);
96
        switch ($this->config()->cleanup_method) {
97
            // If Age, we need to get jobs that are at least n days old
98
            case "age":
99
                $cutOff = date(
100
                    "Y-m-d H:i:s",
101
                    strtotime(DBDatetime::now() .
102
                        " - " .
103
                        $this->config()->cleanup_value .
104
                        " days")
105
                );
106
                $stale = DB::query(
107
                    'SELECT "ID"
108
					FROM "QueuedJobDescriptor"
109
					WHERE "JobStatus"
110
					IN (\'' . $statusList . '\')
111
					AND "LastEdited" < \'' . $cutOff .'\''
112
                );
113
                $staleJobs = $stale->column("ID");
114
                break;
115
            // If Number, we need to save n records, then delete from the rest
116
            case "number":
117
                $fresh = DB::query(
118
                    'SELECT "ID"
119
					FROM "QueuedJobDescriptor"
120
					ORDER BY "LastEdited"
121
					ASC LIMIT ' . $this->config()->cleanup_value
122
                );
123
                $freshJobIDs = implode('\', \'', $fresh->column("ID"));
124
125
                $stale = DB::query(
126
                    'SELECT "ID"
127
					FROM "QueuedJobDescriptor"
128
					WHERE "ID"
129
					NOT IN (\'' . $freshJobIDs . '\')
130
					AND "JobStatus"
131
					IN (\'' . $statusList . '\')'
132
                );
133
                $staleJobs = $stale->column("ID");
134
                break;
135
            default:
136
                $this->addMessage("Incorrect configuration values set. Cleanup ignored");
137
                $this->isComplete = true;
138
                return;
139
        }
140
        if (empty($staleJobs)) {
141
            $this->addMessage("No jobs to clean up.");
142
            $this->isComplete = true;
143
            return;
144
        }
145
        $numJobs = count($staleJobs);
146
        $staleJobs = implode('\', \'', $staleJobs);
147
        DB::query('DELETE FROM "QueuedJobDescriptor"
148
			WHERE "ID"
149
			IN (\'' . $staleJobs . '\')');
150
        $this->addMessage($numJobs . " jobs cleaned up.");
151
        // let's make sure there is a cleanupJob in the queue
152
        if (Config::inst()->get('Symbiote\\QueuedJobs\\Jobs\\CleanupJob', 'is_enabled')) {
153
            $this->addMessage("Queueing the next Cleanup Job.");
154
            $cleanup = new CleanupJob();
155
            singleton('Symbiote\\QueuedJobs\\Services\\QueuedJobService')
156
                ->queueJob($cleanup, date('Y-m-d H:i:s', time() + 86400));
157
        }
158
        $this->isComplete = true;
159
        return;
160
    }
161
}
162