Skip to content

Call request->getRemoteHost() can cause to stuck app #218

@jakubboucek

Description

@jakubboucek

Version: 3.0.5 - 3.1.6

Bug Description

Call $request->getRemoteHost() can stuck app, because remote host cane be unreacheable by reverse DNS or can have too long response.

Steps To Reproduce

use Nette\Http\Request;
$request = new Request(
            new Url('http://example.com'),
            [],
            [],
            [],
            [],
            [],
            '1.0.32.12', // some IP from location with slow reachability (china for example)
            null
        );
$request->getRemoteHost(); // this can to solve too long

Problem 2: Here is no way to force set null value to Request::$remoteHost and get it – it always call internally gethostbyaddr() function.

Expected Behavior

Request should by only dataobject without using any data from external source (DNS server).

The getter getRemoteHost() is also called when I need to modify Request object, for example:

function setRequestHeaders(Request $request, array $headers): self
    {
        $dolly = new Request(
            ($request->getUrl()),
            $request->getPost(),
            $request->getFiles(),
            $request->getCookies(),
            $headers,
            $request->getMethod(),
            $request->getRemoteAddress(),
            $threquestis->getRemoteHost(), // <--- stucked here
            function () {
                return $request->getRawBody();
            },
        );
        return $dolly;
    }

Possible Solution

Usually is Request object filled by RequestFactory and getters just only response. Looks good to trust Request::$remoteHost filled from RequestFactory and don't try to fetch it (here/again) from external source.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions