|
|
@@ -218,6 +218,39 @@ final class httpUtilTest extends \PHPUnit\Framework\TestCase {
|
|
|
];
|
|
|
}
|
|
|
|
|
|
+ /** cURL would rewrite these hosts, and contact another name or address than the one checked and pinned */
|
|
|
+ #[DataProvider('provideHostsRewrittenByCurl')]
|
|
|
+ public function test_getCurlResolveInfoRejectsHostsRewrittenByCurl(string $host): void {
|
|
|
+ FreshRSS_Context::initSystem();
|
|
|
+ $resolveOk = new ReflectionProperty(FreshRSS_http_Util::class, 'resolve_ok');
|
|
|
+ $resolveOk->setValue(null, [strtolower($host) => ['192.0.66.96']]);
|
|
|
+ self::assertFalse(FreshRSS_http_Util::getCurlResolveInfo("http://$host/feed"));
|
|
|
+ self::assertFalse(FreshRSS_http_Util::getCurlResolveInfo("socks5h://$host:1080"));
|
|
|
+ }
|
|
|
+
|
|
|
+ /** @return array<string,array{string}> */
|
|
|
+ public static function provideHostsRewrittenByCurl(): array {
|
|
|
+ return [
|
|
|
+ 'percent-encoded underscore' => ['a%5F.example.test'], // cURL resolves a_.example.test
|
|
|
+ 'percent-encoded UTF-8' => ['%C3%A9.example.test'], // cURL resolves xn--9ca.example.test
|
|
|
+ 'non-ASCII' => ['é.example.test'], // cURL resolves xn--9ca.example.test
|
|
|
+ 'IPv4 as one number' => ['2130706433'], // cURL connects to 127.0.0.1
|
|
|
+ 'IPv4 as hexadecimal' => ['0x7f.1'], // cURL connects to 127.0.0.1
|
|
|
+ 'IPv4 as octal' => ['0177.0.0.1'], // cURL connects to 127.0.0.1
|
|
|
+ 'IPv4 with fewer parts' => ['127.1'], // cURL connects to 127.0.0.1
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ /** Ordinary host names are still resolved and pinned as written */
|
|
|
+ public function test_getCurlResolveInfoAcceptsHostsUsedAsWrittenByCurl(): void {
|
|
|
+ FreshRSS_Context::initSystem();
|
|
|
+ $resolveOk = new ReflectionProperty(FreshRSS_http_Util::class, 'resolve_ok');
|
|
|
+ foreach (['a_b-c.example.test', 'xn--9ca.example.test', '1.example.test', 'example.7z', 'example.test.'] as $host) {
|
|
|
+ $resolveOk->setValue(null, [$host => ['192.0.66.96']]);
|
|
|
+ self::assertSame(["$host:80:192.0.66.96"], FreshRSS_http_Util::getCurlResolveInfo("http://$host/feed"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/** Socks schemes default to port 1080, and an IP address proxy produces no resolve entry */
|
|
|
public function test_getCurlResolveInfoForProxyAddress(): void {
|
|
|
FreshRSS_Context::initSystem();
|