Search code examples
proxydnsfirefox-addon-webextensionssocks

WebExtension proxy API: Resolve DNS entries on SOCKS5 proxy (not on the local system)


Does the WebExtension proxy API in Firefox support to resolve DNS on the proxy server when using SOCKS 5?

In the nsIProtocolProxyService API, which is no longer available in WebExtensions, it was possible. You could pass the flag Components.interfaces.nsIProxyInfo.TRANSPARENT_PROXY_RESOLVES_HOST to nsIProtocolProxyService.newProxyInfo:

This flag is set if the proxy is to perform name resolution itself. If this is the case, the hostname is used in some fashion, and we shouldn't do any form of DNS lookup ourselves

Is there some equivalent option in the new proxy API for WebExtensions?


Solution

  • Now it has become possible for WebExtension API to proxy DNS requests. Since Bug 1381290 has landed in Nightly, the proxy script can return an array of objects instead of a string. In proposal, the objects have the following properties:

    • |type| -- string, one of "http"|"https|"socks5"|"socks4"|"socks"|"direct"|"ignore"|. note that "socks" is a synonym for socks5. "ignore" means Firefox should handle this URI through its global proxy settings (which could be wpad, pac, system, direct/none, or a proxy server) or other installed addons.
    • |host| -- string
    • |port| -- integer between 1 and 65536 (TCP/IP does not allow for ports outside that range)
    • |username| -- optional string
    • |password| -- optional string
    • |proxyDNS| -- optional boolean. default false. if true, TRANSPARENT_PROXY_RESOLVES_HOST is set as a flag on nsIProxyInfo.flags so that the proxy server is used to resolve certain DNS queries.
    • |failoverTimeout| -- optional integer. default 1. Number of seconds before timing out and trying the next proxy in the failover array
    • |failover| -- optional array of objects with these same properties. null to terminate. default null (no failover, which is the desired case 99% of the time in my experience).

    For example:

    {
      type: "socks",
      host: "foo.com",
      port: 1080,
      proxyDNS: true,
      failoverTimeout: 1,
      failover: {
        type: "socks",
        host: "bar.com",
        port: 1080,
        proxyDNS: true,
        failoverTimeout: 0,
        failover: null
      }
    }
    

    But in the actual patch I can see no 'failover' option in that array:

    +    for (let prop of ["type", "host", "port", "username", "password", "proxyDNS", "failoverTimeout"]) {
    +      this[prop](proxyData);
    +    }
    

    And the 'failover' server seems to be defined like this:

    +    let failoverProxy = proxyDataList.length > 0 ? this.createProxyInfoFromData(proxyDataList, defaultProxyInfo) : defaultProxyInfo;
    

    Related Info: