Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

selenium/standalone-chrome:4.0.0: “Host header or origin header is specified and is not localhost” #8326

Closed
devopsix opened this issue May 19, 2020 · 1 comment
Labels

Comments

@devopsix
Copy link

🐛 Bug Report

Remote WebDriver fails to execute any command through a Selenium 4.0.0 Standalone Server in Chrome if any other (non IP address) hostname than “localhost” is used for connecting to the Selenium Server.

Having URLs with other names than “localhost” for the host part is a very common scenario in a containerized environment. Using IP addresses ususally is not an option in environments as dynamic as e.g. a Kuberneter cluster.

The root cause may be related to this Chromium issue.

Detailed steps to reproduce the behavior:

This issue can be reproduced by running basic remote WebDriver commands against a selenium/standalone-chrome:4.0.0 Docker container.

Given you have Docker installed and you have unpacked the attached
selenium.zip file.

  1. Open a shell.
  2. Run docker-compose up -d.
  3. Run docker-compose run client python /selenium4.py.
Traceback (most recent call last):
File "/selenium4.py", line 7, in <module>
  driver.get("http://www.google.com")
File "/usr/local/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 333, in get
  self.execute(Command.GET, {'url': url})
File "/usr/local/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
  self.error_handler.check_response(response)
File "/usr/local/lib/python3.8/site-packages/selenium/webdriver/remote/errorhandler.py", line 208, in check_response
  raise exception_class(value)
selenium.common.exceptions.WebDriverException: Message: Host header or origin header is specified and is not localhost.

For demonstrating that this is not an issue with selenium/standalone-chrome:3.141.59, run: docker-compose run client python /selenium3.py

[<selenium.webdriver.remote.webelement.WebElement (session="1d881a973e913012aab4f7ae2d64bdf7", element="81cb5c16-5461-4378-b7fb-581f591afc04")>]

The commands in selenium3.py and selenium4.py are as simple as:

driver.get("http://www.google.com")
print(driver.find_elements_by_tag_name("body"))

Expected behavior

It should be possible to use URLs like http://selenium4:4444 for connecting to the Selenium Server (i.e. selenium4.py should complete successfully in above scenario).

selenium4.py does complete successfully when being run from the host machine (given Python is installed) with http://localhost:4444, resp. as the Selenium Server URL.

Environment

Browser: Chrome
Browser Version: The one included with selenium/standalone-chrome:4.0.0
Selenium Grid version: 4.0.0

@diemol
Copy link
Member

diemol commented May 26, 2020

This will be released in the next Alpha.

titusfortner pushed a commit to titusfortner/selenium that referenced this issue Aug 13, 2020
Fixes SeleniumHQ#8326 and fixes SeleniumHQ#7821
ChromeDriver will reject requests if the host header contains something different
than localhost and no whitelistedIps are configured.
This does not affect other drivers.
@github-actions github-actions bot locked and limited conversation to collaborators Sep 5, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants