Skip to content

Commit

Permalink
firewall: _validate_port() replaces colon with dash for port ranges
Browse files Browse the repository at this point in the history
  • Loading branch information
Salamandar committed Feb 25, 2025
1 parent 513112e commit b29d9ba
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/firewall.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,12 @@ def list(self, protocol: str, forwarded: bool = False) -> list[int]:

@staticmethod
def _validate_port(protocol: str, port: int | str) -> tuple[str, int | str]:
if isinstance(port, str) and "-" not in port:
port = int(port)
if isinstance(port, str):
# iptables used ":" and app packages might still do
port = port.replace(":", "-")
# Convert to int if it's not a range
if "-" not in port:
port = int(port)
if protocol not in ["tcp", "udp"]:
raise ValueError(f"protocol should be tcp or udp, not {protocol}")
return protocol, port
Expand Down

0 comments on commit b29d9ba

Please sign in to comment.