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 (2)

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/CrawlLogger.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
3
namespace Spatie\HttpStatusCheck;
4
5
use GuzzleHttp\Exception\RequestException;
6
use Psr\Http\Message\ResponseInterface;
7
use Psr\Http\Message\UriInterface;
8
use Spatie\Crawler\CrawlObserver;
9
use Symfony\Component\Console\Output\OutputInterface;
10
11
class CrawlLogger extends CrawlObserver
12
{
13
    const UNRESPONSIVE_HOST = 'Host did not respond';
14
    const REDIRECT = 'Redirect';
15
16
    /**
17
     * @var \Symfony\Component\Console\Output\OutputInterface
18
     */
19
    protected $consoleOutput;
20
21
    /**
22
     * @var array
23
     */
24
    protected $crawledUrls = [];
25
26
    /**
27
     * @var string|null
28
     */
29
    protected $outputFile = null;
30
31
    /**
32
     * @param \Symfony\Component\Console\Output\OutputInterface $consoleOutput
33
     */
34
    public function __construct(OutputInterface $consoleOutput)
35
    {
36
        $this->consoleOutput = $consoleOutput;
37
    }
38
39
    /**
40
     * Called when the crawl will crawl the url.
41
     *
42
     * @param \Psr\Http\Message\UriInterface $url
43
     */
44
    public function willCrawl(UriInterface $url)
45
    {
46
    }
47
48
    /**
49
     * Called when the crawl has ended.
50
     */
51
    public function finishedCrawling()
52
    {
53
        $this->consoleOutput->writeln('');
54
        $this->consoleOutput->writeln('Crawling summary');
55
        $this->consoleOutput->writeln('----------------');
56
57
        ksort($this->crawledUrls);
58
59
        foreach ($this->crawledUrls as $statusCode => $urls) {
60
            $colorTag = $this->getColorTagForStatusCode($statusCode);
61
62
            $count = count($urls);
63
64
            if (is_numeric($statusCode)) {
65
                $this->consoleOutput->writeln("<{$colorTag}>Crawled {$count} url(s) with statuscode {$statusCode}</{$colorTag}>");
66
            }
67
68
            if ($statusCode == static::UNRESPONSIVE_HOST) {
69
                $this->consoleOutput->writeln("<{$colorTag}>{$count} url(s) did have unresponsive host(s)</{$colorTag}>");
70
            }
71
        }
72
73
        $this->consoleOutput->writeln('');
74
    }
75
76
    protected function getColorTagForStatusCode(string $code): string
77
    {
78
        if ($this->startsWith($code, '2')) {
79
            return 'info';
80
        }
81
82
        if ($this->startsWith($code, '3')) {
83
            return 'comment';
84
        }
85
86
        return 'error';
87
    }
88
89
    /**
90
     * @param string|null $haystack
91
     * @param string|array $needles
92
     *
93
     * @return bool
94
     */
95
    public function startsWith($haystack, $needles): bool
96
    {
97
        foreach ((array) $needles as $needle) {
98
            if ($needle != '' && substr($haystack, 0, strlen($needle)) === (string) $needle) {
99
                return true;
100
            }
101
        }
102
103
        return false;
104
    }
105
106
    /**
107
     * Set the filename to write the output log.
108
     *
109
     * @param string $filename
110
     */
111
    public function setOutputFile($filename)
112
    {
113
        $this->outputFile = $filename;
114
    }
115
116
    public function crawled(
117
        UriInterface $url,
118
        ResponseInterface $response,
119
        ?UriInterface $foundOnUrl = null
120
    ) {
121
        if ($this->addRedirectedResult($url, $response, $foundOnUrl)) {
122
            return;
123
        }
124
125
        // response wasnt a redirect so lets add it as a standard result
126
        $this->addResult(
127
            (string) $url,
128
            (string) $foundOnUrl,
129
            $response->getStatusCode(),
130
            $response->getReasonPhrase()
131
        );
132
    }
133
134
    public function crawlFailed(
135
        UriInterface $url,
136
        RequestException $requestException,
137
        ?UriInterface $foundOnUrl = null
138
    ) {
139
        if ($response = $requestException->getResponse()) {
140
            $this->crawled($url, $response, $foundOnUrl);
141
        } else {
142
            $this->addResult((string) $url, (string) $foundOnUrl, '---', self::UNRESPONSIVE_HOST);
143
        }
144
    }
145
146
    public function addResult($url, $foundOnUrl, $statusCode, $reason)
147
    {
148
        /*
149
        * don't display duplicate results
150
        * this happens if a redirect is followed to an existing page
151
        */
152
        if (isset($this->crawledUrls[$statusCode]) && in_array($url, $this->crawledUrls[$statusCode])) {
153
            return;
154
        }
155
156
        $colorTag = $this->getColorTagForStatusCode($statusCode);
157
158
        $timestamp = date('Y-m-d H:i:s');
159
160
        $message = "{$statusCode} {$reason} - ".(string) $url;
161
162
        if ($foundOnUrl && $colorTag === 'error') {
163
            $message .= " (found on {$foundOnUrl})";
164
        }
165
166
        if ($this->outputFile && $colorTag === 'error') {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->outputFile of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
167
            file_put_contents($this->outputFile, $message.PHP_EOL, FILE_APPEND);
168
        }
169
170
        $this->consoleOutput->writeln("<{$colorTag}>[{$timestamp}] {$message}</{$colorTag}>");
171
172
        $this->crawledUrls[$statusCode][] = $url;
173
    }
174
175
    /*
176
    * https://github.com/guzzle/guzzle/blob/master/docs/faq.rst#how-can-i-track-redirected-requests
177
    */
178
    public function addRedirectedResult(
179
        UriInterface $url,
180
        ResponseInterface $response,
181
        ?UriInterface $foundOnUrl = null
182
    ) {
183
        // if its not a redirect the return false
184
        if (! $response->getHeader('X-Guzzle-Redirect-History')) {
185
            return false;
186
        }
187
188
        // retrieve Redirect URI history
189
        $redirectUriHistory = $response->getHeader('X-Guzzle-Redirect-History');
190
191
        // retrieve Redirect HTTP Status history
192
        $redirectCodeHistory = $response->getHeader('X-Guzzle-Redirect-Status-History');
193
194
        // Add the initial URI requested to the (beginning of) URI history
195
        array_unshift($redirectUriHistory, (string) $url);
196
197
        // Add the final HTTP status code to the end of HTTP response history
198
        array_push($redirectCodeHistory, $response->getStatusCode());
199
200
        // Combine the items of each array into a single result set
201
        $fullRedirectReport = [];
202
        foreach ($redirectUriHistory as $key => $value) {
203
            $fullRedirectReport[$key] = ['location' => $value, 'code' => $redirectCodeHistory[$key]];
204
        }
205
206
        // Add the redirects and final URL as results
207
        foreach ($fullRedirectReport as $k=>$redirect) {
208
            $this->addResult(
209
                (string) $redirect['location'],
210
                (string) $foundOnUrl,
211
                $redirect['code'],
212
                $k + 1 == count($fullRedirectReport) ? $response->getReasonPhrase() : self::REDIRECT
213
            );
214
        }
215
216
        return true;
217
    }
218
}
219