Skip to content

Commit a7875e8

Browse files
Merge pull request #9181 from Sesquipedalian/3.0/attachments_and_proxy
[3.0] Fixes a couple things with attachments and the image proxy
2 parents 4353cae + 8a4336e commit a7875e8

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

Sources/Actions/AttachmentApprove.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public function execute(): void
100100

101101
while ($row = Db::$db->fetch_assoc($request)) {
102102
// We can only add it if we can approve in this board!
103-
if ($allowed_boards = [0] || \in_array($row['id_board'], $allowed_boards)) {
103+
if ($allowed_boards === [0] || \in_array($row['id_board'], $allowed_boards)) {
104104
$attachments[] = $row['id_attach'];
105105

106106
// Also come up with the redirection URL.

Sources/ProxyServer.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,15 @@ public function checkRequest(): bool
139139
return false;
140140
}
141141

142+
// Just in case...
143+
if (
144+
filter_var($request->host, FILTER_VALIDATE_IP) !== false
145+
|| $request->host === 'localhost'
146+
|| $request->host === Url::create(Config::$boardurl)->host
147+
) {
148+
return false;
149+
}
150+
142151
// Ensure any non-ASCII characters in the URL are encoded correctly
143152
$request = \strval($request->toAscii());
144153

Sources/Url.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -488,8 +488,16 @@ public function proxied(): self
488488
return $proxied;
489489
}
490490

491-
// Don't bother with HTTPS URLs, schemeless URLs, or obviously invalid URLs.
492-
if (empty($proxied->scheme) || empty($proxied->host) || empty($proxied->path) || $proxied->scheme === 'https') {
491+
if (
492+
// Don't bother with HTTPS URLs, schemeless URLs, or obviously invalid URLs.
493+
empty($proxied->scheme)
494+
|| $proxied->scheme === 'https'
495+
|| empty($proxied->host)
496+
|| empty($proxied->path)
497+
// Don't proxy localhost or IP addresses.
498+
|| $proxied->host === 'localhost'
499+
|| filter_var($proxied->host, FILTER_VALIDATE_IP) !== false
500+
) {
493501
return $proxied;
494502
}
495503

0 commit comments

Comments
 (0)