# starlette.middleware.trustedhost.InvalidHost: Invalid host header

- **ID:** `python/starlette-trustedhost-invalid-host`
- **Domain:** python
- **Category:** network_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

TrustedHostMiddleware is enabled but the request Host header is not in the allowed_hosts list (common behind proxies or on localhost).

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 3.x | active | — | — |

## Workarounds

1. **** (93% success)
   ```
   app.add_middleware(TrustedHostMiddleware, allowed_hosts=['example.com', '*.example.com'])
   ```
2. **** (87% success)
   ```
   from uvicorn.middleware.proxy_headers import ProxyHeadersMiddleware
app.add_middleware(ProxyHeadersMiddleware, trusted_hosts='*')
   ```

## Dead Ends

- **** — Disables host header protection entirely. (85% fail)
- **** — Deployed environments still reject proxy hosts. (80% fail)
