mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-11-25 22:51:19 +00:00
Fix/tweak: include other loopbacks in default ALLOWED_HOSTS (#14846)
This commit is contained in:
1 parent
d1e574ff8f
commit
40598db447
3 files changed
+23
-16
No files matched your search
@@ -510,9 +510,9 @@ You can read more about this in [the Django project's documentation](https://doc
|
||||
|
||||
- With neither setting configured, Paperless accepts any host.
|
||||
- With only `PAPERLESS_URL` set, Paperless accepts the hostname from that URL
|
||||
and `localhost` (used by the Docker health check).
|
||||
- `PAPERLESS_ALLOWED_HOSTS` adds hosts to `localhost` and the hostname from
|
||||
`PAPERLESS_URL`, if set. A blank list adds no hosts.
|
||||
and the loopback hosts `localhost`, `127.0.0.1`, and `[::1]`.
|
||||
- `PAPERLESS_ALLOWED_HOSTS` adds hosts to those loopback hosts and the hostname
|
||||
from `PAPERLESS_URL`, if set. A blank list adds no hosts.
|
||||
- With `PAPERLESS_ALLOWED_HOSTS=*`, Paperless accepts any host, even when
|
||||
`PAPERLESS_URL` is set.
|
||||
|
||||
|
||||
@@ -458,8 +458,8 @@ def _get_allowed_hosts() -> list[str]:
|
||||
else:
|
||||
allowed_hosts = ["*"]
|
||||
if allowed_hosts != ["*"]:
|
||||
# Always allow localhost for the Docker health check.
|
||||
allowed_hosts.append("localhost")
|
||||
# Allow local access and health checks via loopback hostnames and addresses.
|
||||
allowed_hosts.extend(["localhost", "127.0.0.1", "[::1]"])
|
||||
return allowed_hosts
|
||||
|
||||
|
||||
|
||||
@@ -177,11 +177,17 @@ class TestPaperlessURLSettings(TestCase):
|
||||
("url", "allowed_hosts", "expected", "accepted_host", "rejected_host"),
|
||||
[
|
||||
(None, None, ["*"], "other.example.com", None),
|
||||
(None, "", ["localhost"], "localhost:8000", "other.example.com"),
|
||||
(
|
||||
None,
|
||||
"",
|
||||
["localhost", "127.0.0.1", "[::1]"],
|
||||
"localhost:8000",
|
||||
"other.example.com",
|
||||
),
|
||||
(
|
||||
None,
|
||||
"lan.example.com",
|
||||
["lan.example.com", "localhost"],
|
||||
["lan.example.com", "localhost", "127.0.0.1", "[::1]"],
|
||||
"lan.example.com",
|
||||
"other.example.com",
|
||||
),
|
||||
@@ -189,29 +195,29 @@ class TestPaperlessURLSettings(TestCase):
|
||||
(
|
||||
"https://example.com:8443",
|
||||
None,
|
||||
["localhost", "example.com"],
|
||||
["localhost", "127.0.0.1", "[::1]", "example.com"],
|
||||
"example.com:8443",
|
||||
"other.example.com",
|
||||
),
|
||||
(
|
||||
"https://example.com.",
|
||||
"",
|
||||
["localhost", "example.com"],
|
||||
["localhost", "127.0.0.1", "[::1]", "example.com"],
|
||||
"example.com.",
|
||||
"other.example.com",
|
||||
),
|
||||
(
|
||||
"http://[::1]:8000",
|
||||
"http://[2001:db8::1]:8000",
|
||||
None,
|
||||
["localhost", "[::1]"],
|
||||
"[::1]:8000",
|
||||
["localhost", "127.0.0.1", "[::1]", "[2001:db8::1]"],
|
||||
"[2001:db8::1]:8000",
|
||||
"other.example.com",
|
||||
),
|
||||
("https://example.com", "*", ["*", "example.com"], "other.example.com", None),
|
||||
(
|
||||
"https://example.com",
|
||||
"lan.example.com",
|
||||
["lan.example.com", "localhost", "example.com"],
|
||||
["lan.example.com", "localhost", "127.0.0.1", "[::1]", "example.com"],
|
||||
"lan.example.com",
|
||||
"other.example.com",
|
||||
),
|
||||
@@ -241,9 +247,10 @@ def test_allowed_hosts_at_startup(
|
||||
assert expected == paperless_settings.ALLOWED_HOSTS
|
||||
|
||||
request = HttpRequest()
|
||||
with override_settings(ALLOWED_HOSTS=expected):
|
||||
request.META["HTTP_HOST"] = accepted_host
|
||||
assert request.get_host() == accepted_host
|
||||
with override_settings(ALLOWED_HOSTS=paperless_settings.ALLOWED_HOSTS):
|
||||
for host in (accepted_host, "localhost:8000", "127.0.0.1:30070", "[::1]:8000"):
|
||||
request.META["HTTP_HOST"] = host
|
||||
assert request.get_host() == host
|
||||
if rejected_host:
|
||||
request.META["HTTP_HOST"] = rejected_host
|
||||
with pytest.raises(DisallowedHost):
|
||||
|
||||
Reference in new issue
Block a user