diff --git a/omega-pac/src/conditions.coffee b/omega-pac/src/conditions.coffee index 44ceab8..d9a2b07 100644 --- a/omega-pac/src/conditions.coffee +++ b/omega-pac/src/conditions.coffee @@ -352,7 +352,16 @@ module.exports = exports = return false if cache.ip? and not @match cache.ip, request if cache.host? if cache.host == '' - return request.host in @localHosts + # https://code.google.com/p/chromium/codesearch#chromium/src/net/proxy/proxy_bypass_rules.cc&sq=package:chromium&l=67 + # We align with Chromium's behavior of bypassing 127.0.0.1, ::1 as + # well as any host without dots. + # + # This, however, will match IPv6 literals who also don't have dots. + return ( + request.host == '127.0.0.1' or + request.host == '::1' or + request.host.indexOf('.') < 0 + ) else return false if not cache.host.test(request.host) return false if cache.url? and !cache.url.test(request.url) @@ -370,12 +379,22 @@ module.exports = exports = ) return new U2.AST_Binary( left: new U2.AST_Binary( - left: hostEquals '[::1]' + left: hostEquals '127.0.0.1' operator: '||' - right: hostEquals 'localhost' + right: hostEquals '::1' ) operator: '||' - right: hostEquals '127.0.0.1' + right: new U2.AST_Binary( + left: new U2.AST_Call( + expression: new U2.AST_Dot( + expression: new U2.AST_SymbolRef name: 'host' + property: 'indexOf' + ) + args: [new U2.AST_String value: '.'] + ) + operator: '<' + right: new U2.AST_Number value: 0 + ) ) if cache.scheme? conditions.push new U2.AST_Binary( diff --git a/omega-pac/src/profiles.coffee b/omega-pac/src/profiles.coffee index 0d3da2b..ff93878 100644 --- a/omega-pac/src/profiles.coffee +++ b/omega-pac/src/profiles.coffee @@ -237,10 +237,20 @@ module.exports = exports = 'FixedProfile': includable: true create: (profile) -> - profile.bypassList ?= [{ - conditionType: 'BypassCondition' - pattern: '' - }] + profile.bypassList ?= [ + { + conditionType: 'BypassCondition' + pattern: '127.0.0.1' + } + { + conditionType: 'BypassCondition' + pattern: '::1' + } + { + conditionType: 'BypassCondition' + pattern: 'localhost' + } + ] match: (profile, request) -> if profile.bypassList for cond in profile.bypassList diff --git a/omega-pac/test/conditions.coffee b/omega-pac/test/conditions.coffee index 11da554..cc91bb8 100644 --- a/omega-pac/test/conditions.coffee +++ b/omega-pac/test/conditions.coffee @@ -31,6 +31,7 @@ describe 'Conditions', -> printCond = JSON.stringify(condition) printCompiled = if compiled then 'COMPILED ' else '' printMatch = if should_match then 'to match' else 'not to match' + console.log(request) msg = ("expect #{printCompiled}condition #{printCond} " + "#{printMatch} request #{o_request}") chai.assert(false, msg) @@ -219,6 +220,31 @@ describe 'Conditions', -> prefixLength: 0 }) + it 'should match 127.0.0.1 when is used', -> + cond = + conditionType: 'BypassCondition' + pattern: '' + testCond(cond, 'http://127.0.0.1:8080/', 'match') + + it 'should match [::1] when is used', -> + cond = + conditionType: 'BypassCondition' + pattern: '' + testCond(cond, 'http://[::1]:8080/', 'match') + + it 'should match any host without dots when is used', -> + cond = + conditionType: 'BypassCondition' + pattern: '' + testCond(cond, 'http://localhost:8080/', 'match') + testCond(cond, 'http://intranet:8080/', 'match') + testCond(cond, 'http://foobar/', 'match') + testCond(cond, 'http://example.com/', not 'match') + + # Intended, see the corresponding code and comments for the reasoning. + testCond(cond, 'http://[::ffff:eeee]/', 'match') + testCond(cond, 'http://[::1.2.3.4]/', not 'match') + describe 'IpCondition', -> # IpCondition requires isInNetEx or isInNet function provided by the PAC # runner, which is not available in the unit test. So We can't use testCond diff --git a/omega-target-chromium-extension/src/options.coffee b/omega-target-chromium-extension/src/options.coffee index 6c95e35..d34011b 100644 --- a/omega-target-chromium-extension/src/options.coffee +++ b/omega-target-chromium-extension/src/options.coffee @@ -108,11 +108,7 @@ class ChromeOptions extends OmegaTarget.Options if config['mode'] != 'direct' rules['bypassList'] = bypassList = [] for rule in profile.bypassList - if rule.pattern == '' - for host in OmegaPac.Conditions.localHosts - bypassList.push(host) - else - bypassList.push(rule.pattern) + bypassList.push(rule.pattern) config['rules'] = rules return config diff --git a/omega-target-chromium-extension/src/upgrade.coffee b/omega-target-chromium-extension/src/upgrade.coffee index f8ffbfd..f7bc722 100644 --- a/omega-target-chromium-extension/src/upgrade.coffee +++ b/omega-target-chromium-extension/src/upgrade.coffee @@ -122,8 +122,18 @@ module.exports = (oldOptions, i18n) -> exampleFixedProfileName = 'Example Profile' options[OmegaPac.Profiles.nameAsKey(exampleFixedProfileName)] = bypassList: [ - pattern: "" - conditionType: "BypassCondition" + { + pattern: "127.0.0.1" + conditionType: "BypassCondition" + } + { + pattern: "::1" + conditionType: "BypassCondition" + } + { + pattern: "localhost" + conditionType: "BypassCondition" + } ] profileType: "FixedProfile" name: exampleFixedProfileName diff --git a/omega-target/src/default_options.coffee b/omega-target/src/default_options.coffee index 0d40a8e..92dc31c 100644 --- a/omega-target/src/default_options.coffee +++ b/omega-target/src/default_options.coffee @@ -10,8 +10,18 @@ module.exports = -> "-downloadInterval": 1440 "+proxy": bypassList: [ - pattern: "" - conditionType: "BypassCondition" + { + pattern: "127.0.0.1" + conditionType: "BypassCondition" + } + { + pattern: "::1" + conditionType: "BypassCondition" + } + { + pattern: "localhost" + conditionType: "BypassCondition" + } ] profileType: "FixedProfile" name: "proxy"