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/Babel/Crawl/CrawlerBase.php (6 issues)

1
<?php
2
3
namespace App\Babel\Crawl;
4
5
use App\Models\ProblemModel;
6
use KubAT\PhpSimple\HtmlDomParser;
7
use Auth;
8
use Exception;
9
10
class CrawlerBase
11
{
12
    public $pro=[
13
        'file'=> 0,
14
        'file_url'=> null,
15
        'pcode'=>'',
16
        'solved_count'=>'',
17
        'time_limit'=>'',
18
        'memory_limit'=>'',
19
        'title'=>'',
20
        'OJ'=>'',
21
        'description'=>'',
22
        'input'=>'',
23
        'output'=>'',
24
        'note'=>'',
25
        'input_type'=>'',
26
        'output_type'=>'',
27
        'contest_id'=>'',
28
        'index_id'=>'',
29
        'origin'=>'',
30
        'source'=>'',
31
        'sample'=>[],
32
        'markdown'=>0,
33
        'tot_score'=>1,
34
        'partial'=>0,
35
        'special_compiler'=>null,
36
    ];
37
38
    public $data=null;
39
    public $command=null;
40
41
    /**
42
     * Initial
43
     *
44
     * @return Response
0 ignored issues
show
The type App\Babel\Crawl\Response was not found. Did you mean Response? If so, make sure to prefix the type with \.
Loading history...
45
     */
46
    public function __construct()
47
    {
48
    }
49
50
    protected function _resetPro()
51
    {
52
        $this->pro=[
53
            'file'=> 0,
54
            'pcode'=>'',
55
            'solved_count'=>'',
56
            'time_limit'=>'',
57
            'memory_limit'=>'',
58
            'title'=>'',
59
            'OJ'=>'',
60
            'description'=>'',
61
            'input'=>'',
62
            'output'=>'',
63
            'note'=>'',
64
            'input_type'=>'',
65
            'output_type'=>'',
66
            'contest_id'=>'',
67
            'index_id'=>'',
68
            'origin'=>'',
69
            'source'=>'',
70
            'sample'=>[],
71
            'markdown'=>0,
72
            'tot_score'=>1,
73
            'partial'=>0,
74
            'special_compiler'=>null,
75
            'order_index'=>null,
76
        ];
77
    }
78
79
    public function importCommandLine($commandTemp)
80
    {
81
        $this->command=$commandTemp;
82
    }
83
84
    public static function cmp($a, $b)
85
    {
86
        return ($a[1]>$b[1]) ?-1 : 1;
87
    }
88
89
    private function _cacheImage($data)
90
    {
91
        if (!isset($data["ori"]) || !isset($data["path"]) || !isset($data["baseurl"]) || !isset($data["space_deli"]) || !isset($data["cookie"])) {
92
            throw new Exception("data is not completely exist in cacheImage");
93
        }
94
        $ori=$data["ori"];
95
        $path=$data["path"];
96
        $baseurl=$data["baseurl"];
97
        $space_deli=$data["space_deli"];
98
        $cookie=$data["cookie"];
99
100
        $para["path"]=$path;
0 ignored issues
show
Comprehensibility Best Practice introduced by
$para was never initialized. Although not strictly required by PHP, it is generally a good practice to add $para = array(); before regardless.
Loading history...
101
        $para["base"]=$baseurl;
102
        $para["trans"]=!$space_deli;
103
        $para["cookie"]=$cookie;
104
105
        if ($space_deli) {
106
            $reg="/< *im[a]?g[^>]*src *= *[\"\\']?([^\"\\' >]*)[^>]*>/si";
107
        } else {
108
            $reg="/< *im[a]?g[^>]*src *= *[\"\\']?([^\"\\'>]*)[^>]*>/si";
109
        }
110
111
        return preg_replace_callback($reg, function($matches) use ($para) {
112
            global $config;
113
            $url=trim($matches[1]);
114
            if (stripos($url, "http://")===false && stripos($url, "https://")===false) {
115
                if ($para["trans"]) {
116
                    $url=str_replace(" ", "%20", $url);
117
                }
118
                $url=$para["base"].$url;
119
            }
120
            $name=basename($url);
121
            $name="images/".strtr($name, ":", "_");
122
            $result=str_replace(trim($matches[1]), "online_Judges/spoj/images/".strtr(basename($url), ":", "_"), $matches[0]);
123
            $ch=curl_init();
124
            curl_setopt($ch, CURLOPT_URL, $url);
125
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
126
            curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
127
            if ($para["cookie"]!="") {
128
                curl_setopt($ch, CURLOPT_COOKIEFILE, $para["cookie"]);
129
            }
130
            curl_setopt($ch, CURLOPT_HEADER, 0);
131
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
132
            $content=curl_exec($ch);
133
            curl_close($ch);
134
            $fp=fopen($name, "wb");
135
            fwrite($fp, $content);
0 ignored issues
show
It seems like $content can also be of type true; however, parameter $data of fwrite() 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

135
            fwrite($fp, /** @scrutinizer ignore-type */ $content);
Loading history...
136
            fclose($fp);
137
            return $result;
138
        }, $ori);
139
    }
140
141
    public function procInfo($data)
142
    {
143
        if (isset($data["path"])) {
144
            $path=$data["path"];
145
        } else {
146
            throw new Exception("path is not exist in data");
147
        }
148
        if (isset($data["baseurl"])) {
149
            $baseurl=$data["baseurl"];
150
        } else {
151
            throw new Exception("baseurl is not exist in data");
152
        }
153
        if (isset($data["space_deli"])) {
154
            $space_deli=$data["space_deli"];
155
        } else {
156
            $space_deli=true;
157
        }
158
        if (isset($data["cookie"])) {
159
            $cookie=$data["cookie"];
160
        } else {
161
            $cookie="";
162
        }
163
164
        $this->pro["description"]=$this->_cacheImage($this->pro["description"], $path, $baseurl, $space_deli, $cookie);
0 ignored issues
show
The call to App\Babel\Crawl\CrawlerBase::_cacheImage() has too many arguments starting with $path. ( Ignorable by Annotation )

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

164
        /** @scrutinizer ignore-call */ 
165
        $this->pro["description"]=$this->_cacheImage($this->pro["description"], $path, $baseurl, $space_deli, $cookie);

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. Please note the @ignore annotation hint above.

Loading history...
165
        $this->pro["input"]=$this->_cacheImage($this->pro["input"], $path, $baseurl, $space_deli, $cookie);
166
        $this->pro["output"]=$this->_cacheImage($this->pro["output"], $path, $baseurl, $space_deli, $cookie);
167
        $this->pro["note"]=$this->_cacheImage($this->pro["note"], $path, $baseurl, $space_deli, $cookie);
168
    }
169
170
    public function getUrl($url)
171
    {
172
        $ch=curl_init();
173
        curl_setopt($ch, CURLOPT_URL, $url);
174
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
175
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
176
        curl_setopt($ch, CURLOPT_HEADER, 0);
177
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
178
        $content=curl_exec($ch);
179
        curl_close($ch);
180
        return $content;
181
    }
182
183
    public function insertProblem($oid=2)
0 ignored issues
show
The parameter $oid is not used and could be removed. ( Ignorable by Annotation )

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

183
    public function insertProblem(/** @scrutinizer ignore-unused */ $oid=2)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
184
    {
185
        $problemModel=new ProblemModel();
186
        return $problemModel->insertProblem($this->pro);
187
    }
188
189
    public function updateProblem($oid=2)
0 ignored issues
show
The parameter $oid is not used and could be removed. ( Ignorable by Annotation )

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

189
    public function updateProblem(/** @scrutinizer ignore-unused */ $oid=2)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
190
    {
191
        $problemModel=new ProblemModel();
192
        return $problemModel->updateProblem($this->pro);
193
    }
194
195
    protected function line($line)
196
    {
197
        if (is_null($this->command)) {
198
            echo $line;
199
        } else {
200
            $this->command->line($line);
201
        }
202
    }
203
}
204