mirror of
https://github.com/zero-peak/ZeroOmega.git
synced 2025-01-22 15:08:12 -05:00
Pass <local> to target browser as-is. Avoid <local> in default config.
See the added comments as well as #443 for discussion. Newly created proxy profiles will have 127.0.0.1, ::1 and localhost in bypass list by default, instead of <local> in hope that fewer users will be trapped in the IPv6 literals gotcha.
This commit is contained in:
parent
374b8a42c5
commit
b67790eb83
@ -352,7 +352,16 @@ module.exports = exports =
|
|||||||
return false if cache.ip? and not @match cache.ip, request
|
return false if cache.ip? and not @match cache.ip, request
|
||||||
if cache.host?
|
if cache.host?
|
||||||
if cache.host == '<local>'
|
if cache.host == '<local>'
|
||||||
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
|
else
|
||||||
return false if not cache.host.test(request.host)
|
return false if not cache.host.test(request.host)
|
||||||
return false if cache.url? and !cache.url.test(request.url)
|
return false if cache.url? and !cache.url.test(request.url)
|
||||||
@ -370,12 +379,22 @@ module.exports = exports =
|
|||||||
)
|
)
|
||||||
return new U2.AST_Binary(
|
return new U2.AST_Binary(
|
||||||
left: new U2.AST_Binary(
|
left: new U2.AST_Binary(
|
||||||
left: hostEquals '[::1]'
|
left: hostEquals '127.0.0.1'
|
||||||
operator: '||'
|
operator: '||'
|
||||||
right: hostEquals 'localhost'
|
right: hostEquals '::1'
|
||||||
)
|
)
|
||||||
operator: '||'
|
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?
|
if cache.scheme?
|
||||||
conditions.push new U2.AST_Binary(
|
conditions.push new U2.AST_Binary(
|
||||||
|
@ -237,10 +237,20 @@ module.exports = exports =
|
|||||||
'FixedProfile':
|
'FixedProfile':
|
||||||
includable: true
|
includable: true
|
||||||
create: (profile) ->
|
create: (profile) ->
|
||||||
profile.bypassList ?= [{
|
profile.bypassList ?= [
|
||||||
conditionType: 'BypassCondition'
|
{
|
||||||
pattern: '<local>'
|
conditionType: 'BypassCondition'
|
||||||
}]
|
pattern: '127.0.0.1'
|
||||||
|
}
|
||||||
|
{
|
||||||
|
conditionType: 'BypassCondition'
|
||||||
|
pattern: '::1'
|
||||||
|
}
|
||||||
|
{
|
||||||
|
conditionType: 'BypassCondition'
|
||||||
|
pattern: 'localhost'
|
||||||
|
}
|
||||||
|
]
|
||||||
match: (profile, request) ->
|
match: (profile, request) ->
|
||||||
if profile.bypassList
|
if profile.bypassList
|
||||||
for cond in profile.bypassList
|
for cond in profile.bypassList
|
||||||
|
@ -31,6 +31,7 @@ describe 'Conditions', ->
|
|||||||
printCond = JSON.stringify(condition)
|
printCond = JSON.stringify(condition)
|
||||||
printCompiled = if compiled then 'COMPILED ' else ''
|
printCompiled = if compiled then 'COMPILED ' else ''
|
||||||
printMatch = if should_match then 'to match' else 'not to match'
|
printMatch = if should_match then 'to match' else 'not to match'
|
||||||
|
console.log(request)
|
||||||
msg = ("expect #{printCompiled}condition #{printCond} " +
|
msg = ("expect #{printCompiled}condition #{printCond} " +
|
||||||
"#{printMatch} request #{o_request}")
|
"#{printMatch} request #{o_request}")
|
||||||
chai.assert(false, msg)
|
chai.assert(false, msg)
|
||||||
@ -219,6 +220,31 @@ describe 'Conditions', ->
|
|||||||
prefixLength: 0
|
prefixLength: 0
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it 'should match 127.0.0.1 when <local> is used', ->
|
||||||
|
cond =
|
||||||
|
conditionType: 'BypassCondition'
|
||||||
|
pattern: '<local>'
|
||||||
|
testCond(cond, 'http://127.0.0.1:8080/', 'match')
|
||||||
|
|
||||||
|
it 'should match [::1] when <local> is used', ->
|
||||||
|
cond =
|
||||||
|
conditionType: 'BypassCondition'
|
||||||
|
pattern: '<local>'
|
||||||
|
testCond(cond, 'http://[::1]:8080/', 'match')
|
||||||
|
|
||||||
|
it 'should match any host without dots when <local> is used', ->
|
||||||
|
cond =
|
||||||
|
conditionType: 'BypassCondition'
|
||||||
|
pattern: '<local>'
|
||||||
|
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', ->
|
describe 'IpCondition', ->
|
||||||
# IpCondition requires isInNetEx or isInNet function provided by the PAC
|
# 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
|
# runner, which is not available in the unit test. So We can't use testCond
|
||||||
|
@ -108,11 +108,7 @@ class ChromeOptions extends OmegaTarget.Options
|
|||||||
if config['mode'] != 'direct'
|
if config['mode'] != 'direct'
|
||||||
rules['bypassList'] = bypassList = []
|
rules['bypassList'] = bypassList = []
|
||||||
for rule in profile.bypassList
|
for rule in profile.bypassList
|
||||||
if rule.pattern == '<local>'
|
bypassList.push(rule.pattern)
|
||||||
for host in OmegaPac.Conditions.localHosts
|
|
||||||
bypassList.push(host)
|
|
||||||
else
|
|
||||||
bypassList.push(rule.pattern)
|
|
||||||
config['rules'] = rules
|
config['rules'] = rules
|
||||||
return config
|
return config
|
||||||
|
|
||||||
|
@ -122,8 +122,18 @@ module.exports = (oldOptions, i18n) ->
|
|||||||
exampleFixedProfileName = 'Example Profile'
|
exampleFixedProfileName = 'Example Profile'
|
||||||
options[OmegaPac.Profiles.nameAsKey(exampleFixedProfileName)] =
|
options[OmegaPac.Profiles.nameAsKey(exampleFixedProfileName)] =
|
||||||
bypassList: [
|
bypassList: [
|
||||||
pattern: "<local>"
|
{
|
||||||
conditionType: "BypassCondition"
|
pattern: "127.0.0.1"
|
||||||
|
conditionType: "BypassCondition"
|
||||||
|
}
|
||||||
|
{
|
||||||
|
pattern: "::1"
|
||||||
|
conditionType: "BypassCondition"
|
||||||
|
}
|
||||||
|
{
|
||||||
|
pattern: "localhost"
|
||||||
|
conditionType: "BypassCondition"
|
||||||
|
}
|
||||||
]
|
]
|
||||||
profileType: "FixedProfile"
|
profileType: "FixedProfile"
|
||||||
name: exampleFixedProfileName
|
name: exampleFixedProfileName
|
||||||
|
@ -10,8 +10,18 @@ module.exports = ->
|
|||||||
"-downloadInterval": 1440
|
"-downloadInterval": 1440
|
||||||
"+proxy":
|
"+proxy":
|
||||||
bypassList: [
|
bypassList: [
|
||||||
pattern: "<local>"
|
{
|
||||||
conditionType: "BypassCondition"
|
pattern: "127.0.0.1"
|
||||||
|
conditionType: "BypassCondition"
|
||||||
|
}
|
||||||
|
{
|
||||||
|
pattern: "::1"
|
||||||
|
conditionType: "BypassCondition"
|
||||||
|
}
|
||||||
|
{
|
||||||
|
pattern: "localhost"
|
||||||
|
conditionType: "BypassCondition"
|
||||||
|
}
|
||||||
]
|
]
|
||||||
profileType: "FixedProfile"
|
profileType: "FixedProfile"
|
||||||
name: "proxy"
|
name: "proxy"
|
||||||
|
Loading…
Reference in New Issue
Block a user