Skip to content

Commit

Permalink
fix: Add forgotten loopback check. #982
Browse files Browse the repository at this point in the history
  • Loading branch information
mturoci committed Jan 20, 2023
1 parent 1adc040 commit 61a9055
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions py/h2o_wave/core.py
Expand Up @@ -675,7 +675,7 @@ def upload(self, files: List[str]) -> List[str]:

# If we know the path of waved and running app on the same machine,
# we can simply copy the files instead of making an HTTP request.
if not skip_local_upload and waved_dir and data_dir:
if _is_loopback_address() and not skip_local_upload and waved_dir and data_dir:
try:
is_windows = 'Windows' in platform.system()
cp_command = 'xcopy' if is_windows else 'cp'
Expand Down Expand Up @@ -735,7 +735,7 @@ def upload_dir(self, directory: str) -> str:

# If we know the path of waved and running app on the same machine,
# we can simply copy the files instead of making an HTTP request.
if not skip_local_upload and waved_dir and data_dir:
if _is_loopback_address() and not skip_local_upload and waved_dir and data_dir:
try:
uuid = str(uuid4())
dst = os.path.join(waved_dir, data_dir, 'f', uuid)
Expand Down Expand Up @@ -911,7 +911,7 @@ async def upload_dir(self, directory: str) -> str:

# If we know the path of waved and running app on the same machine,
# we can simply copy the files instead of making an HTTP request.
if not skip_local_upload and waved_dir and data_dir:
if _is_loopback_address() and not skip_local_upload and waved_dir and data_dir:
try:
uuid = str(uuid4())
dst = os.path.join(waved_dir, data_dir, 'f', uuid)
Expand Down Expand Up @@ -959,7 +959,7 @@ async def upload(self, files: List[str]) -> List[str]:

# If we know the path of waved and running app on the same machine,
# we can simply copy the files instead of making an HTTP request.
if not skip_local_upload and waved_dir and data_dir:
if _is_loopback_address() and not skip_local_upload and waved_dir and data_dir:
try:
tasks = []
for f in files:
Expand Down Expand Up @@ -1137,9 +1137,9 @@ def pack(data: Any) -> str:
return 'data:' + marshal(_dump(data))


def _is_loopback_address(address: str) -> bool:
def _is_loopback_address() -> bool:
try:
hostname = urlparse(address).hostname
hostname = urlparse(_config.hub_address).hostname
return ipaddress.ip_address(hostname).is_loopback
except ValueError:
return False

0 comments on commit 61a9055

Please sign in to comment.