Introduce a new method `setAllowedHostnames` which perform the validation against untrusted hostnames. Fixes gh-4310