Skip to content

Error 400 after setting TRUSTED_HOSTS in docker-compose.yaml #1453

Description

@mkne

After updating to Version 2.13.3 the following message appears with the admin account logged in:

TRUSTED_HOSTS nicht konfiguriert
Die Umgebungsvariable TRUSTED_HOSTS ist nicht gesetzt. Das bedeutet, dass Part-DB Anfragen für jeden beliebigen Hostnamen akzeptiert, was ein Sicherheitsrisiko darstellen kann (z. B. HTTP-Host-Header-Injection). Es wird empfohlen, dies auf die Hostnamen zu beschränken, unter denen Part-DB tatsächlich erreichbar ist.

Legen Sie einen regulären Ausdruck fest, der alle Hostnamen abdeckt, unter denen Part-DB erreichbar sein soll, z. B. basierend auf dem Hostnamen, den Sie für den Zugriff auf diese Seite verwendet haben. Dies ist möglich in Ihrer Datei .env.local oder docker-compose.yaml:
TRUSTED_HOSTS='^(mypartdb)$'

  1. So I added the following line in my docker-compose.yaml
    - TRUSTED_HOSTS='^(mypartdb)$'
  2. and did
    sudo docker compose up -d
  3. (optionally) tried a
    sudo docker exec --user=www-data partdb php bin/console cache:clear
  4. and after reloading the page I get greeted by the following Error 400 message:
    400
    Bad Request
    Part-DB was accessed using a host name that is not marked as trusted.
    The host name Part-DB saw was: neli
    You can try to Go Back or Visit the homepage.

If this error persists, please contact your administrator.

Infos for Admin: Untrusted host name.
For security reasons (to prevent HTTP Host header attacks), Part-DB only responds to requests using host names that were explicitly marked as trusted, once more than one host name is used to access it (e.g. behind a reverse proxy).

Try following things:

Ensure that you are using the correct URL to access Part-DB.
Set the TRUSTED_HOSTS environment variable in your .env.local file (or your docker-compose environment) to a regular expression matching all host names Part-DB should be reachable under, e.g. TRUSTED_HOSTS='^(neli)$' (if neli is a host name you trust)
If Part-DB is running behind a reverse proxy, also make sure that TRUSTED_PROXIES is configured correctly, so the original host name is forwarded properly.
Run php bin/console cache:clear after changing the configuration.
If you think that this is an error in Part-DB, open an Issue on GitHub.

You can disable these hints in config/parameters.yaml by setting partdb.error_pages.show_help to false.

I also updated the docker-ce, docker-compose-plugin, ... via apt and tried to use the IP-Address in the TRUSTED_HOSTS.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions