add helpful error message to 403 response

Signed-off-by: Jared Van Bortel <jared@nomic.ai>
This commit is contained in:
Jared Van Bortel 2025-05-27 16:04:49 -04:00
parent 86326bb57b
commit f6a6dcf750

View File

@ -501,7 +501,10 @@ void Server::start()
// this works for HTTP/1.1 "Host" header and HTTP/2 ":authority" pseudo-header
auto host = req.url().host();
if (!host.isEmpty() && isHostUnsafe(host))
return QHttpServerResponse(QHttpServerResponder::StatusCode::Forbidden);
return QHttpServerResponse(
QJsonObject { { u"error"_s, u"Access to the server via non-local host %1 is forbidden."_s.arg(host) } },
QHttpServerResponder::StatusCode::Forbidden
);
return std::nullopt;
});