Call request->getRemoteHost() can cause to stuck app
jakubboucek opened this issue · 2 comments
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.
Probably the best solution would be to deprecate getRemoteHost().
@dg Díky! ❤️