question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItĀ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[šŸ› Bug]: "Invalid Host Header" in Firefox 106 w/ geckodriver 0.32.0

See original GitHub issue

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:

https://github.com/SeleniumHQ/selenium/blob/7fdaf217b8e58033b7cd01d916e3063c8198a403/java/src/org/openqa/selenium/firefox/GeckoDriverService.java#L187-L211

Source of target url for reqeusts to geckodriver:

https://github.com/SeleniumHQ/selenium/blob/7fdaf217b8e58033b7cd01d916e3063c8198a403/java/src/org/openqa/selenium/remote/service/DriverService.java#L172-L174


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

Issue Analytics

  • State:open
  • Created 10 months ago
  • Comments:11 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
titusfortnercommented, Dec 8, 2022

Well, you should be able to create your own GeckoDriverService with the arguments specified, but I haven’t tested it to see if they get overridden somewhere (FirefoxService code is a bit weird for legacy reasons). The code itself encourages using the Builder, though, and that doesn’t support adding arguments. I want us to do a review of it all soon.

0reactions
zireael-0commented, Dec 8, 2022

@diemol To be honest, I don’t think this is a misconfig. Yes, I was able to work around the issue by updating my system configuration. However, if you ask me, having an empty /etc/hosts file is not a misconfiguration - it’s even the default on my distro.

I don’t know if it’s necessary to change this within selenium per-se. But in my opinion there should at least be a way to pass additional parameters to geckodriver for cases like this. Right now, I can set parameters to launch firefox via FirefoxOptions, but not geckodrvier itself.

If I had no su access to the machine I am working on, I wouldn’t have been able to resolve this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

1750691 - Release geckodriver 0.32.0 - Bugzilla@Mozilla
Bug 1750691 - [geckodriver] Update changeset for the 0.32.0 release. 2 months ago ... Bug 1750691 - [geckodriver] Release version 0.32.0. 2 months...
Read more >
python - Invalid Host header localhost - Stack Overflow
I am getting the following error. /home/USER/workspace/PycharmProjects/linkedinkeywords/venv/bin/python /usr/share/pycharm/plugins/pythonĀ ...
Read more >
Bug List - FreeBSD Bugzilla
ID Productā–³ Componentā–³ Assigneeā–½ Statusā–½ Resolutionā–³ Changed 163568 Base System amd64 amd64 Closed Not Enough Info 2016‑01‑02 259438 Base System arm freebsd‑arm Open ‑‑‑ 2021‑10‑25 236373...
Read more >
ChangeLog.txt - SlackBuilds.org
New maintainer. libraries/libbsd: Updated for version 0.11.6. libraries/libcurl-gnutls: Patched to fix fatal error. libraries/libfm-qt: Added (PCManFM-QtĀ ...
Read more >
Compare Packages Between Distributions - DistroWatch.com
Often times it is useful to be able to compare the versions of different packages between two distributions. This can let us know...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found