validate_host
Validate the given host for this site.
Check that the host looks valid and matches a host or host pattern in the
given list of allowed_hosts. Any pattern beginning with a period
matches a domain and all its subdomains (e.g. .example.com matches
example.com and any subdomain), * matches anything, and anything
else must match exactly.
Note: This function assumes that the given host is lowercased and has already had the port, if any, stripped off.
Return True for a valid host, False otherwise.
def validate_host(
host: string,
allowed_hosts: list
) - > boolean
Validate the given host for this site. Check that the host looks valid and matches a host or host pattern in the given list of allowed_hosts. Any pattern beginning with a period matches a domain and all its subdomains (e.g. .example.com matches example.com and any subdomain), * matches anything, and anything else must match exactly.
Parameters
| Name | Type | Description |
|---|---|---|
| host | string | The lowercased hostname with the port stripped off to be validated against the allowlist. |
| allowed_hosts | list | A list of valid hostnames or patterns (e.g., ".example.com", "*") to check the host against. |
Returns
| Type | Description |
|---|---|
boolean | Return True for a valid host, False otherwise. |