File tree Expand file tree Collapse file tree 1 file changed +6
-1
lines changed Expand file tree Collapse file tree 1 file changed +6
-1
lines changed Original file line number Diff line number Diff line change 83
83
# Regex to check if the file etag IS a valid sha256
84
84
REGEX_SHA256 = re .compile (r"^[0-9a-f]{64}$" )
85
85
86
+ # Redirect allowlist for use by relative redirect wrapper
87
+ # Example: HF_DOWNLOAD_REDIRECT_ALLOWLIST=opendns.com
88
+ REDIRECT_ALLOWLIST = os .environ .get ("HF_DOWNLOAD_REDIRECT_ALLOWLIST" , "" ).split ("," )
89
+ REDIRECT_ALLOWLIST = [domain for domain in REDIRECT_ALLOWLIST if len (domain ) > 0 ]
90
+
86
91
_are_symlinks_supported_in_dir : Dict [str , bool ] = {}
87
92
88
93
@@ -294,7 +299,7 @@ def _request_wrapper(
294
299
# This is useful in case of a renamed repository.
295
300
if 300 <= response .status_code <= 399 :
296
301
parsed_target = urlparse (response .headers ["Location" ])
297
- if parsed_target .netloc == "" :
302
+ if parsed_target .netloc == "" or any ( parsed_target . netloc . endswith ( domain ) for domain in REDIRECT_ALLOWLIST ) :
298
303
# This means it is a relative 'location' headers, as allowed by RFC 7231.
299
304
# (e.g. '/path/to/resource' instead of 'http://domain.tld/path/to/resource')
300
305
# We want to follow this relative redirect !
You can’t perform that action at this time.
0 commit comments