Skip to content

Commit

Permalink
[worker] fix registry domain validation
Browse files Browse the repository at this point in the history
  • Loading branch information
yashgorana committed Feb 5, 2024
1 parent 4bb02b8 commit 9bfd515
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions packages/syft/src/syft/service/worker/image_registry.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# stdlib
import re
from urllib.parse import urlparse

# third party
Expand All @@ -10,6 +11,8 @@
from ...types.syft_object import SyftObject
from ...types.uid import UID

REGX_DOMAIN = re.compile(r"^(localhost|([a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*))(\:\d{1,5})?$")


@serializable()
class SyftImageRegistry(SyftObject):
Expand All @@ -26,15 +29,19 @@ class SyftImageRegistry(SyftObject):

@validator("url")
def validate_url(cls, val: str):
if val.startswith("http") or "://" in val:
raise ValueError("Registry URL must be a valid RFC 3986 URI")
if not val:
raise ValueError("Invalid Registry URL. Must not be empty")

if not bool(re.match(REGX_DOMAIN, val)):
raise ValueError("Invalid Registry URL. Must be a valid domain.")

return val

@classmethod
def from_url(cls, full_str: str):
# this is only for urlparse
if "://" not in full_str:
full_str = f"http://{full_str}"

parsed = urlparse(full_str)

# netloc includes the host & port, so local dev should work as expected
Expand Down

0 comments on commit 9bfd515

Please sign in to comment.