Skip to content

Commit a5eaa56

Browse files
Merge pull request #42005 from nextcloud/backport/41999/stable28
[stable28] fix(security): Handle idn_to_utf8 returning false
2 parents b6dd719 + 704751f commit a5eaa56

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

lib/private/Security/RemoteHostValidator.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ public function isValid(string $host): bool {
5252
}
5353

5454
$host = idn_to_utf8(strtolower(urldecode($host)));
55+
if ($host === false) {
56+
return false;
57+
}
58+
5559
// Remove brackets from IPv6 addresses
5660
if (str_starts_with($host, '[') && str_ends_with($host, ']')) {
5761
$host = substr($host, 1, -1);

tests/lib/Http/Client/ClientTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ public function dataPreventLocalAddress():array {
149149
['https://service.localhost'],
150150
['!@#$', true], // test invalid url
151151
['https://normal.host.com'],
152+
['https://com.one-.nextcloud-one.com'],
152153
];
153154
}
154155

tests/lib/Security/RemoteHostValidatorTest.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,17 @@ protected function setUp(): void {
6060
);
6161
}
6262

63-
public function testValid(): void {
64-
$host = 'nextcloud.com';
63+
public function dataValid(): array {
64+
return [
65+
['nextcloud.com', true],
66+
['com.one-.nextcloud-one.com', false],
67+
];
68+
}
69+
70+
/**
71+
* @dataProvider dataValid
72+
*/
73+
public function testValid(string $host, bool $expected): void {
6574
$this->hostnameClassifier
6675
->method('isLocalHostname')
6776
->with($host)
@@ -73,7 +82,7 @@ public function testValid(): void {
7382

7483
$valid = $this->validator->isValid($host);
7584

76-
self::assertTrue($valid);
85+
self::assertSame($expected, $valid);
7786
}
7887

7988
public function testLocalHostname(): void {

0 commit comments

Comments
 (0)