From d18c51fdf0f99ebbe78d916032fcbbf7cdec4b25 Mon Sep 17 00:00:00 2001 From: Daniel Carl Date: Mon, 25 Mar 2019 00:07:52 +0100 Subject: [PATCH] Use webkit_uri_for_display(). Use this function for shown url for IDN homograph mitigation. --- src/main.c | 10 +++++----- src/util.c | 14 +++++++++++--- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/main.c b/src/main.c index 8127235..e54d7ac 100644 --- a/src/main.c +++ b/src/main.c @@ -1351,13 +1351,13 @@ static void on_webview_load_changed(WebKitWebView *webview, switch (event) { case WEBKIT_LOAD_STARTED: - uri = util_sanitize_uri(webkit_web_view_get_uri(webview)); #ifdef FEATURE_AUTOCMD - autocmd_run(c, AU_LOAD_STARTED, uri, NULL); + autocmd_run(c, AU_LOAD_STARTED, webkit_web_view_get_uri(webview), NULL); #endif /* update load progress in statusbar */ c->state.progress = 0; vb_statusbar_update(c); + uri = util_sanitize_uri(webkit_web_view_get_uri(webview)); set_title(c, uri); /* Make sure hinting is cleared before the new page is loaded. * Without that vimb would still be in hinting mode after hinting @@ -1378,11 +1378,11 @@ static void on_webview_load_changed(WebKitWebView *webview, * or aborted the load will be commited. So this seems to be the * right place to remove the flag. */ c->mode->flags &= ~FLAG_IGNORE_FOCUS; - uri = util_sanitize_uri(webkit_web_view_get_uri(webview)); #ifdef FEATURE_AUTOCMD - autocmd_run(c, AU_LOAD_COMMITTED, uri, NULL); + autocmd_run(c, AU_LOAD_COMMITTED, webkit_web_view_get_uri(webview), NULL); #endif /* save the current URI in register % */ + uri = util_sanitize_uri(webkit_web_view_get_uri(webview)); vb_register_add(c, '%', uri); /* check if tls is on and the page is trusted */ if (g_str_has_prefix(uri, "https://")) { @@ -1407,7 +1407,7 @@ static void on_webview_load_changed(WebKitWebView *webview, case WEBKIT_LOAD_FINISHED: uri = util_sanitize_uri(webkit_web_view_get_uri(webview)); #ifdef FEATURE_AUTOCMD - autocmd_run(c, AU_LOAD_FINISHED, uri, NULL); + autocmd_run(c, AU_LOAD_FINISHED, webkit_web_view_get_uri(webview), NULL); #endif c->state.progress = 100; if (strncmp(uri, "about:", 6)) { diff --git a/src/util.c b/src/util.c index e22bb1d..a6fd4cc 100644 --- a/src/util.c +++ b/src/util.c @@ -827,16 +827,24 @@ char *util_sanitize_uri(const char *uri_str) { SoupURI *uri; char *sanitized_uri; + char *for_display; + +#if WEBKIT_CHECK_VERSION(2, 24, 0) + for_display = webkit_uri_for_display(uri_str); +#else + for_display = g_strdup(uri_str); +#endif /* Sanitize the uri only in case there is a @ which might be the indicator * for credentials used in uri. */ - if (!strchr(uri_str, '@')) { - return g_strdup(uri_str); + if (!strchr(for_display, '@')) { + return for_display; } - uri = soup_uri_new(uri_str); + uri = soup_uri_new(for_display); sanitized_uri = soup_uri_to_string(uri, FALSE); soup_uri_free(uri); + g_free(for_display); return sanitized_uri; } -- 2.20.1