@@ -70,7 +70,8 @@ def safe_download(url, required_length):
70
70
71
71
<Arguments>
72
72
url:
73
- A URL string that represents the location of the file.
73
+ A URL string that represents the location of the file. The URI scheme
74
+ component must be one of 'tuf.conf.SUPPORTED_URI_SCHEMES'.
74
75
75
76
required_length:
76
77
An integer value representing the length of the file. This is an exact
@@ -92,6 +93,25 @@ def safe_download(url, required_length):
92
93
A 'tuf.util.TempFile' file-like object that points to the contents of 'url'.
93
94
"""
94
95
96
+ # Do all of the arguments have the appropriate format?
97
+ # Raise 'tuf.FormatError' if there is a mismatch.
98
+ tuf .formats .URL_SCHEMA .check_match (url )
99
+ tuf .formats .LENGTH_SCHEMA .check_match (required_length )
100
+
101
+ # Ensure 'url' specifies one of the URI schemes in
102
+ # 'tuf.conf.SUPPORTED_URI_SCHEMES'. Be default, ['http', 'https'] is
103
+ # supported. If the URI scheme of 'url' is empty or "file", files on the
104
+ # local system can be accessed. Unexpected files may be accessed by
105
+ # compromised metadata (unlikely to happen if targets.json metadata is signed
106
+ # with offline keys).
107
+ parsed_url = six .moves .urllib .parse .urlparse (url )
108
+
109
+ if parsed_url .scheme not in tuf .conf .SUPPORTED_URI_SCHEMES :
110
+ message = \
111
+ repr (url ) + ' specifies an unsupported URI scheme. Supported ' + \
112
+ ' URI Schemes: ' + repr (tuf .conf .SUPPORTED_URI_SCHEMES )
113
+ raise tuf .FormatError (message )
114
+
95
115
return _download_file (url , required_length , STRICT_REQUIRED_LENGTH = True )
96
116
97
117
@@ -114,7 +134,8 @@ def unsafe_download(url, required_length):
114
134
115
135
<Arguments>
116
136
url:
117
- A URL string that represents the location of the file.
137
+ A URL string that represents the location of the file. The URI scheme
138
+ component must be one of 'tuf.conf.SUPPORTED_URI_SCHEMES'.
118
139
119
140
required_length:
120
141
An integer value representing the length of the file. This is an upper
@@ -136,6 +157,25 @@ def unsafe_download(url, required_length):
136
157
A 'tuf.util.TempFile' file-like object that points to the contents of 'url'.
137
158
"""
138
159
160
+ # Do all of the arguments have the appropriate format?
161
+ # Raise 'tuf.FormatError' if there is a mismatch.
162
+ tuf .formats .URL_SCHEMA .check_match (url )
163
+ tuf .formats .LENGTH_SCHEMA .check_match (required_length )
164
+
165
+ # Ensure 'url' specifies one of the URI schemes in
166
+ # 'tuf.conf.SUPPORTED_URI_SCHEMES'. Be default, ['http', 'https'] is
167
+ # supported. If the URI scheme of 'url' is empty or "file", files on the
168
+ # local system can be accessed. Unexpected files may be accessed by
169
+ # compromised metadata (unlikely to happen if targets.json metadata is signed
170
+ # with offline keys).
171
+ parsed_url = six .moves .urllib .parse .urlparse (url )
172
+
173
+ if parsed_url .scheme not in tuf .conf .SUPPORTED_URI_SCHEMES :
174
+ message = \
175
+ repr (url ) + ' specifies an unsupported URI scheme. Supported ' + \
176
+ ' URI Schemes: ' + repr (tuf .conf .SUPPORTED_URI_SCHEMES )
177
+ raise tuf .FormatError (message )
178
+
139
179
return _download_file (url , required_length , STRICT_REQUIRED_LENGTH = False )
140
180
141
181
0 commit comments