Issues (563)

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.

app/Models/Eloquent/Problem.php (4 issues)

1
<?php
2
3
namespace App\Models\Eloquent;
4
5
use Illuminate\Database\Eloquent\Model;
6
use App\Models\Eloquent\Contest;
7
use Auth;
8
use Carbon;
9
use DB;
10
use Exception;
11
use App\Models\Traits\LikeScope;
12
use DateTimeInterface;
13
14
class Problem extends Model
15
{
16
    use LikeScope;
17
18
    protected $table = 'problem';
19
    protected $primaryKey = 'pid';
20
    const UPDATED_AT = "update_date";
21
22
    protected function serializeDate(DateTimeInterface $date)
23
    {
24
        return $date->format('Y-m-d H:i:s');
25
    }
26
27
    public function getReadableNameAttribute()
28
    {
29
        return $this->pcode . '. ' . $this->title;
30
    }
31
32
    public function submissions()
33
    {
34
        return $this->hasMany('App\Models\Eloquent\Submission', 'pid', 'pid');
35
    }
36
37
    public function problemSamples()
38
    {
39
        return $this->hasMany('App\Models\Eloquent\ProblemSample', 'pid', 'pid');
40
    }
41
42
    public function solutions()
43
    {
44
        return $this->hasMany('App\Models\Eloquent\ProblemSolution', 'pid', 'pid');
45
    }
46
47
    public function homework_problems()
48
    {
49
        return $this->hasMany('App\Models\Eloquent\GroupHomeworkProblem', 'problem_id', 'pid');
50
    }
51
52
    public function onlinejudge()
53
    {
54
        return $this->belongsTo('App\Models\Eloquent\OJ', 'OJ', 'oid');
55
    }
56
57
    public function getProblemStatusAttribute()
58
    {
59
        return $this->getProblemStatus();
60
    }
61
62
    public function getProblemStatus($userID = null, $contestID = null, Carbon $till = null)
63
    {
64
        if (blank($userID)) {
65
            if (Auth::guard('web')->check()) {
66
                $userID = Auth::guard('web')->user()->id;
0 ignored issues
show
Accessing id on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
67
            }
68
        }
69
70
        if (filled($userID)) {
71
            $probStatus = $this->getProblemStatusFromDB($userID, $contestID, $till);
72
            if (blank($probStatus)) {
73
                return [
74
                    "icon" => "checkbox-blank-circle-outline",
75
                    "color" => "wemd-grey-text"
76
                ];
77
            } else {
78
                return [
79
                    "icon" => $probStatus->verdict == "Accepted" ? "checkbox-blank-circle" : "cisco-webex",
80
                    "color" => $probStatus->color
81
                ];
82
            }
83
        } else {
84
            return [
85
                "icon" => "checkbox-blank-circle-outline",
86
                "color" => "wemd-grey-text"
87
            ];
88
        }
89
    }
90
91
    private function getProblemStatusFromDB($userID, $contestID = null, Carbon $till = null)
92
    {
93
        $endedAt = Carbon::now();
94
95
        if (filled($contestID)) {
96
            try {
97
                $endedAt = Carbon::parse(Contest::findOrFail($contestID)->endedAt);
0 ignored issues
show
The property endedAt does not seem to exist on App\Models\Eloquent\Contest. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
98
            } catch (Exception $e) {
99
                return null;
100
            }
101
        }
102
103
        // Get the very first AC record
104
105
        $acRecords = $this->submissions()->where([
106
            'uid' => $userID,
107
            'cid' => $contestID,
108
            'verdict' => 'Accepted'
109
        ]);
110
        if (filled($contestID)) {
111
            $acRecords = $acRecords->where("submission_date", "<", $endedAt->timestamp);
112
        }
113
        if (filled($till)) {
114
            $acRecords = $acRecords->where("submission_date", "<", $till->timestamp);
115
        }
116
        $acRecords = $acRecords->orderBy('submission_date', 'desc')->first();
117
        if (blank($acRecords)) {
118
            $pacRecords = $this->submissions()->where([
119
                'uid' => $userID,
120
                'cid' => $contestID,
121
                'verdict' => 'Partially Accepted'
122
            ]);
123
            if (filled($contestID)) {
124
                $pacRecords = $pacRecords->where("submission_date", "<", $endedAt->timestamp);
125
            }
126
            if (filled($till)) {
127
                $pacRecords = $pacRecords->where("submission_date", "<", $till->timestamp);
128
            }
129
            $pacRecords = $pacRecords->orderBy('submission_date', 'desc')->first();
130
            if (blank($pacRecords)) {
131
                $otherRecords = $this->submissions()->where([
132
                    'uid' => $userID,
133
                    'cid' => $contestID
134
                ]);
135
                if (filled($contestID)) {
136
                    $otherRecords = $otherRecords->where("submission_date", "<", $endedAt->timestamp);
137
                }
138
                if (filled($till)) {
139
                    $otherRecords = $otherRecords->where("submission_date", "<", $till->timestamp);
140
                }
141
                return $otherRecords->orderBy('submission_date', 'desc')->first();
142
            }
143
            return $pacRecords;
144
        } else {
145
            return $acRecords;
146
        }
147
    }
148
149
    public function users_latest_submission($users, $contestID = null, Carbon $till = null, $verdictFilter = [])
150
    {
151
        if (filled($contestID)) {
152
            $endedAt = Carbon::parse(Contest::findOrFail($contestID)->endedAt);
0 ignored issues
show
The property endedAt does not seem to exist on App\Models\Eloquent\Contest. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
153
        }
154
155
        $lastRecordSubQuery = $this->submissions()->select('uid', DB::raw('MAX(submission_date) as submission_date'))->whereIntegerInRaw('uid', $users)->where('cid', $contestID)->groupBy('uid');
156
157
        if (filled($contestID)) {
158
            $lastRecordSubQuery = $lastRecordSubQuery->where("submission_date", "<", $endedAt->timestamp);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $endedAt does not seem to be defined for all execution paths leading up to this point.
Loading history...
159
        }
160
161
        if (filled($till)) {
162
            $lastRecordSubQuery = $lastRecordSubQuery->where("submission_date", "<", $till->timestamp);
163
        }
164
165
        if(filled($verdictFilter)) {
166
            $lastRecordSubQuery = $lastRecordSubQuery->whereIn('verdict', $verdictFilter);
167
        }
168
169
        $query = DB::table(DB::raw("({$lastRecordSubQuery->toSql()}) last_sub"))->leftJoinSub(Submission::toBase(), 'submissions', function ($join) {
170
            $join->on('last_sub.submission_date', '=', 'submissions.submission_date')->on('last_sub.uid', '=', 'submissions.uid');
171
        })->select('sid', 'last_sub.submission_date as submission_date', 'last_sub.uid as uid', 'verdict', 'color')->orderBy('uid', 'ASC');
172
173
        return $query->mergeBindings($lastRecordSubQuery->toBase());
174
    }
175
176
    /*     public function getSamplesAttribute()
177
    {
178
        return array_map(function($sample) {
179
            return [
180
                'sample_input' => $sample->sample_input,
181
                'sample_output' => $sample->sample_output,
182
                'sample_note' => $sample->sample_note,
183
            ];
184
        }, $this->problemSamples()->select('sample_input', 'sample_output', 'sample_note')->get()->all());
185
    }
186
187
    public function setSamplesAttribute($value)
188
    {
189
        return;
190
    } */
191
}
192