Skip to content
Merged
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
39 changes: 34 additions & 5 deletions core/remote_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@

from __future__ import annotations

import ipaddress
import logging
import platform
import re
Expand Down Expand Up @@ -176,12 +177,40 @@ def execute_remote_winrm(
# ── Dispatch ──────────────────────────────────────────────────────────────

target_host = str(target_host or "").strip()
if not _HOST_RE.fullmatch(target_host):
return ExecutionResult(
command=command,
error="Invalid target_host: must be a valid hostname, IPv4, or IPv6 literal.",
duration_ms=0,
normalized_host = ""
try:
# Canonicalize literal IPs (IPv4 / IPv6)
normalized_host = str(ipaddress.ip_address(target_host))
except ValueError:
# Validate hostname labels (RFC 1123-style)
if (
not target_host
or len(target_host) > 253
or target_host.endswith(".")
or not _HOST_RE.fullmatch(target_host)
):
return ExecutionResult(
command=command,
error="Invalid target_host: must be a valid hostname, IPv4, or IPv6 literal.",
duration_ms=0,
)
labels = target_host.split(".")
label_ok = all(
1 <= len(lbl) <= 63
and lbl[0].isalnum()
and lbl[-1].isalnum()
and all(ch.isalnum() or ch == "-" for ch in lbl)
for lbl in labels
)
if not label_ok:
return ExecutionResult(
command=command,
error="Invalid target_host: must be a valid hostname, IPv4, or IPv6 literal.",
duration_ms=0,
)
normalized_host = target_host

target_host = normalized_host

system = platform.system().lower()
if system == "windows":
Expand Down
Loading