support ALLOWED_HOSTS (#1905)
Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com>
This commit is contained in:
@@ -40,6 +40,7 @@ class Settings(BaseSettings):
|
|||||||
PORT: int = 8000
|
PORT: int = 8000
|
||||||
ALLOWED_ORIGINS: list[str] = ["*"]
|
ALLOWED_ORIGINS: list[str] = ["*"]
|
||||||
BLOCKED_HOSTS: list[str] = ["localhost"]
|
BLOCKED_HOSTS: list[str] = ["localhost"]
|
||||||
|
ALLOWED_HOSTS: list[str] = []
|
||||||
|
|
||||||
# Secret key for JWT. Please generate your own secret key in production
|
# Secret key for JWT. Please generate your own secret key in production
|
||||||
SECRET_KEY: str = "PLACEHOLDER"
|
SECRET_KEY: str = "PLACEHOLDER"
|
||||||
|
|||||||
@@ -29,6 +29,8 @@ def prepend_scheme_and_validate_url(url: str) -> str:
|
|||||||
|
|
||||||
|
|
||||||
def is_blocked_host(host: str) -> bool:
|
def is_blocked_host(host: str) -> bool:
|
||||||
|
if host.lower() in (h.lower() for h in settings.ALLOWED_HOSTS):
|
||||||
|
return False
|
||||||
try:
|
try:
|
||||||
ip = ipaddress.ip_address(host)
|
ip = ipaddress.ip_address(host)
|
||||||
# Check if the IP is private, link-local, loopback, or reserved
|
# Check if the IP is private, link-local, loopback, or reserved
|
||||||
|
|||||||
Reference in New Issue
Block a user