Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 9 additions & 21 deletions src/rockstor/system/tailscale.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,32 +104,20 @@ def extract_param(param: str) -> str:


def validate_ts_hostname(config: dict) -> dict:
"""Ensure hostname is alphanumeric with hyphens only
No special character (including hyphens) is allowed as a custom hostname.

"hostname": "rock-dev_@#~!$%^&*()+123"
"""Applies a set of rules to validate hostname
Keep each character in hostname only if:
- not a special character
- not a unicode character
- is hyphen
- replace underscore with hyphen

"hostname": "rock-dev_@#~!$%^&*()+123ü"
should return
"hostname": "rock-dev-123"
"""
if "hostname" in config:
config["hostname"] = re.sub("_", "-", config["hostname"])
to_exclude = [
"@",
"#",
"~",
"!",
"$",
"%",
"^",
"&",
"*",
"(",
")",
"+",
]
config["hostname"] = "".join(
c for c in config["hostname"] if not c in to_exclude
)
config["hostname"] = re.sub("[^a-zA-Z0-9-]", "", config["hostname"])
return config


Expand Down
4 changes: 2 additions & 2 deletions src/rockstor/system/tests/test_tailscale.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ def test_tailscale_extract_param(self):
)

def test_tailscale_validate_hostname(self):
"""Ensure alphanumeric and no underscore in hostname"""
"""Ensure alphanumeric, no underscore, and no unicode in hostname"""
test_config = {
"accept_routes": "yes",
"advertise_exit_node": "yes",
"advertise_routes": "192.168.1.0/24",
"exit_node": "100.1.1.1",
"exit_node_allow_lan_access": "true",
"hostname": "rock-dev_@#~!$%^&*()+123",
"hostname": "rock-dev_@#~!$%^&*()+123ü",
"reset": "yes",
"ssh": "yes",
"custom_config": "--shields-up\n--accept-risk=all",
Expand Down