Skip to content

Commit a2624aa

Browse files
committed
docs: Add NOSONAR comments for security hotspots
- cleaner.py: Document regex is safe from ReDoS - scanner.py: Document temp directory scanning is intentional
1 parent 25933b0 commit a2624aa

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

cortex/cleanup/cleaner.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ def _extract_size_from_line(self, line: str) -> int:
116116
Returns:
117117
int: Size in bytes.
118118
"""
119-
# Match patterns like "50.5 MB" or "512 KB"
119+
# NOSONAR: This regex has no nested quantifiers and cannot cause ReDoS.
120+
# Input is apt-get output, not user-controlled.
120121
match = re.search(r'([\d.]+)\s*(KB|MB|GB)', line, re.IGNORECASE)
121122
if match:
122123
value = float(match.group(1))

cortex/cleanup/scanner.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ class CleanupScanner:
3535
def __init__(self):
3636
self.apt_cache_dir = Path("/var/cache/apt/archives")
3737
self.log_dir = Path("/var/log")
38+
# NOSONAR: Intentionally scanning public directories for cleanup purposes.
39+
# This is read-only scanning, not writing sensitive data.
3840
self.temp_dirs = [Path("/tmp"), Path.home() / ".cache"]
3941

4042
def scan_all(self) -> List[ScanResult]:
@@ -153,6 +155,7 @@ def _extract_size(self, stdout: str) -> int:
153155
"""
154156
for line in stdout.splitlines():
155157
if "disk space will be freed" in line:
158+
# NOSONAR: Simple regex without nested quantifiers, input is apt-get output
156159
match = re.search(r'([\d.]+)\s*(KB|MB|GB)', line, re.IGNORECASE)
157160
if match:
158161
value = float(match.group(1))

0 commit comments

Comments
 (0)