All kiwix-serve errors are now frontend-translatable

But the question is do we need all of them to be translatable in the
frontend? Maybe only responses to /random, /content and /search endpoints (that
are displayed in the viewer) should be translatable?

Also, the test cases against vulnerabilities in kiwix-serve seem to suggest
that KIWIX_RESPONSE_DATA should be HTML-encoded too.
This commit is contained in:
Veloman Yunkan
2024-01-17 18:35:52 +04:00
committed by Matthieu Gautier
parent 13a6863183
commit 30b3f05497
5 changed files with 70 additions and 21 deletions

View File

@ -942,7 +942,8 @@ std::unique_ptr<Response> InternalServer::handle_search_request(const RequestCon
HTTPErrorResponse response(request, MHD_HTTP_NOT_FOUND,
"fulltext-search-unavailable",
"404-page-heading",
cssUrl);
cssUrl,
/*includeKiwixResponseData=*/true);
response += nonParameterizedMessage("no-search-results");
// XXX: Now this has to be handled by the iframe-based viewer which
// XXX: has to resolve if the book selection resulted in a single book.

View File

@ -381,20 +381,18 @@ HTTPErrorResponse::HTTPErrorResponse(const RequestContext& request,
});
}
HTTP404Response::HTTP404Response(const RequestContext& request,
bool includeKiwixResponseData)
HTTP404Response::HTTP404Response(const RequestContext& request)
: HTTPErrorResponse(request,
MHD_HTTP_NOT_FOUND,
"404-page-title",
"404-page-heading",
std::string(),
includeKiwixResponseData)
/*includeKiwixResponseData=*/true)
{
}
UrlNotFoundResponse::UrlNotFoundResponse(const RequestContext& request,
bool includeKiwixResponseData)
: HTTP404Response(request, includeKiwixResponseData)
UrlNotFoundResponse::UrlNotFoundResponse(const RequestContext& request)
: HTTP404Response(request)
{
const std::string requestUrl = urlDecode(m_request.get_full_url(), false);
*this += ParameterizedMessage("url-not-found", {{"url", requestUrl}});
@ -417,7 +415,9 @@ HTTP400Response::HTTP400Response(const RequestContext& request)
: HTTPErrorResponse(request,
MHD_HTTP_BAD_REQUEST,
"400-page-title",
"400-page-heading")
"400-page-heading",
std::string(),
/*includeKiwixResponseData=*/true)
{
std::string requestUrl = urlDecode(m_request.get_full_url(), false);
const auto query = m_request.get_query();

View File

@ -160,14 +160,12 @@ struct HTTPErrorResponse : ContentResponseBlueprint
struct HTTP404Response : HTTPErrorResponse
{
explicit HTTP404Response(const RequestContext& request,
bool includeKiwixResponseData = false);
explicit HTTP404Response(const RequestContext& request);
};
struct UrlNotFoundResponse : HTTP404Response
{
explicit UrlNotFoundResponse(const RequestContext& request,
bool includeKiwixResponseData = false);
explicit UrlNotFoundResponse(const RequestContext& request);
};
struct HTTP400Response : HTTPErrorResponse