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 s
(host, allowed_hosts)
| 855 | |
| 856 | |
| 857 | def validate_host(host, allowed_hosts): |
| 858 | """ |
| 859 | Validate the given host for this site. |
| 860 | |
| 861 | Check that the host looks valid and matches a host or host pattern in the |
| 862 | given list of ``allowed_hosts``. Any pattern beginning with a period |
| 863 | matches a domain and all its subdomains (e.g. ``.example.com`` matches |
| 864 | ``example.com`` and any subdomain), ``*`` matches anything, and anything |
| 865 | else must match exactly. |
| 866 | |
| 867 | Note: This function assumes that the given host is lowercased and has |
| 868 | already had the port, if any, stripped off. |
| 869 | |
| 870 | Return ``True`` for a valid host, ``False`` otherwise. |
| 871 | """ |
| 872 | return any( |
| 873 | pattern == "*" or is_same_domain(host, pattern) for pattern in allowed_hosts |
| 874 | ) |