Skip to content

[🐛 Bug]: "Invalid Host Header" in Firefox 106 w/ geckodriver 0.32.0 #11264

@zireael-0

Description

@zireael-0

What happened?

I'm using Firefox 106 with selenium-firefox-driver:4.5.0 for Java and geckodriver 0.32.0 (via Selenide 6.9.0)

Selenium GeckoDriverService launches geckodriver and when starting a new browser session it calls PUT http://localhost:<port>/session

However, since the --allow-hosts localhost flag is not provided when starting geckodriver, requests to geckodriver always return 500 Invalid Host Header

Source of geckodriver arguments:

@Override
protected List<String> createArgs() {
List<String> args = new ArrayList<>();
int wsPort = PortProber.findFreePort();
args.add(String.format("--port=%d", getPort()));
args.add(String.format("--websocket-port=%d", wsPort));
args.add("--allow-origins");
args.add(String.format("http://127.0.0.1:%d", wsPort));
args.add(String.format("http://localhost:%d", wsPort));
args.add(String.format("http://[::1]:%d", wsPort));
if (firefoxBinary != null) {
args.add("-b");
args.add(firefoxBinary.getPath());
} else {
// Read system property for Firefox binary and use those if they are set
Optional<Executable> executable =
Optional.ofNullable(FirefoxBinary.locateFirefoxBinaryFromSystemProperty());
executable.ifPresent(e -> {
args.add("-b");
args.add(e.getPath());
});
}
// If the binary stays null, GeckoDriver will be responsible for finding Firefox on the PATH or via a capability.
return unmodifiableList(args);
}

Source of target url for reqeusts to geckodriver:

protected URL getUrl(int port) throws IOException {
return new URL(String.format("http://localhost:%d", port));
}


My suggestion would be to update GeckoDriverService to either include --allow-hosts localhost or override ::getPort(int) to http://127.0.0.1:%d.

How can we reproduce the issue?

Breaks 100% of the time with the specified versions:

import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;

public class Main {
    public static void main(String[] args) throws Exception {
        var options = new FirefoxOptions();
        System.setProperty("webdriver.gecko.driver", "/usr/bin/geckodriver"); // geckodriver 0.32.0
        options.setBinary("/usr/bin/firefox"); // firefox 106 installed

        var driver = new FirefoxDriver(options);
        driver.get("https://www.stackoverflow.com");
    }
}

Relevant log output

1668526366108	geckodriver	INFO	Listening on 127.0.0.1:55726
1668526366212	webdriver::server	WARN	Rejected request with Host header localhost:55726, allowed values are []
Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Response code 500. Message: Invalid Host header localhost:55726

Operating System

linux

Selenium version

java 4.5.0

What are the browser(s) and version(s) where you see this issue?

Firefox 106

What are the browser driver(s) and version(s) where you see this issue?

geckodriver 0.32.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-javaJava BindingsI-defectSomething is not working as intended

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions