Bug 1325876 - Add a pref for showing internal error page for HTTP responses with error codes (4xx, 5xx) and Content-Length: 0 instead of blank page r=manuel,necko-reviewers,fluent-reviewers,jesup,bolsson,valentin,kershaw

Differential Revision: https://phabricator.services.mozilla.com/D220193
This commit is contained in:
Sean
2025-01-27 21:05:42 +00:00
parent b45af8c387
commit c73aeda52c
11 changed files with 45 additions and 2 deletions

View File

@@ -6,6 +6,7 @@ malformedURI2=Please check that the URL is correct and try again.
fileNotFound=Firefox cant find the file at %S.
fileAccessDenied=The file at %S is not readable.
# %S is replaced by the uri host
httpErrorPage=%S sent back an error.
serverError=%S might have a temporary problem or it could have moved.
dnsNotFound2=We cant connect to the server at %S.
basicHttpAuthDisabled=Someone pretending to be the site could try to steal things like your username, password, or email.

View File

@@ -3354,6 +3354,9 @@ nsDocShell::DisplayLoadError(nsresult aError, nsIURI* aURI,
nestedURI = do_QueryInterface(tempURI);
}
error = "unknownProtocolFound";
} else if (NS_ERROR_NET_EMPTY_RESPONSE == aError) {
NS_ENSURE_ARG_POINTER(aURI);
error = "httpErrorPage";
} else if (NS_ERROR_NET_ERROR_RESPONSE == aError) {
NS_ENSURE_ARG_POINTER(aURI);
error = "serverError";
@@ -6111,6 +6114,7 @@ nsresult nsDocShell::FilterStatusForErrorPage(
if (aStatus == NS_ERROR_NET_TIMEOUT ||
aStatus == NS_ERROR_NET_TIMEOUT_EXTERNAL ||
aStatus == NS_ERROR_NET_EMPTY_RESPONSE ||
aStatus == NS_ERROR_NET_ERROR_RESPONSE ||
aStatus == NS_ERROR_PROXY_GATEWAY_TIMEOUT ||
aStatus == NS_ERROR_REDIRECT_LOOP ||

View File

@@ -6,6 +6,7 @@ malformedURI2=Please check that the URL is correct and try again.
fileNotFound=The file %S cannot be found. Please check the location and try again.
fileAccessDenied=The file at %S is not readable.
# %S is replaced by the uri host
httpErrorPage=%S sent back an error.
serverError=%S might have a temporary problem or it could have moved.
dnsNotFound2=%S could not be found. Please check the name and try again.
basicHttpAuthDisabled=Someone pretending to be the site could try to steal your info. Your connection settings could also be set up incorrectly.

View File

@@ -158,6 +158,7 @@ XPC_MSG_DEF(NS_ERROR_NET_TIMEOUT_EXTERNAL , "The request has been canc
XPC_MSG_DEF(NS_ERROR_OFFLINE , "The requested action could not be completed in the offline state")
XPC_MSG_DEF(NS_ERROR_PORT_ACCESS_NOT_ALLOWED , "Establishing a connection to an unsafe or otherwise banned port was prohibited")
XPC_MSG_DEF(NS_ERROR_NET_RESET , "The connection was established, but no data was ever received")
XPC_MSG_DEF(NS_ERROR_NET_EMPTY_RESPONSE , "The connection was established, but the browser received an empty page with an error response")
XPC_MSG_DEF(NS_ERROR_NET_ERROR_RESPONSE , "The connection was established, but the browser received an error response from the server")
XPC_MSG_DEF(NS_ERROR_NET_INTERRUPT , "The connection was established, but the data transfer was interrupted")
XPC_MSG_DEF(NS_ERROR_NET_PARTIAL_TRANSFER , "A transfer was only partially done when it completed")

View File

@@ -1584,6 +1584,15 @@
value: false
mirror: always
# If false, show internal error page for HTTP responses with error
# codes (4xx, 5xx) and "Content-Length": 0 instead of blank page
# See https://bugzilla.mozilla.org/show_bug.cgi?id=1325876#c32 for why this
# is disabled on Android.
- name: browser.http.blank_page_with_error_response.enabled
type: bool
value: true
mirror: always
# The minimum area for a rect to be included in a wireframe, in CSS pixels.
#
# The current value of 50 is pretty arbitrary, and will be tuned as we refine

View File

@@ -46,6 +46,7 @@ const KNOWN_ERROR_TITLE_IDS = new Set([
"unsafeContentType-title",
"netReset-title",
"netTimeout-title",
"httpErrorPage-title",
"serverError-title",
"unknownProtocolFound-title",
"proxyConnectFailure-title",
@@ -773,8 +774,7 @@ function getNetErrorDescParts() {
case "connectionFailure":
case "netInterrupt":
case "netReset":
case "netTimeout":
case "serverError": {
case "netTimeout": {
let errorTags = [
["li", "neterror-load-error-try-again"],
["li", "neterror-load-error-connection"],
@@ -786,6 +786,10 @@ function getNetErrorDescParts() {
return errorTags;
}
case "httpErrorPage": // 4xx
return [["li", "neterror-http-error-page"]];
case "serverError": // 5xx
return [["li", "neterror-load-error-try-again"]];
case "blockedByCOOP": {
return [
["p", "certerror-blocked-by-corp-headers-description"],

View File

@@ -127,6 +127,7 @@ contentEncodingError-title = Content Encoding Error
unsafeContentType-title = Unsafe File Type
netReset-title = The connection was reset
netTimeout-title = The connection has timed out
httpErrorPage-title = Looks like theres a problem with this site
serverError-title = Looks like theres a problem with this site
unknownProtocolFound-title = The address wasnt understood
proxyConnectFailure-title = The proxy server is refusing connections

View File

@@ -44,6 +44,8 @@ neterror-load-error-firewall = If your computer or network is protected by a fir
# This warning is only shown on macOS Sequoia and later (see bug 1929377)
neterror-load-osx-permission = If you are trying to load a local network page, please check that { -brand-short-name } has been granted Local Network permissions in the macOS Privacy & Security settings.
neterror-http-error-page = Check to make sure youve typed the website address correctly.
neterror-captive-portal = You must log in to this network before you can access the internet.
# Variables:

View File

@@ -63,6 +63,7 @@ ID01:
- unsafeContentType-title
- netReset-title
- netTimeout-title
- httpErrorPage-title
- serverError-title
- unknownProtocolFound-title
- proxyConnectFailure-title

View File

@@ -131,6 +131,23 @@ NS_IMETHODIMP nsDocumentOpenInfo::OnStartRequest(nsIRequest* request) {
if (204 == responseCode || 205 == responseCode) {
return NS_BINDING_ABORTED;
}
if (!mozilla::StaticPrefs::
browser_http_blank_page_with_error_response_enabled()) {
// Bug 1325876: Show internal error page for HTTP responses with error
// codes (4xx, 5xx) and "Content-Length": 0 instead of blank page
int64_t contentLength = 0;
rv = httpChannel->GetContentLength(&contentLength);
if (NS_FAILED(rv) || contentLength <= 0) {
if (responseCode >= 500) {
return NS_ERROR_NET_ERROR_RESPONSE;
}
if (responseCode >= 400) {
return NS_ERROR_NET_EMPTY_RESPONSE;
}
}
}
}
//

View File

@@ -327,6 +327,8 @@ with modules["NETWORK"]:
errors["NS_ERROR_NET_RESET"] = FAILURE(20)
# The connection was established, but browser received an error response from the server
errors["NS_ERROR_NET_ERROR_RESPONSE"] = FAILURE(35)
# The connection was established, but browser received an empty page with 4xx, 5xx error response
errors["NS_ERROR_NET_EMPTY_RESPONSE"] = FAILURE(36)
# The connection was established, but the data transfer was interrupted.
errors["NS_ERROR_NET_INTERRUPT"] = FAILURE(71)
# The connection attempt to a proxy failed.