Azure / Azure/azure-functions-host
HTTP Error 400. The request hostname is invalid.
- Dominant language
- C#
- Stars
- 2k
- Forks
- 482
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 38
Description
We've seen that in super rare cases a cold start request to Function App might incorrectly return an error response of the form:
```
{
'statusCode': 400,
'headers': {
'Date': 'Mon, 25 Nov 2024 19:42:56 GMT',
'Content-Length': '334',
'Content-Type': 'text/html'
},
'body': '<!DOCTYPE HTML PUBLIC \\'-//W3C//DTD HTML 4.01//EN\\'\\'http://www.w3.org/TR/html4/strict.dtd\\'>\\r\\n<HTML><HEAD><TITLE>Bad Request</TITLE>\\r\\n<META HTTP-EQUIV=\\'Content-Type\\' Content=\\'text/html; charset=us-ascii\\'></ HEAD >\\r\\n<BODY><h2>Bad Request - Invalid Hostname </h2>\\r\\n<hr><p>HTTP Error 400. The request hostname is invalid. </p>\\r\\n</BODY></HTML>'
}
```
This has come up most recently in the following CRI: https://portal.microsofticm.com/imp/v5/incidents/details/570328048/summary. Investigation has shown that this response isn't coming from the App Service platform, nor the Functions Host runtime. It appears to be coming from ASP.NET [HostFilteringMiddleware](https://github.com/dotnet/aspnetcore/blob/849235790fe151ab311192d7e6c5860e6c177f5e/src/Middleware/HostFiltering/src/HostFilteringMiddleware.cs#L23). Now the Functions Host doesn't register or configure this middleware in any way. See also [this](https://github.com/dotnet/aspnetcore/blob/849235790fe151ab311192d7e6c5860e6c177f5e/src/DefaultBuilder/src/WebHost.cs#L253C13-L268C81) code.
While we don't know yet what might be causing this, this issue will serve as a tracking item to see if we get more cases of this. In the case we saw, when the request was retried it succeeded so the issue is super rare and transient.
Contributor guide
Research direction
Start with the ASP.NET HostFilteringMiddleware and the Functions Host WebHost.cs references in the issue, then review the reported cold-start response and the linked incident. Done means identifying why the transient invalid-hostname response occurs and documenting a reproducible fix or a concrete follow-up investigation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- azure, csharp
- Domain
- backend, cloud
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 32/100