This is a migrated thread and some comments may be shown as answers.

FiddlerCore Blocking Problem

3 Answers 269 Views
FiddlerCore
This is a migrated thread and some comments may be shown as answers.
Mahbub
Top achievements
Rank 1
Mahbub asked on 04 Nov 2015, 09:59 PM

Hello, this is my first time using FiddlerCore and am trying to grasp the concepts behind it. I am developing a simple project that should block websites that are specified in a database, and block all sites if the user is browsing at a time that is set by the administrator. It is for a school project. For now, I have hard-coded the site I want blocked: "facebook.com". Below is the code:

 

void FiddlerApplication_BeforeRequest(Session oSession)
        {
            if (oSession.url.Contains("facebook.com"))
            {
                oSession.utilCreateResponseAndBypassServer();
                oSession.oResponse.headers.SetStatus(307, "Redirect");
                oSession.oResponse["Cache-Control"] = "nocache";
                oSession.oResponse["Location"] = "http://microsoft.com";
                oSession.utilSetResponseBody(GenerateErrorMessage("Internet Time", "The request was set at a time interval that is blocked by the " +
                    "administrator(s) of this computer", oSession.fullUrl, "--"));
                return;
            }
        }

 However, I am getting an ERR_TUNNEL_CONNECTION_FAILED message in google chrome and I am getting a page cannot be displayed in internet explorer. Basically what I would like is if a site is block, display the html in the browser specified in oSession.utilSetResponseBody(GenerateErrorMessage("Internet Time", "The request was set at a time interval that is blocked by the " + "administrator(s) of this computer", oSession.fullUrl, "--"));

 

This works in all sites that do not have "https:". For ex: I am getting my desired result that I want if I try to block "microsoft.com".

Any help is appreciated. 

3 Answers, 1 is accepted

Sort by
0
Mahbub
Top achievements
Rank 1
answered on 04 Nov 2015, 10:01 PM

Small edit,

 It should NOT be: oSession.oResponse.headers.SetStatus(307, "Redirect");

 It should be: oSession.oResponse.headers.SetStatus(451, "Blocked");

I accidentally copy pasted an old code

0
Eric Lawrence
Telerik team
answered on 04 Nov 2015, 10:40 PM
Yes, you need to use a status other than 307 and you should NOT include a Location header.

So the code should look something like:

void FiddlerApplication_BeforeRequest(Session oSession)
        {
            if (!oSession.HTTPMethodIs("CONNECT"))
           {
            if oSession.url.Contains("facebook.com"))

            {
                oSession.utilCreateResponseAndBypassServer();
                oSession.oResponse.headers.SetStatus(451, "Blocked");
                oSession.oResponse["Cache-Control"] = "no-cache";
                oSession.utilSetResponseBody(GenerateErrorMessage("Internet Time", "The request was set at a time interval that is blocked by the " +
                    "administrator(s) of this computer", Utilities.HtmlEncode(oSession.fullUrl), "--"));
                return;
            }
         }
        else
        {
            if (oSession.HostnameIs("facebook.com")) oSession["x-replywithtunnel"] = "will block later...";
        }
        }

If the HTTP Method is CONNECT then you need to do things differently to avoid corrupting the HTTPS channel. You can either not touch the request at all, or you can examine the target hostname and if it's something you care about, then you just set the session flag: oSession["x-replywithTunnel"] = "My interceptor"; and Fiddler will generate an appropriate tunnel response without actually talking to the target server.

Regards,
Eric Lawrence
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Mahbub
Top achievements
Rank 1
answered on 04 Nov 2015, 10:49 PM
Thank you, that solved my problem.
Tags
FiddlerCore
Asked by
Mahbub
Top achievements
Rank 1
Answers by
Mahbub
Top achievements
Rank 1
Eric Lawrence
Telerik team
Share this question
or