0

I'm writing a .pac file for browser. I want browser to check url that i enter matches the rules.

function FindProxyForURL(url, host) {
    url=url.toLowerCase();
    host=host.toLowerCase();
    debugPAC ="PAC Debug Information\n";
    debugPAC +="-----------------------------------\n";
    debugPAC +="Machine IP: " + myIpAddress() + "\n";
    debugPAC +="Hostname: " + host + "\n";
    if (isResolvable(host)) {resolvableHost = "True"} else {resolvableHost = "False"};
    debugPAC +="Host Resolvable: " + resolvableHost + "\n";
    debugPAC +="Hostname IP: " + dnsResolve(host) + "\n";
    if (isPlainHostName(host)) {plainHost = "True"} else {plainHost = "False"};
    debugPAC +="Plain Hostname: " + plainHost + "\n";
    debugPAC +="Domain Levels: " + dnsDomainLevels(host) + "\n";
    debugPAC +="URL: " + url + "\n";
    if (url.substring(0,5)=="http:") {protocol="HTTP";}
    else if (url.substring(0,6)=="https:") {protocol="HTTPS";} 
    else if (url.substring(0,4)=="ftp:") {protocol="FTP";}
    else {protocol="Unknown";}
    debugPAC +="Protocol: " + protocol + "\n";
    if (!shExpMatch(url,"*.(js|xml|ico|gif|png|jpg|jpeg|css|swf)*")) {alert(debugPAC);}
    if(shExpMatch(url,"*://login.dangdang.com/images/bg/dataimg/dly_0807_01*"))
    {
        var noproxy=url;
        alert("noproxy4simplejpg"+noproxy);
        return "PROXY 192.168.0.101:808";
    }
    if(shExpMatch(url,"*://login.dangdang.com/script/sign_in2011.js"))
    {
        var noproxy=url;
        alert("noproxy4js"+noproxy);
        return "DIRECT";
    }
    if(shExpMatch(url,"*login.dangdang.com/*.gif*"))
    {
        var noproxy=url;
        alert("noproxy4gif"+noproxy);
        return "DIRECT";
    }
    if(shExpMatch(url,"*login.dangdang.com/*"))
    {
        var proxy=url;
        alert("proxy4login"+proxy);
        return "PROXY 192.168.0.101:808";
    }
    else
        return  "DIRECT"; 
}

The question is that i want to receive the complete url from browser rather than protocol and host . But now i can only receive url such as https://www.login.dngdang.com/ by testing, but i entered https://www.login.dangdang.com/xxx. what's wrong?

Passerby
  • 9,715
  • 2
  • 33
  • 50
  • Can you be more specific? What do you mean by "get"? – Passerby Aug 12 '13 at 08:16
  • I wrote some javascript to check parameter 'url' in the function. Below is the javascript: debugPAC +="Machine IP: " + myIpAddress() + "\n"; debugPAC +="Hostname: " + host + "\n"; debugPAC +="URL: " + url + "\n"; if (!shExpMatch(url,"*.(js|xml|ico|gif|png|jpg|jpeg|css|swf)*")) {alert(debugPAC);} I enter 'https://www.login.dangdang.com/xxx' ,but the function receive 'https://www.login.dangdang.com/'.why? I read the reference ,it said what you enter what receive. – sky rain Qin Aug 13 '13 at 02:32
  • You can update your own question; Put codes into your question to make it more answerable. Also, are you using some debugging tool? Because as far as I remember, `alert` does not work in PAC because it's a method of `window`, not part of ECMAScript. – Passerby Aug 13 '13 at 03:24
  • Alert does work in PAC. And I have searched some reference and found it can be used. MY browser works well too by using altert. About the debugging tool, Now google has a tool named pacparser could debug it ,but it does work ONLY on 32 bit computer, but my computer is 64 bit, so i cannot be able to use it at present. Now, what I want to konw most is whether browser sends url ignore the path or not? – sky rain Qin Aug 13 '13 at 05:19
  • eg. when entering https://external1.collaboration.pc.com/external/default.aspx The url result is https://external1.collaboration.pc.com, the other path is disapper.And I want to kown more about how the borwser engine work for it? So could you please help me look into it and share your comments? Thanks for your help. – sky rain Qin Aug 13 '13 at 05:19
  • I wonder what browser you're using, because Chrome and Firefox seem to suppress `alert`, only IE accept that. And even IE6 get the correct result. Are you sure you're posting the correct code? E.g. not accidentally wrote `url=host.toLowerCase()`? – Passerby Aug 13 '13 at 07:57
  • I use IE 10, it works well.Firefox and Chrome do not support it.I checked code many times.I could recrive the alert message but the other path is disapper. – sky rain Qin Aug 13 '13 at 08:52

1 Answers1

2

I see your URL uses HTTPS - https://www.login.dangdang.com/xxx

The path and query components of https:// URLs are stripped for security reasons by browsers by default.

In Chrome, you can disable this by setting PacHttpsUrlStrippingEnabled to false

In Firefox the preference is network.proxy.autoconfig_url.include_path.

Browsers strip privacy and security sensitive parts of https:// URLs before passing them on to PAC scripts (Proxy Auto Config) during proxy resolution.

When True, the security feature is enabled, and https:// URLs are stripped before submitting them to a PAC script. In this manner the PAC script is not able to view data that is ordinarily protected by an encrypted channel (such as the URL's path and query).

When False, the security feature is disabled, and PAC scripts are implicitly granted the ability to view all components of an https:// URL. This applies to all PAC scripts regardless of origin (including those fetched over an insecure transport, or discovered insecurely through WPAD).

This defaults to True (security feature enabled).

It is recommended that this be set to True. The only reason to set it to False is if it causes a compatibility problem with existing PAC scripts.

Abhishek
  • 1,101
  • 8
  • 8
  • It's 2022 and I just realized this. What a pity, this makes the `url` parameter in `FindProxyForURL` completely useless. I'm writing my own PAC file so I can disable this with confident, but still. – Passerby Jul 23 '22 at 14:03