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
5 changes: 5 additions & 0 deletions .jules/sentinel.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,8 @@
**Vulnerability:** The application used `shutil.which("ping") or "ping"`. If `ping` was not found in the system `PATH`, it fell back to executing the relative string `"ping"`. This could allow arbitrary code execution or local privilege escalation if run from a directory containing a malicious executable named `ping`.
**Learning:** Never fallback to relative command names when a system binary is expected. If a required binary is missing from the system path, the application should fail securely rather than attempting a risky, unverified local execution.
**Prevention:** Remove fallback logic for critical system commands. Use `shutil.which()` and raise an exception (e.g., `RuntimeError`) if the expected binary is `None`.

## 2024-04-03 - Thread crash via OverflowError in float to int cast
**Vulnerability:** Application crashes and potential DoS due to `OverflowError` when untrusted input containing `Infinity` or `NaN` is parsed (e.g., from JSON) and subsequently converted to an integer using `int()`.
**Learning:** Python's `int()` function raises `OverflowError` instead of `ValueError` or `TypeError` when it encounters infinite float values. If not explicitly caught, this can crash worker thread pools processing untrusted user input.
**Prevention:** When converting untrusted input to integers using `int()`, explicitly catch `OverflowError` alongside `ValueError` and `TypeError` to ensure graceful handling.
5 changes: 5 additions & 0 deletions test_testping1.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ def test_is_reachable_invalid_timeout(self, mock_call):
# πŸ›‘οΈ Sentinel: Test resource exhaustion prevention
self.assertFalse(is_reachable('192.168.1.1', timeout=101))
mock_call.assert_not_called()
# πŸ›‘οΈ Sentinel: Test float infinity prevention (OverflowError)
self.assertFalse(is_reachable('192.168.1.1', timeout=float('inf')))
mock_call.assert_not_called()
self.assertFalse(is_reachable('192.168.1.1', timeout=float('-inf')))
mock_call.assert_not_called()

@patch('testping1.subprocess.call')
def test_is_reachable_timeout_too_long(self, mock_call):
Expand Down
5 changes: 4 additions & 1 deletion testping1.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ def is_reachable(ip, timeout=1):
timeout_val = int(timeout)
if timeout_val <= 0 or timeout_val > 100:
raise ValueError("Timeout must be a positive integer <= 100")
except (ValueError, TypeError):
except (ValueError, TypeError, OverflowError):
# πŸ›‘οΈ Sentinel: Catch OverflowError alongside ValueError/TypeError
# Inputs originating from JSON can include Infinity (parsed as float)
# which raises OverflowError when cast to int and crashes threads.
# πŸ›‘οΈ Sentinel: Sanitize log input to prevent CRLF/Log Injection
logging.error(f"Invalid timeout value: {repr(timeout)}")
return False
Expand Down
Loading