GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Issues (16)

Security Analysis    no request data  

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/Monar/TwoChanDriver.php (5 issues)

Labels
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 Localdisk\Monar;
4
5
use GuzzleHttp\Cookie\CookieJar;
6
use GuzzleHttp\Cookie\SetCookie;
7
use Illuminate\Support\Collection;
8
use Localdisk\Monar\Exceptions\MonarException;
9
10
class TwoChanDriver extends AbstractDriver
11
{
12
    /**
13
     * @var string
14
     */
15
    protected $encoding = 'SJIS-win';
16
17
    /**
18
     * get threads.
19
     *
20
     * @return \Illuminate\Support\Collection
21
     * @throws MonarException
22
     * @throws \GuzzleHttp\Exception\GuzzleException
23
     */
24
    public function threads(): Collection
25
    {
26
        $body = $this->request('GET', $this->threadsUrl());
27
28
        return $this->parseThreadsCollection($body);
29
    }
30
31
    /**
32
     * get messages.
33
     *
34
     * @param int|null $start
35
     * @param int|null $end
36
     *
37
     * @return \Illuminate\Support\Collection
38
     * @throws MonarException
39
     * @throws \GuzzleHttp\Exception\GuzzleException
40
     */
41
    public function messages(?int $start = null, ?int $end = null): Collection
42
    {
43
        $body = $this->request('GET', $this->messagesUrl($start, $end));
44
45
        return $this->parseDatCollection($body, $start, $end);
46
    }
47
48
    /**
49
     * post message.
50
     *
51
     * @param string $name
52
     * @param string $email
53
     * @param string|null $text
54
     *
55
     * @return string
56
     * @throws MonarException
57
     * @throws \GuzzleHttp\Exception\GuzzleException
58
     */
59
    public function post(?string $name = '', ?string $email = '', ?string $text = null): string
60
    {
61
        mb_convert_variables('SJIS-win', 'UTF-8', $name, $email, $text);
62
        $params = [
63
            'bbs' => $this->board,
64
            'key' => $this->thread,
65
            'time' => time(),
66
            'FROM' => $name,
67
            'mail' => $email,
68
            'MESSAGE' => $text,
69
            'submit' => $this->encode('書き込む', 'SJIS-win', 'UTF-8'),
70
        ];
71
        $headers = [
72
            'Host' => parse_url($this->url, PHP_URL_HOST),
73
            'Referer' => $this->url,
74
            'User-Agent' => 'Monazilla/1.00',
75
        ];
76
77
        $cookie = new CookieJar();
78
        $response = $this->request('POST', $this->postUrl(), [
79
            'headers' => $headers,
80
            'form_params' => $params,
81
            'cookies' => $cookie,
82
        ]);
83
84
        if ($this->isError($response)) {
85
            throw new MonarException($response);
86
        }
87
88
        if ($this->confirm($response)) {
89
            $cookie->setCookie(SetCookie::fromString('IS_COOKIE=1'));
90
            $response = $this->request('POST', $this->postUrl(), [
91
                'headers' => $headers,
92
                'form_params' => $params,
93
                'cookies' => $cookie,
94
            ]);
95
        }
96
97
        return $response;
98
    }
99
100
    /**
101
     * parse url.
102
     *
103
     * @return void
104
     */
105
    protected function parse(): void
106
    {
107
        $parsed = parse_url($this->url);
108
        $paths = $this->renewArray(explode('/', parse_url($this->url, PHP_URL_PATH)));
109
110
        $this->baseUrl = $parsed['scheme'].'://'.$parsed['host'];
111
        $this->category = '';
112
113
        if (\count($paths) === 1) {
114
            $this->board = $paths[0];
115
            $this->thread = '';
116
        } else {
117
            $this->board = $paths[2];
118
            $this->thread = $paths[3];
119
        }
120
    }
121
122
    /**
123
     * parse dat collection.
124
     *
125
     * @param string $body
126
     *
127
     * @return \Illuminate\Support\Collection
128
     */
129
    protected function parseDatCollection(string $body, ?int $start = null, ?int $end = null): Collection
130
    {
131
        $lines = array_filter(explode("\n", $body), '\strlen');
132
133
        $lineCount = count($lines);
134
135
        if (null === $start) {
136
            $start = 1;
137
        }
138
139
        if (null !== $end) {
140
            $end = $end - $start + 1;
141
        }
142
143
        if ($end > $lineCount) {
144
            $end = $lineCount;
145
        }
146
147
        $messages = array_slice($lines, $start - 1, $end);
148
149
        $collection = collect();
150
151
        $number = $start;
152
        foreach ($messages as $message) {
153
            [$name, $email, $date, $body] = explode('<>', $message);
0 ignored issues
show
The variable $name does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
The variable $email does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
The variable $date does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
154
            $name = trim(strip_tags($name));
155
            $body = strip_tags($body, '<br>');
156
            $resid = mb_substr($date, strpos($date, ' ID:') + 2);
157
            $date = mb_substr($date, 0, strpos($date, ' ID:') - 2);
158
159
            $collection->push(compact('number', 'name', 'email', 'date', 'body', 'resid'));
160
161
            $number++;
162
        }
163
164
        return $collection;
165
    }
166
167
    /**
168
     * parse threads collection.
169
     *
170
     * @param string $body
171
     *
172
     * @return \Illuminate\Support\Collection
173
     */
174
    protected function parseThreadsCollection(string $body): Collection
175
    {
176
        $threads = array_filter(explode("\n", $body), '\strlen');
177
178
        return collect(array_map(function ($elem) {
179
            [$id, $tmp] = explode('.dat<>', $elem);
0 ignored issues
show
The variable $id does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
The variable $tmp does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
180
            preg_match('/^(.*)\((\d+)\)\z/', $tmp, $matches);
181
182
            return [
183
                'url' => vsprintf('http://%s/test/read.cgi/%s/%d', [
184
                    parse_url($this->url, PHP_URL_HOST),
185
                    $this->board,
186
                    $id,
187
                ]),
188
                'id' => $id,
189
                'title' => trim($matches[1]),
190
                'count' => $matches[2],
191
            ];
192
        }, $threads));
193
    }
194
195
    /**
196
     * build message url.
197
     *
198
     * @param int $start
199
     * @param int|null $end
200
     *
201
     * @return string
202
     */
203
    protected function messagesUrl(?int $start = null, ?int $end = null): string
204
    {
205
        return "{$this->baseUrl}/{$this->board}/dat/{$this->thread}.dat";
206
    }
207
208
    /**
209
     * build thread url.
210
     *
211
     * @return string
212
     */
213
    protected function threadsUrl(): string
214
    {
215
        return "{$this->baseUrl}/{$this->board}/subject.txt";
216
    }
217
218
    /**
219
     * build post url.
220
     *
221
     * @return string
222
     */
223
    protected function postUrl(): string
224
    {
225
        return "{$this->baseUrl}/test/bbs.cgi";
226
    }
227
228
    /**
229
     * 書き込み確認かどうか.
230
     *
231
     * @param  string $html
232
     *
233
     * @return bool
234
     */
235
    private function confirm(string $html): bool
236
    {
237
        return strpos($html, '書き込み確認') !== false;
238
    }
239
240
    /**
241
     * @param string $html
242
     *
243
     * @return bool
244
     */
245
    private function isError(string $html): bool
246
    {
247
        return strpos($html, '<!-- 2ch_X:error -->') !== false;
248
    }
249
}
250