Adjust default value for INVENTRE_ALLOWED_HOSTS (#13416)

* Adjust default value for INVENTRE_ALLOWED_HOSTS

Starting in 1.8.0 the default value for INVENTREE_ALLOWED_HOSTS is unset. Currently it is '*' - which is overly permissive and can lead to host spoofing and other security weaknesses.

The new default value (only applied to fresh setups) will require more work from the sys-admin but is safer overall

* Add CHANGELOG entry

* adjust settings for unit tests

* Allow testserver for schema building

* Add INVE-W23
This commit is contained in:
Oliver authored and GitHub committed 2026-12-01 11:44:25 +11:00
1 parent 855164e91f
commit 819231c342
9 files changed
+82 -8

No files matched your search

+9
View File
@@ -297,6 +297,15 @@ The message lists each affected plugin, together with the plugin settings which
If the check itself fails, the message "Unable to check plugin integrations" is shown instead. Check the server log for details.
#### INVE-W23
**Allowed hosts is set to allow all hosts - Backend**
The `INVENTREE_ALLOWED_HOSTS` / `allowed_hosts` setting contains `*`, which allows requests with any `Host` header. Older versions of the configuration file template set this value by default.
It is recommended to remove `*` and set the [site URL](../start/config.md#site-url) instead; the host of the site URL is allowed automatically. Any additional host names can be added to the allowed hosts list - see the [allowed hosts settings](../start/config.md#allowed-hosts).
This warning is also shown in [debug mode](../start/config.md#debug-mode), where all hosts are allowed if no allowed hosts are specified.
### INVE-I (InvenTree Information)
Information — These are not errors but information messages. They might point out potential issues or just provide information.
+21 -3
View File
@@ -75,6 +75,15 @@ The *INVENTREE_SITE_URL* option defines the base URL for the InvenTree server. T
The site URL is the URL that users will use to access the InvenTree server. For example, if the server is accessible at `https://inventree.example.com`, the site URL should be set to `https://inventree.example.com`. Note that this is not necessarily the same as the internal URL that the server is running on - the internal URL will depend entirely on your server configuration and may be obscured by a reverse proxy or other such setup.
The site URL is used for:
- **Allowed hosts** - the host part of the site URL is always added to the list of [allowed hosts](#allowed-hosts).
- **Trusted origins** - it is used as the default for the trusted CSRF and CORS origins (see [Server Access](#server-access)).
- **Links in emails** - links sent out by the server are built from the site URL, not from the address used to make the request.
!!! warning "Required in Production"
If neither `INVENTREE_SITE_URL` nor `INVENTREE_ALLOWED_HOSTS` is specified, the server will refuse to start (unless running in [debug mode](#debug-mode)).
### Timezone
By default, the InvenTree server is configured to use the UTC timezone. This can be adjusted to your desired local timezone. You can refer to [Wikipedia](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones) for a list of available timezones. Use the values specified in the *TZ Identifier* column in the linked page. For example, to change to the United States Pacific timezone, set `INVENTREE_TIMEZONE='America/Los_Angeles'`.
@@ -119,7 +128,7 @@ Depending on how your InvenTree installation is configured, you will need to pay
The following settings require a certain assumed level of knowledge. You should also refer to the [django documentation]({% include "django.html" %}/ref/settings/) for more information.
!!! danger "Not Secure"
Allowing access from any host is not secure, and should be adjusted for your installation.
Allowing access from any host (e.g. setting `INVENTREE_ALLOWED_HOSTS` to `*`) is not secure, and should not be used in production. Refer to [allowed hosts](#allowed-hosts) below.
!!! success "INVENTREE_SITE_URL"
If you have specified the `INVENTREE_SITE_URL`, this will automatically be used as a trusted CSRF and CORS host (see below).
@@ -128,7 +137,7 @@ Depending on how your InvenTree installation is configured, you will need to pay
If InvenTree is served behind an existing reverse proxy (e.g. NGINX, Traefik) with SSL termination happening upstream, refer to the [worked example](./processes.md#integrating-with-existing-proxy) for the combination of `INVENTREE_TRUSTED_ORIGINS` and `INVENTREE_USE_X_FORWARDED_*` settings that setup requires.
{{ configtable() }}
{{ configsetting("INVENTREE_ALLOWED_HOSTS") }} List of allowed hosts |
{{ configsetting("INVENTREE_ALLOWED_HOSTS", default="Uses the *INVENTREE_SITE_URL* parameter, if set. Otherwise, an empty list.") }} List of allowed hosts. Do not set this to `*` in production, as it allows Host header spoofing. |
{{ configsetting("INVENTREE_TRUSTED_ORIGINS", default="Uses the *INVENTREE_SITE_URL* parameter, if set. Otherwise, an empty list.") }} List of trusted origins. Refer to the [django documentation]({% include "django.html" %}/ref/settings/#csrf-trusted-origins) |
{{ configsetting("INVENTREE_CORS_ORIGIN_ALLOW_ALL") }} Allow all remote URLS for CORS checks |
{{ configsetting("INVENTREE_CORS_ORIGIN_WHITELIST", default="Uses the *INVENTREE_SITE_URL* parameter, if set. Otherwise, an empty list.") }} List of whitelisted CORS URLs. Refer to the [django-cors-headers documentation](https://github.com/adamchainz/django-cors-headers#cors_allowed_origins-sequencestr) |
@@ -144,6 +153,15 @@ Depending on how your InvenTree installation is configured, you will need to pay
{{ configsetting("INVENTREE_THROTTLE_ANON") }} Throttle rate for anonymous users (e.g. '20/minute') |
{{ configsetting("INVENTREE_THROTTLE_USER") }} Throttle rate for authenticated users (e.g. '5/second') |
### Allowed Hosts
The `INVENTREE_ALLOWED_HOSTS` setting is a list of the host (domain) names that the InvenTree server will respond to. Requests made with any other `Host` header are rejected. Refer to the [django documentation]({% include "django.html" %}/ref/settings/#allowed-hosts) for more information.
In most cases, this setting does not need to be specified: the host of the [site URL](#site-url) is automatically allowed. You only need to set it if users access the server using additional names.
!!! danger "Do not allow all hosts"
Setting `INVENTREE_ALLOWED_HOSTS` to `*` allows a client to send requests with any `Host` header. This can be exploited to spoof links and redirects. Older versions of the [configuration file template](#configuration-file-template) set this value to `*` by default - if your configuration file contains this value, you should remove it and set the [site URL](#site-url) instead.
### Debug Mode
Note that in [debug mode](./index.md#debug-mode), some of the above settings are automatically adjusted to allow for easier development. The following settings are internally overridden in debug mode with the values specified below:
@@ -161,7 +179,7 @@ Note that if you set the `INVENTREE_COOKIE_SAMESITE` to `None`, then `INVENTREE_
### Proxy Considerations
If you are running InvenTree behind a proxy, or forwarded HTTPS connections, you will need to ensure that the InvenTree server is configured to listen on the correct host and port. You will likely have to adjust the `INVENTREE_ALLOWED_HOSTS` setting to ensure that the server will accept requests from the proxy.
If you are running InvenTree behind a proxy, or forwarded HTTPS connections, you will need to ensure that the InvenTree server is configured to listen on the correct host and port. Ensure that the [allowed hosts](#allowed-hosts) include the host which the proxy forwards to the InvenTree server.
Additionally, you may need to configure the following header to ensure that the InvenTree server is watching for information forwarded by the proxy: