fix(security): Handle idn_to_utf8 returning false

Signed-off-by: Joas Schilling <coding@schilljs.com>
pull/41999/head
Joas Schilling 2 years ago
parent df7bc46eab
commit 33e1c8b236
No known key found for this signature in database
GPG Key ID: 74434EFE0D2E2205
  1. 4
      lib/private/Security/RemoteHostValidator.php
  2. 1
      tests/lib/Http/Client/ClientTest.php
  3. 15
      tests/lib/Security/RemoteHostValidatorTest.php

@ -52,6 +52,10 @@ final class RemoteHostValidator implements IRemoteHostValidator {
}
$host = idn_to_utf8(strtolower(urldecode($host)));
if ($host === false) {
return false;
}
// Remove brackets from IPv6 addresses
if (str_starts_with($host, '[') && str_ends_with($host, ']')) {
$host = substr($host, 1, -1);

@ -149,6 +149,7 @@ class ClientTest extends \Test\TestCase {
['https://service.localhost'],
['!@#$', true], // test invalid url
['https://normal.host.com'],
['https://com.one-.nextcloud-one.com'],
];
}

@ -60,8 +60,17 @@ class RemoteHostValidatorTest extends TestCase {
);
}
public function testValid(): void {
$host = 'nextcloud.com';
public function dataValid(): array {
return [
['nextcloud.com', true],
['com.one-.nextcloud-one.com', false],
];
}
/**
* @dataProvider dataValid
*/
public function testValid(string $host, bool $expected): void {
$this->hostnameClassifier
->method('isLocalHostname')
->with($host)
@ -73,7 +82,7 @@ class RemoteHostValidatorTest extends TestCase {
$valid = $this->validator->isValid($host);
self::assertTrue($valid);
self::assertSame($expected, $valid);
}
public function testLocalHostname(): void {

Loading…
Cancel
Save