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.

Untrusted host while running with url different than localhost

See original GitHub issue

Environment

  • Docker for Mac 18.06.1-ce-mac73
  • macOS High Sierra

Steps to reproduce

  1. Install API Platform as described here: https://api-platform.com/docs/distribution#installing-the-framework (download package & run docker-compose up -d)
  2. Open https://localhost in browser. It works.
  3. (problem starts here) Add 127.0.0.1 myproject.dev to /etc/hosts
  4. Edit src/Welcome.js and replace localhost with myproject.dev (not required nowadays, 2019-07-03, kniziol)
  5. Open http://myproject.dev in browser. It works.
  6. Click any link in first/left box of AVAILABLE SERVICES section (API or CACHED API)
  7. You will see the Untrusted host exception:
Untrusted host exception
  1. Open api/.env
  2. Add myproject.dev to TRUSTED_HOSTS (before: localhost,api, after: localhost,api,myproject.dev)
  3. Go to step 6. Doesn’t work.
  4. Clear cache & restart all containers by running docker-compose exec php bin/console c:c && docker-compose restart. Doesn’t work.
  5. In api/public/index.php:31 value of $_SERVER['TRUSTED_HOSTS'] is still localhost,api, but it should be localhost,api,myproject.dev.

Solution

  1. Open api/config/packages/framework.yaml
  2. Add framework.trusted_hosts parameter:
framework:
    secret: '%env(APP_SECRET)%'
    trusted_hosts:
        - localhost
        - api
        - myproject.dev
  1. Click any link in first/left box of AVAILABLE SERVICES section (API or CACHED API)
  2. It works.

Problem

Host added to TRUSTED_HOSTS is not included.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:4
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

7reactions
kniziolcommented, Jul 18, 2019

Solution

Domains should be separated by | (not by ,).

Incorrect

TRUSTED_HOSTS='^localhost,api,myproject.dev$'

Correct

TRUSTED_HOSTS='^localhost|api|myproject.dev$'
Zrzut ekranu 2019-07-18 o 14 40 08

@teohhanhui @dunglas Problem solved. Thanks.

1reaction
kniziolcommented, Jul 3, 2019

@ghanbari Sorry, doesn’t work

Read more comments on GitHub >

github_iconTop Results From Across the Web

Untrusted Host "localhost" in [duplicate] - Drupal Answers
I have an Apache web server running locally, with the test site defined using a VirtualHost directive. I add the domain name of...
Read more >
docker container running on untrusted host machine
I know that docker containers which are running on a host machine have root privileges. This is mostly incorrect. A docker container has ......
Read more >
Untrusted Host "127.0.0.1
When I run symfony server:start it returns Error like "Untrusted Host ... Use localhost when accessing website or add 127.0.0.1 to trusted hosts:...
Read more >
Troubleshooting Apache SSL Certificate Errors
How to correct common SSL Certificate errors with Apache Servers. Read more about troubleshooting Apache SSL Certificate errors.
Read more >
Security in the Jupyter notebook server - Read the Docs
Since access to the Jupyter notebook server means access to running arbitrary code, ... When token authentication is enabled, the notebook uses a...
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