From 6f3fa9135b34e14c5330cb563b136e915d91ecf9 Mon Sep 17 00:00:00 2001 From: corvid Date: Tue, 6 Apr 2010 02:27:54 +0000 Subject: filter automatic requests same_domain option in preference so that spying on users isn't so easy. --- src/capi.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) (limited to 'src/capi.c') diff --git a/src/capi.c b/src/capi.c index 987efc3d..cbabbeae 100644 --- a/src/capi.c +++ b/src/capi.c @@ -353,6 +353,61 @@ static void Capi_dpi_send_source(BrowserWindow *bw, DilloUrl *url) dFree(cmd); } +/* + * When dillo wants to open an URL, this can be either due to user action + * (e.g., typing in an URL, clicking a link), or automatic (HTTP header + * indicates redirection, META HTML tag with refresh attribute and 0 delay, + * and images and stylesheets on an HTML page when autoloading is enabled). + * + * For a user request, the action will be permitted. + * For an automatic request, permission to load depends on the filter set + * by the user. + */ +static bool_t Capi_filters_allow(const DilloUrl *wanted, + const DilloUrl *requester) +{ + bool_t ret; + + if (requester == NULL) { + /* request made by user */ + ret = TRUE; + } else { + switch (prefs.filter_auto_requests) { + case PREFS_FILTER_SAME_DOMAIN: + { + const char *req_host = URL_HOST(requester), + *want_host = URL_HOST(wanted), + *req_suffix, + *want_suffix; + if (!req_host && !want_host) { + ret = TRUE; + } else if (!req_host || !want_host) { + ret = FALSE; + } else { + /* This will regard "www.dillo.org" and "www.dillo.org." as + * different, but it doesn't seem worth caring about. + */ + req_suffix = a_Url_host_find_public_suffix(req_host); + want_suffix = a_Url_host_find_public_suffix(want_host); + + ret = dStrcasecmp(req_suffix, want_suffix) == 0; + } + + if (ret) + MSG("ALLOW\n"); + else + MSG("DENY\n"); + break; + } + case PREFS_FILTER_ALLOW_ALL: + default: + ret = TRUE; + break; + } + } + return ret; +} + /* * Most used function for requesting a URL. * TODO: clean up the ad-hoc bindings with an API that allows dynamic @@ -369,6 +424,9 @@ int a_Capi_open_url(DilloWeb *web, CA_Callback_t Call, void *CbData) const char *scheme = URL_SCHEME(web->url); int safe = 0, ret = 0, use_cache = 0; + dReturn_val_if_fail((a_Capi_get_flags(web->url) & CAPI_IsCached) || + Capi_filters_allow(web->url, web->requester), 0); + /* reload test */ reload = (!(a_Capi_get_flags(web->url) & CAPI_IsCached) || (URL_FLAGS(web->url) & URL_E2EQuery)); -- cgit v1.2.3