-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is it possible to use Proxy by Patterns and PAC at the same time? #155
Comments
Proxy Auto-Configuration (PAC) file is meant to handle all patterns within itself. If you can edit the PAC, then you can add the patterns yourself. The way browsers handles proxying is that you can either choose a PAC or an individual proxy, as seen on: |
I cannot edit pac file. |
If you are looking for some practical solution, then it would be good to know the practical problem. But maybe proxying requests in every direction when browsing x.com (rather than proxying all requests to x.com whatever the current location is) would suffice? Containers allow that. |
I have a |
If the target patterns are not many, you can manually set it up. PAC
|
I need to use pac file because it keeps changing. So I cannot replace it with manual setup |
I am afraid, that adds nothing to what was said in the OP.
You've got what was said about so called containers, I hope.
Why, by the way? Monkey-patching a PAC should be as easy as: #!/bin/bash
pac_uri="http://_gateway/.pac"
pac_dest="$HOME/.pac"
cat > "$pac_dest" \
<(curl "$pac_uri" \
| sed 's/FindProxyForURL/FindProxyForURL_upstream/g') \
- <<EOF
function FindProxyForURL(url, host)
{
if (host === "x.com" || host.endsWith(".x.com"))
return "SOCKS5 a-proxy-for-x.com:1080";
else
return FindProxyForURL_upstream(url, host);
}
EOF (not tested of course) |
FWIW, here is a slighly saner version: #!/bin/bash
set -o errexit -o pipefail
pac_uri="http://_gateway/.pac"
pac_dest="$HOME/.pac"
pac_upstream=$(curl "$pac_uri")
cat > "$pac_dest" <<EOF
function _upstream(url, host)
{
EOF
printf >> "$pac_dest" '%s\n' "$pac_upstream"
cat >> "$pac_dest" <<EOF
return FindProxyForURL(url, host);
}
function FindProxyForURL(url, host)
{
if (host === "x.com" || host.endsWith(".x.com"))
return "SOCKS5 a-proxy-for-x.com:1080";
else
return _upstream(url, host);
}
EOF But may I now ask a bit offtopic question? You said, you had a PAC file, yet had been already using FoxyProxy. Till today I was under an impression, that FoxyProxy does not support loading PACs from local files; or rather Mozilla (unlike Google) forbids webexts to use Neither I can find any documentation, that would promise such a support and explain how exactly to enjoy it (besides some heavily outdated https://getfoxyproxy.org/developers/jsapi/proxy-config-object/). So the naive experiment fails:
with a pretty expectable error on console:
But now I've found: I am confused... |
Firefox allows loading PAC from
Extensions are not permitted to access local files in Firefox. |
I encountered a similar problem: A large and dynamic pac is provided by our network team yet I need to have a few exceptions redirected to another dedicated proxy. These exceptions are mostly development systems and they will be not included in the live pac file. Downloading+patching then importing the pac every few hours could work... however would be much simpler having a proxy manager that respects the higher priority of the exception rules then applies the pac if there were no other exception hit. |
Why do I ever need this extension if I could just write my own scripts? |
Yeah, you got my point right: you absolutely don't. ;) |
Yes, sorry for being unclear, that I'm very familiar with that.
Ah! But I'm afraid in my case it does not! If I understand you right, I should investigate it a bit further and report it as a bug, despite it being a (yet) undocumented feature. |
Ehm... Is not that exactly what happens, when you configure a F***fox-based browser to use a PAC, and then configure patterns with FoxyProxy (or any other onRequest-based solution)? With a reservation for a surprising behaviour (one, who thinks of proxy as of something closely related to privacy, would say, a vulnerability [1]), that Mozilla turns a blind eye to [2], that browser-wide proxy serves as a fallback one. But as long as your case is not about privacy, but about connectivity, it should not be much of an issue. Or do you talk about Chromium-based one? [1] mozilla/multi-account-containers#2265 |
Yes. Here is an example of a such config:
user_pref("network.proxy.type", 2);
user_pref("network.proxy.autoconfig_url", "file:///home/d-g/sw/browser/firefox/proxy/foxyproxy/patterns+pac/.pac");
// -*-javascript-*-
const tor = "SOCKS5 _gateway:9050";
const pxy = "SOCKS5 _gateway:1080";
const domains = {
"onion" : tor,
"example.org" : pxy,
};
function FindProxyForURL(_url, host)
{
let proxy;
if (proxy = domains[host])
return proxy;
let cursor;
while (cursor !== 0 /* indexOf returns -1 instead of false */) {
cursor = host.indexOf('.', cursor) + 1;
if (proxy = domains[host.substring(cursor)])
return proxy;
}
return "DIRECT";
} FoxyProxy: {
"mode": "pattern",
"passthrough": "",
"data": [
{
"active": true,
"title": "pxy-2",
"type": "socks5",
"hostname": "_gateway",
"port": "2080",
"pac": "",
"pacString": "",
"proxyDNS": true,
"include": [
{
"type": "wildcard",
"title": "",
"pattern": "*://example.net",
"active": true
},
{
"type": "wildcard",
"title": "",
"pattern": "*://*.example.net",
"active": true
}
],
"exclude": []
}
]
} |
Okay, it had nothing to do with This makes it even more of a bug, however! |
By the way, @user753,
note, how writing a ruleset for ‘this extension’ actually turned out more cumbersome, than expressing the same idea with a homebrewed script: just
vs
Which is hardly surprising by itself: given two tools: of a limited expressive power and of less limited, you can imagine infinite number of scenarios, when the latter enables you to write cleaner code. What did surprise me, is that was the most (I believe) common scenario: when you need to match a domain and all its subdomains. |
I tried to interpret what you just suggested and implement it:
Result: Most likely my original problem was that I configured both the exceptions AND the "default" (the pac) on FoxyProxy level while leaving the browser level config on the "No Proxy" setting. I was expected FoxyProxy to sort out which traffic should go to which proxy config... and however this configuration now works, it is not too intuitive or logical... at least for me. I would suggest an enhancement in some way so the user doesn't have to configure proxy settings on 2 different places: in the manager AND in the browser as well. Anyways, thanks for the "workaround" suggestion! |
Iʼm afraid the original underlying problem is that (as @erosman explained above) there is really no such thing as PAC support at FoxyProxy level (yet?). Instead, when you command it to use PAC, it just sets I suppose, this mess is a result of UI unification with FP for Chromium-based browsers.
I have a bold guess, that you were not alone on this thread. ;)
You are welcome. But it is hardly a workaround... it is a pretty straightforward setup for your task. |
I use Firefox and FoxyProxy 8.9
I have a pac proxy and another proxy for
x.com
If I select my pac proxy - sites for this proxy works buy proxy for
x.com
doesn't workIf I select
Proxy by Patterns
- proxy forx.com
works buy pac proxy doesn't workWhat can I do?
The text was updated successfully, but these errors were encountered: