Issues (23)

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/Snapshots/History.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
/** History class */
3
4
namespace smtech\GradingAnalytics\Snapshots;
5
6
use smtech\GradingAnalytics\Snapshots\Exception\SnapshotException;
7
8
/**
9
 * A class to query and cache the history of a course's statistics
10
 *
11
 * @author Seth Battis <[email protected]>
12
 */
13
class History extends CacheableDatabase
14
{
15
    /**
16
     * The Canvas ID of the course
17
     * @var string|integer
18
     */
19
    protected $courseId;
20
21
    /**
22
     * The course history
23
     * @var array
24
     */
25
    protected static $data;
26
27
    /**
28
     * Construct a history object
29
     *
30
     * Note that the actual history will be queried and/or cached just in time
31
     * when needed, not during instantiation.
32
     *
33
     * @param \mysqli|\smtech\ReflexiveCanvasLTI\Toolbox|CacheableDatabase $databaseProvider
34
     *        An object containing a reusable mysqli access object
35
     * @param string|integer $courseId Canvas ID of the course
36
     *
37
     * @throws SnapshotException `SnapshotException::COURSE_ID` If `$courseId`
38
     *         does not appear to be a valid (numeric) Canvas course ID.
39
     */
40
    public function __construct($databaseProvider, $courseId)
41
    {
42
        parent::__construct($databaseProvider);
43
44
        if (is_numeric($courseId)) {
45
            $this->courseId = $courseId;
0 ignored issues
show
Documentation Bug introduced by
It seems like $courseId can also be of type double. However, the property $courseId is declared as type string|integer. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
46
        } else {
47
            throw new SnapshotException(
48
                'Numeric Course ID required',
49
                SnapshotException::COURSE_ID
50
            );
51
        }
52
    }
53
54
    /**
55
     * Get the numeric Canvas course ID
56
     *
57
     * @return string|integer
58
     */
59
    public function getCourseId()
60
    {
61
        return $this->courseId;
62
    }
63
64
    /**
65
     * Get the numeric Canvas account ID of the course's parent department
66
     *
67
     * @return string|integer|false Returns `FALSE` if no parent department is
68
     *         included in the most recent collected course statistics
69
     */
70
    public function getDepartmentId()
71
    {
72
        if ($this->cacheHistory()) {
73
            return (integer) static::$data[$this->getCourseID()][0]['course[account_id]'];
74
        }
75
        return false;
76
    }
77
78
    /**
79
     * Get the date of the most recently collected course statistics
80
     *
81
     * @return string|false The date in `YYYY-MM-DD` format or `FALSE` if no
82
     *                          timestamp is available.
83
     */
84
    public function getCurrentTimestamp()
85
    {
86
        if ($this->cacheHistory()) {
87
            return substr(static::$data[$this->getCourseId()][0]['timestamp'], 0, 10);
88
        }
89
        return false;
90
    }
91
92
    /**
93
     * Trigger a caching of the course history, if not already cached
94
     *
95
     * @return boolean `TRUE` if there is a non-empty cache of course
96
     *                        statistics to work with, `FALSE` otherwise
97
     */
98
    public function cacheHistory()
99
    {
100
        $courseId = $this->getCourseId();
101
        if (empty(static::$data[$courseId])) {
102
            static::$data = $this->getCache()->getCache($courseId);
103
            if (empty($this->data)) {
104
                if ($response = $this->sql->query("
105
                    SELECT * FROM `course_statistics`
106
                        WHERE
107
                            `course[id]` = '$courseId'
108
                        ORDER BY
109
                            `timestamp` DESC
110
                ")) {
111
                    while ($row = $response->fetch_assoc()) {
112
                        static::$data[$courseId][] = $row;
113
                    }
114
                    $this->getCache()->setCache($courseId, static::$data[$courseId]);
115
                }
116
            }
117
        }
118
        return (is_array(static::$data) &&
119
            is_array(static::$data[$courseId]) &&
120
            count(static::$data[$courseId]) > 0
121
        );
122
    }
123
124
    /**
125
     * Get the course's history of statistics
126
     *
127
     * @link https://smtech.github.io/grading-analytics/definitions.html Online
128
     *       documentation of course statistic fields
129
     *
130
     * @return array|false One row per course statistic collected daily, as
131
     *                         described in the documentation, or `FALSE` if no
132
     *                         statistics are available
133
     */
134
    public function getHistory()
135
    {
136
        if ($this->cacheHistory()) {
137
            return static::$data[$this->getCourseId()];
138
        }
139
        return false;
140
    }
141
}
142