[epiphany/mcatanzaro/#1612: 11/13] web-view: encode data in error pages
- From: Marge Bot <marge-bot src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany/mcatanzaro/#1612: 11/13] web-view: encode data in error pages
- Date: Wed, 15 Dec 2021 19:30:59 +0000 (UTC)
commit 00821051a8120cadb721835ee8203336e8867be4
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 55d969020..ae8413e94 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"
@@ -1858,6 +1859,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;
@@ -1869,7 +1872,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."),
@@ -1891,7 +1895,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");
@@ -1910,6 +1915,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;
@@ -1921,7 +1928,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."),
@@ -1940,7 +1948,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");
@@ -1959,6 +1968,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. */
@@ -1974,7 +1984,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");
@@ -1993,6 +2004,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. */
@@ -2008,7 +2020,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");
@@ -2032,6 +2045,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;
@@ -2041,7 +2055,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 "
@@ -2086,6 +2101,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;
@@ -2095,7 +2111,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
*/
@@ -2166,7 +2183,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;
@@ -2176,10 +2194,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]