[epiphany/gnome-41] web-view: encode data in error pages
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany/gnome-41] web-view: encode data in error pages
- Date: Wed, 15 Dec 2021 20:42:37 +0000 (UTC)
commit 1666c1140c8366e83685c54bfa5c46f4661e8e22
Author: Michael Catanzaro <mcatanzaro redhat com>
Date: Tue Dec 14 17:37:05 2021 -0600
web-view: encode data in error pages
Page titles and URLs are untrusted and could be nasty, so we need to
encode them appropriately when injecting them into HTML.
Part-of: <https://gitlab.gnome.org/GNOME/epiphany/-/merge_requests/1045>
embed/ephy-web-view.c | 41 ++++++++++++++++++++++++++++++-----------
1 file changed, 30 insertions(+), 11 deletions(-)
---
diff --git a/embed/ephy-web-view.c b/embed/ephy-web-view.c
index f4f1e9295..07f8072a9 100644
--- a/embed/ephy-web-view.c
+++ b/embed/ephy-web-view.c
@@ -38,6 +38,7 @@
#include "ephy-gsb-utils.h"
#include "ephy-history-service.h"
#include "ephy-lib-type-builtins.h"
+#include "ephy-output-encoding.h"
#include "ephy-permissions-manager.h"
#include "ephy-prefs.h"
#include "ephy-reader-handler.h"
@@ -1857,6 +1858,8 @@ format_network_error_page (const char *uri,
const char **icon_name,
const char **style)
{
+ g_autofree char *encoded_uri = NULL;
+ g_autofree char *encoded_origin = NULL;
g_autofree char *formatted_origin = NULL;
g_autofree char *formatted_reason = NULL;
g_autofree char *first_paragraph = NULL;
@@ -1868,7 +1871,8 @@ format_network_error_page (const char *uri,
/* Message title when a site cannot be loaded due to a network error. */
*message_title = g_strdup (_("Unable to display this website"));
- formatted_origin = g_strdup_printf ("<strong>%s</strong>", origin);
+ encoded_origin = ephy_encode_for_html_entity (origin);
+ formatted_origin = g_strdup_printf ("<strong>%s</strong>", encoded_origin);
/* Error details when a site cannot be loaded due to a network error. */
first_paragraph = g_strdup_printf (_("The site at %s seems to be "
"unavailable."),
@@ -1890,7 +1894,8 @@ format_network_error_page (const char *uri,
/* The button on the network error page. DO NOT ADD MNEMONICS HERE. */
*button_label = g_strdup (_("Reload"));
- *button_action = g_strdup_printf ("window.location = '%s';", uri);
+ encoded_uri = ephy_encode_for_javascript (uri);
+ *button_action = g_strdup_printf ("window.location = '%s';", encoded_uri);
/* Mnemonic for the Reload button on browser error pages. */
*button_accesskey = C_("reload-access-key", "R");
@@ -1909,6 +1914,8 @@ format_crash_error_page (const char *uri,
const char **icon_name,
const char **style)
{
+ g_autofree char *html_encoded_uri = NULL;
+ g_autofree char *js_encoded_uri = NULL;
g_autofree char *formatted_uri = NULL;
g_autofree char *formatted_distributor = NULL;
g_autofree char *first_paragraph = NULL;
@@ -1920,7 +1927,8 @@ format_crash_error_page (const char *uri,
/* Message title when a site cannot be loaded due to a page crash error. */
*message_title = g_strdup (_("Oops! There may be a problem"));
- formatted_uri = g_strdup_printf ("<strong>%s</strong>", uri);
+ html_encoded_uri = ephy_encode_for_html_entity (uri);
+ formatted_uri = g_strdup_printf ("<strong>%s</strong>", html_encoded_uri);
/* Error details when a site cannot be loaded due to a page crash error. */
first_paragraph = g_strdup_printf (_("The page %s may have caused Web to "
"close unexpectedly."),
@@ -1939,7 +1947,8 @@ format_crash_error_page (const char *uri,
/* The button on the page crash error page. DO NOT ADD MNEMONICS HERE. */
*button_label = g_strdup (_("Reload"));
- *button_action = g_strdup_printf ("window.location = '%s';", uri);
+ js_encoded_uri = ephy_encode_for_javascript (uri);
+ *button_action = g_strdup_printf ("window.location = '%s';", js_encoded_uri);
/* Mnemonic for the Reload button on browser error pages. */
*button_accesskey = C_("reload-access-key", "R");
@@ -1958,6 +1967,7 @@ format_process_crash_error_page (const char *uri,
const char **icon_name,
const char **style)
{
+ g_autofree char *encoded_uri = NULL;
const char *first_paragraph;
/* Page title when a site cannot be loaded due to a process crash error. */
@@ -1973,7 +1983,8 @@ format_process_crash_error_page (const char *uri,
/* The button on the process crash error page. DO NOT ADD MNEMONICS HERE. */
*button_label = g_strdup (_("Reload"));
- *button_action = g_strdup_printf ("window.location = '%s';", uri);
+ encoded_uri = ephy_encode_for_javascript (uri);
+ *button_action = g_strdup_printf ("window.location = '%s';", encoded_uri);
/* Mnemonic for the Reload button on browser error pages. */
*button_accesskey = C_("reload-access-key", "R");
@@ -1992,6 +2003,7 @@ format_unresponsive_process_error_page (const char *uri,
const char **icon_name,
const char **style)
{
+ g_autofree char *encoded_uri = NULL;
const char *first_paragraph;
/* Page title when web content has become unresponsive. */
@@ -2007,7 +2019,8 @@ format_unresponsive_process_error_page (const char *uri,
/* The button on the unresponsive process error page. DO NOT ADD MNEMONICS HERE. */
*button_label = g_strdup (_("Reload"));
- *button_action = g_strdup_printf ("window.location = '%s';", uri);
+ encoded_uri = ephy_encode_for_javascript (uri);
+ *button_action = g_strdup_printf ("window.location = '%s';", encoded_uri);
/* Mnemonic for the Reload button on browser error pages. */
*button_accesskey = C_("reload-access-key", "R");
@@ -2031,6 +2044,7 @@ format_tls_error_page (EphyWebView *view,
const char **icon_name,
const char **style)
{
+ g_autofree char *encoded_origin = NULL;
g_autofree char *formatted_origin = NULL;
g_autofree char *first_paragraph = NULL;
@@ -2040,7 +2054,8 @@ format_tls_error_page (EphyWebView *view,
/* Message title when a site is not loaded due to an invalid TLS certificate. */
*message_title = g_strdup (_("This Connection is Not Secure"));
- formatted_origin = g_strdup_printf ("<strong>%s</strong>", origin);
+ encoded_origin = ephy_encode_for_html_entity (origin);
+ formatted_origin = g_strdup_printf ("<strong>%s</strong>", encoded_origin);
/* Error details when a site is not loaded due to an invalid TLS certificate. */
first_paragraph = g_strdup_printf (_("This does not look like the real %s. "
"Attackers might be trying to steal or "
@@ -2085,6 +2100,7 @@ format_unsafe_browsing_error_page (EphyWebView *view,
const char **icon_name,
const char **style)
{
+ g_autofree char *encoded_origin = NULL;
g_autofree char *formatted_origin = NULL;
g_autofree char *first_paragraph = NULL;
@@ -2094,7 +2110,8 @@ format_unsafe_browsing_error_page (EphyWebView *view,
/* Message title on the unsafe browsing error page. */
*message_title = g_strdup (_("Unsafe website detected!"));
- formatted_origin = g_strdup_printf ("<strong>%s</strong>", origin);
+ encoded_origin = ephy_encode_for_html_entity (origin);
+ formatted_origin = g_strdup_printf ("<strong>%s</strong>", encoded_origin);
/* Error details on the unsafe browsing error page.
* https://developers.google.com/safe-browsing/v4/usage-limits#UserWarnings
*/
@@ -2165,7 +2182,8 @@ format_no_such_file_error_page (EphyWebView *view,
const char **icon_name,
const char **style)
{
- g_autofree gchar *formatted_origin = NULL;
+ g_autofree gchar *encoded_address = NULL;
+ g_autofree gchar *formatted_address = NULL;
g_autofree gchar *first_paragraph = NULL;
g_autofree gchar *second_paragraph = NULL;
@@ -2175,10 +2193,11 @@ format_no_such_file_error_page (EphyWebView *view,
/* Message title on the no such file error page. */
*message_title = g_strdup (_("File not found"));
- formatted_origin = g_strdup_printf ("<strong>%s</strong>", view->address);
+ encoded_address = ephy_encode_for_html_entity (view->address);
+ formatted_address = g_strdup_printf ("<strong>%s</strong>", encoded_address);
first_paragraph = g_strdup_printf (_("%s could not be found."),
- formatted_origin);
+ formatted_address);
second_paragraph = g_strdup_printf (_("Please check the file name for "
"capitalization or other typing errors. Also check if "
"it has been moved, renamed, or deleted."));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]