def process(self, request, render_options, operation, data):
        filter_names = render_options.get_filters(adblock_rules=self.rules)

        if filter_names == ['none']:
            return request

        if not filter_names:
            if self.rules.filter_is_known('default'):
                filter_names = ['default']
            else:
                return request

        url = str(request.url().toString())
        browser_url = self._get_browser_url(request)
        domain = urlsplit(browser_url).hostname or ''
        # XXX: here we're using domain of a parent frame
        # for requests coming from iframes.
        options = {'domain': domain}
        blocking_filter = self.rules.get_blocking_filter(
            filter_names, url, options)
        if blocking_filter:
            if self.verbosity >= 2:
                msg = "Filter %s: dropped %s %s" % (
                    blocking_filter, render_options.get_uid(),
                    request_repr(request, operation))
                log.msg(msg, system='request_middleware')
            drop_request(request)
        return request
Ejemplo n.º 2
0
    def process(self, request, render_options, operation, data):
        filter_names = render_options.get_filters(adblock_rules=self.rules)

        if filter_names == ['none']:
            return request

        if not filter_names:
            if self.rules.filter_is_known('default'):
                filter_names = ['default']
            else:
                return request

        url = str(request.url().toString())
        browser_url = self._get_browser_url(request)
        domain = urlsplit(browser_url).hostname or ''
        # XXX: here we're using domain of a parent frame
        # for requests coming from iframes.
        options = {'domain': domain}
        blocking_filter = self.rules.get_blocking_filter(filter_names, url, options)
        if blocking_filter:
            if self.verbosity >= 2:
                msg = "Filter %s: dropped %s %s" % (
                    blocking_filter,
                    render_options.get_uid(),
                    request_repr(request, operation)
                )
                log.msg(msg, system='request_middleware')
            drop_request(request)
        return request
Ejemplo n.º 3
0
 def process(self, request, render_options, operation, data):
     allowed_domains = render_options.get_allowed_domains()
     host_re = self._get_host_regex(allowed_domains, self.allow_subdomains)
     if not host_re.match(six.text_type(request.url().host())):
         if self.verbosity >= 2:
             log.msg("Dropped offsite %s" % (request_repr(request, operation),), system='request_middleware')
         drop_request(request)
     return request
 def process(self, request, render_options, operation, data):
     scheme = str(request.url().scheme()).lower()
     if scheme not in self.allowed_schemes:
         if self.verbosity >= 2:
             log.msg("Dropped %s because of URI scheme" %
                     (request_repr(request, operation), ),
                     system='request_middleware')
         drop_request(request)
     return request
Ejemplo n.º 5
0
 def process(self, request, render_options, operation, data):
     scheme = str(request.url().scheme()).lower()
     if scheme not in self.allowed_schemes:
         if self.verbosity >= 2:
             log.msg(
                 "Dropped %s because of URI scheme" % (request_repr(request, operation),),
                 system='request_middleware'
             )
         drop_request(request)
     return request
Ejemplo n.º 6
0
    def process(self, reply, render_options):
        content_type = reply.header(QNetworkRequest.ContentTypeHeader)
        if not content_type.isValid():
            return

        mimetype = self.clean_mime(str(content_type.toString()))
        allowed = render_options.get_allowed_content_types()
        forbidden = render_options.get_forbidden_content_types()
        whitelist = set(map(ContentTypeMiddleware.clean_mime, allowed))
        blacklist = set(map(ContentTypeMiddleware.clean_mime, forbidden))

        if self.contains(blacklist, mimetype) or not self.contains(whitelist, mimetype):
            if self.verbosity >= 2:
                request_str = request_repr(reply, reply.operation())
                msg = "Dropping %s because of Content Type" % request_str
                log.msg(msg, system='response_middleware')
            reply.abort()
Ejemplo n.º 7
0
    def process(self, reply, render_options):
        content_type = reply.header(QNetworkRequest.ContentTypeHeader)
        if not content_type.isValid():
            return

        mimetype = self.clean_mime(str(content_type.toString()))
        allowed = render_options.get_allowed_content_types()
        forbidden = render_options.get_forbidden_content_types()
        whitelist = set(map(ContentTypeMiddleware.clean_mime, allowed))
        blacklist = set(map(ContentTypeMiddleware.clean_mime, forbidden))

        if self.contains(blacklist, mimetype) or not self.contains(whitelist, mimetype):
            if self.verbosity >= 2:
                request_str = request_repr(reply, reply.operation())
                msg = "Dropping %s because of Content Type" % request_str
                log.msg(msg, system='response_middleware')
            reply.abort()
Ejemplo n.º 8
0
    def process(self, request, render_options, operation, data):
        filter_names = render_options.get_filters(adblock_rules=self.rules)

        if filter_names == ['none']:
            return request

        if not filter_names:
            if self.rules.filter_is_known('default'):
                filter_names = ['default']
            else:
                return request

        url, options = self._url_and_adblock_options(request, render_options)
        blocking_filter = self.rules.get_blocking_filter(
            filter_names, url, options)
        if blocking_filter:
            if self.verbosity >= 2:
                msg = "Filter %s: dropped %s %s" % (
                    blocking_filter, render_options.get_uid(),
                    request_repr(request, operation))
                log.msg(msg, system='request_middleware')
            drop_request(request)
        return request
Ejemplo n.º 9
0
    def process(self, request, render_options, operation, data):
        filter_names = render_options.get_filters(adblock_rules=self.rules)

        if filter_names == ['none']:
            return request

        if not filter_names:
            if self.rules.filter_is_known('default'):
                filter_names = ['default']
            else:
                return request

        url, options = self._url_and_adblock_options(request, render_options)
        blocking_filter = self.rules.get_blocking_filter(filter_names, url, options)
        if blocking_filter:
            if self.verbosity >= 2:
                msg = "Filter %s: dropped %s %s" % (
                    blocking_filter,
                    render_options.get_uid(),
                    request_repr(request, operation)
                )
                log.msg(msg, system='request_middleware')
            drop_request(request)
        return request
Ejemplo n.º 10
0
    def process(self, request, splash_request, operation, data):
        filter_names = [f for f in getarg(splash_request, "filters", default="").split(',') if f]

        if filter_names == ['none']:
            return request

        if not filter_names:
            if self.rules.filter_is_known('default'):
                filter_names = ['default']
            else:
                return request

        url, options = self._url_and_options(request, splash_request)
        blocking_filter = self.rules.get_blocking_filter(filter_names, url, options)
        if blocking_filter:
            if self.verbosity >= 2:
                msg = "Filter %s: dropped %s %s" % (
                    blocking_filter,
                    id(splash_request),
                    request_repr(request, operation)
                )
                log.msg(msg, system='request_middleware')
            drop_request(request)
        return request
Ejemplo n.º 11
0
 def process(self, request, render_options, operation, data):
     log.msg("[%s] %s" %
             (render_options.get_uid(), request_repr(request, operation)),
             system='network')
     return request
Ejemplo n.º 12
0
 def process(self, request, render_options, operation, data):
     log.msg(
         "[%s] %s" % (render_options.get_uid(), request_repr(request, operation)),
         system='network'
     )
     return request
Ejemplo n.º 13
0
 def process(self, request, splash_request, operation, data):
     log.msg(
         "Request %s %s" % (id(splash_request), request_repr(request, operation)),
         system='network'
     )
     return request