aboutsummaryrefslogtreecommitdiff
path: root/src/capi.c
diff options
context:
space:
mode:
authorcorvid <corvid@lavabit.com>2010-04-06 02:27:54 +0000
committercorvid <corvid@lavabit.com>2010-04-06 02:27:54 +0000
commit6f3fa9135b34e14c5330cb563b136e915d91ecf9 (patch)
treec27e6bd8327c305e062e225ea1e5200c86425db6 /src/capi.c
parentd632e3c9d3a9fb6e3fd2dd7b28edca99012d7782 (diff)
filter automatic requests
same_domain option in preference so that spying on users isn't so easy.
Diffstat (limited to 'src/capi.c')
-rw-r--r--src/capi.c58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/capi.c b/src/capi.c
index 987efc3d..cbabbeae 100644
--- a/src/capi.c
+++ b/src/capi.c
@@ -354,6 +354,61 @@ static void Capi_dpi_send_source(BrowserWindow *bw, DilloUrl *url)
}
/*
+ * 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
* addition of new plugins.
@@ -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));