Skip to content
Closed
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
7 changes: 7 additions & 0 deletions test_testping1.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ def test_is_reachable_invalid_ip_format(self, mock_call):
self.assertFalse(is_reachable('invalid_ip'))
mock_call.assert_not_called()

@patch('testping1.subprocess.call')
def test_is_reachable_ip_length_limit(self, mock_call):
"""Test is_reachable enforces length limit on IP addresses."""
long_ip = "1" * 101
self.assertFalse(is_reachable(long_ip))
mock_call.assert_not_called()

@patch('testping1.subprocess.call')
def test_is_reachable_argument_injection(self, mock_call):
"""Test is_reachable prevents argument injection by rejecting invalid IPs."""
Expand Down
5 changes: 5 additions & 0 deletions testping1.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ def is_reachable(ip, timeout=1):
bool: True if the ping is successful, False otherwise.
"""

# πŸ›‘οΈ Sentinel: Enforce strict string length limits to prevent DoS via ipaddress module
if not isinstance(ip, str) or len(ip) > 100:
logging.error(f"IP address exceeds maximum length or is invalid type")
return False

# πŸ›‘οΈ Sentinel: Validate IP address to prevent argument injection
try:
ip_obj = ipaddress.ip_address(ip)
Expand Down
Loading