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 8383# Regex to check if the file etag IS a valid sha256
8484REGEX_SHA256 = re .compile (r"^[0-9a-f]{64}$" )
8585
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+
8691_are_symlinks_supported_in_dir : Dict [str , bool ] = {}
8792
8893
@@ -294,7 +299,7 @@ def _request_wrapper(
294299 # This is useful in case of a renamed repository.
295300 if 300 <= response .status_code <= 399 :
296301 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 ) :
298303 # This means it is a relative 'location' headers, as allowed by RFC 7231.
299304 # (e.g. '/path/to/resource' instead of 'http://domain.tld/path/to/resource')
300305 # We want to follow this relative redirect !
You can’t perform that action at this time.
0 commit comments