Skip to content

Commit c8bb0c0

Browse files
authored
Validate ping url (alexjustesen#1662)
1 parent 9a0d7da commit c8bb0c0

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

app/Jobs/Speedtests/ExecuteOoklaSpeedtest.php

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Illuminate\Queue\InteractsWithQueue;
1414
use Illuminate\Queue\SerializesModels;
1515
use Illuminate\Support\Arr;
16+
use Illuminate\Support\Facades\URL;
1617
use JJG\Ping;
1718
use Symfony\Component\Process\Exception\ProcessFailedException;
1819
use Symfony\Component\Process\Process;
@@ -88,13 +89,34 @@ public function handle(): void
8889

8990
protected function checkForInternetConnection(): bool
9091
{
92+
$url = config('speedtest.ping_url');
93+
9194
// Skip checking for internet connection if ping url isn't set (disabled)
92-
if (blank(config('speedtest.ping_url'))) {
95+
if (blank($url)) {
9396
return true;
9497
}
9598

99+
if (! URL::isValidUrl($url)) {
100+
$this->result->update([
101+
'server_id' => $this->serverId,
102+
'data' => [
103+
'type' => 'log',
104+
'level' => 'error',
105+
'message' => 'Invalid ping URL.',
106+
],
107+
'status' => ResultStatus::Failed,
108+
]);
109+
110+
SpeedtestFailed::dispatch($this->result);
111+
112+
return false;
113+
}
114+
115+
// Remove http:// or https:// from the URL if present
116+
$url = preg_replace('/^https?:\/\//', '', $url);
117+
96118
$ping = new Ping(
97-
host: config('speedtest.ping_url'),
119+
host: $url,
98120
timeout: 3,
99121
);
100122

0 commit comments

Comments
 (0)