Skip to content

Commit

Permalink
sanitse hostname URL with regex validation
Browse files Browse the repository at this point in the history
  • Loading branch information
ThorstenHeck committed Nov 25, 2024
1 parent a02bac4 commit 612fc7b
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions plugins/module_utils/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
__metaclass__ = type

import json
import re
from urllib.error import HTTPError, URLError
from urllib.parse import ParseResult, urlencode, urlparse

Expand Down Expand Up @@ -50,18 +51,17 @@ def __init__(
timeout: Optional[Any] = None,
validate_certs: Optional[Any] = None,
) -> None:
if not (host or "").startswith(("https://", "http://")):
raise EDAHTTPError(
f"Invalid instance host value: '{host}'. "
"Value must start with 'https://' or 'http://'"
)

self.host = host
self.username = username
self.password = password
self.timeout = timeout
self.validate_certs = validate_certs

# Perform some basic validation
if not re.match("^https{0,1}://", self.host):
self.host = f"https://{0}"

Check warning on line 63 in plugins/module_utils/client.py

View check run for this annotation

Codecov / codecov/patch

plugins/module_utils/client.py#L63

Added line #L63 was not covered by tests

# Try to parse the hostname as a url
try:
self.url = urlparse(self.host)
Expand Down

0 comments on commit 612fc7b

Please sign in to comment.