Skip to content

Commit 8281d3b

Browse files
Double check network location during updates.
1 parent c7bb17a commit 8281d3b

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

tuf/interposition/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,8 @@ def interpose():
190190

191191

192192
def open_url( instancemethod ):
193-
"""Decorate a caller instance method of the form
194-
instancemethod( self, url,... ) with me in order to give it to TUF."""
193+
"""Decorate an instance method of the form
194+
instancemethod( self, url,... ) with me in order to pass it to TUF."""
195195

196196
@functools.wraps( instancemethod )
197197
def wrapper( self, *args, **kwargs ):

tuf/interposition/updater.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,26 @@ def get_updater( url ):
135135
parsed_url = urlparse.urlparse( url )
136136
hostname = parsed_url.hostname
137137
port = parsed_url.port or 80
138+
netloc = parsed_url.netloc
139+
network_location = \
140+
"{hostname}:{port}".format( hostname = hostname, port = port )
141+
142+
# Sometimes parsed_url.netloc does not have a port (e.g. 80),
143+
# so we do a double check.
144+
network_locations = set( ( netloc, network_location ) )
145+
138146
updater = Updater.__updaters.get( hostname )
139147

140148
# Ensure that the updater is meant for this (hostname, port).
141-
if updater is not None and updater.configuration.port == port:
142-
# Raises an exception in case we do not recognize how to
143-
# transform this URL for TUF. In that case, there will be no
144-
# updater for this URL.
145-
target_filepath = updater.get_target_filepath( url )
149+
if updater is not None:
150+
if updater.configuration.network_location in network_locations:
151+
# Raises an exception in case we do not recognize how to
152+
# transform this URL for TUF. In that case, there will be no
153+
# updater for this URL.
154+
target_filepath = updater.get_target_filepath( url )
155+
else:
156+
# Same hostname, but different (not user-specified) port.
157+
updater = None
146158
except:
147159
Logger.warn( WARNING_MESSAGE.format( url = url ) )
148160
updater = None

0 commit comments

Comments
 (0)