Skip to content

Commit 425ff3d

Browse files
committed
Fix issues (cont.)
1 parent aeec1a9 commit 425ff3d

File tree

4 files changed

+17
-11
lines changed

4 files changed

+17
-11
lines changed

app/utils/monitoring.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,10 @@ async def get_system_metrics() -> Dict[str, Any]:
184184
}
185185

186186
except Exception as e:
187-
logger.error("Failed to get system metrics", error=str(e))
187+
logger.error("Failed to get system metrics", error=str(e), exception_type=type(e).__name__)
188188
return {
189189
"timestamp": time.time(),
190-
"error": str(e),
190+
"metrics_error": True,
191191
"application": resource_usage.copy(),
192192
}
193193

@@ -267,8 +267,8 @@ async def check_dependency_health(cache_ttl: int = 10) -> Dict[str, Any]:
267267
cache_healthy = False
268268

269269
if isinstance(metrics, Exception):
270-
logger.error("System metrics exception", error=str(metrics))
271-
metrics = {"error": str(metrics)}
270+
logger.error("System metrics exception", error=str(metrics), exception_type=type(metrics).__name__)
271+
metrics = {"metrics_error": True}
272272

273273
total_duration = time.time() - start_time
274274

@@ -294,10 +294,10 @@ async def check_dependency_health(cache_ttl: int = 10) -> Dict[str, Any]:
294294
return result
295295

296296
except Exception as e:
297-
logger.error("Dependency health check failed", error=str(e))
297+
logger.error("Dependency health check failed", error=str(e), exception_type=type(e).__name__, stack_info=True)
298298
return {
299299
"overall_healthy": False,
300-
"error": str(e),
300+
"metrics_error": True,
301301
"check_duration_seconds": time.time() - start_time,
302302
}
303303

tests/unit/pre_audit/reporting/test_input_validator.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ def test_validate_string_blocks_xss_patterns(self, validator):
6868
"expression(alert('XSS'))",
6969
"vbscript:msgbox('XSS')",
7070
"data:text/html,<script>alert('XSS')</script>",
71+
# Test malformed end tags that browsers accept (CodeQL py/bad-tag-filter fix)
72+
"<script>alert('XSS')</script foo='bar'>", # Malformed end tag with attributes
73+
"<script>alert('XSS')</script\tfoo>", # Malformed with tab and attribute
74+
"<script>alert('XSS')</script\nbar>", # Malformed with newline
75+
"<style>body{background:url(evil.com)}</style attr='test'>", # Malformed style end tag
7176
]
7277

7378
for pattern in xss_patterns:

tests/unit/utils/test_monitoring.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,9 @@ async def test_get_system_metrics_exception(self) -> None:
207207
metrics = await get_system_metrics()
208208

209209
assert "timestamp" in metrics
210-
assert "error" in metrics
210+
assert "metrics_error" in metrics
211211
assert "application" in metrics
212-
assert metrics["error"] == "psutil error"
212+
assert metrics["metrics_error"] is True # Generic error indicator, no detail exposure
213213

214214

215215
class TestConnectionCounting:

tools/pre_audit/reporting/security/input_validator.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,16 @@ class InputValidator:
4242
# Dangerous patterns to block - comprehensive security patterns
4343
DANGEROUS_PATTERNS = [
4444
# Block script tags with comprehensive patterns to prevent XSS
45-
re.compile(r"<\s*script[^>]*>.*?<\s*/\s*script\s*>", re.IGNORECASE | re.DOTALL),
45+
# Fixed: Handle malformed end tags that browsers accept
46+
re.compile(r"<\s*script[^>]*>.*?<\s*/\s*script[^>]*>", re.IGNORECASE | re.DOTALL),
4647
re.compile(r"<\s*script[^>]*>", re.IGNORECASE),
47-
re.compile(r"</\s*script\s*>", re.IGNORECASE),
48+
re.compile(r"</\s*script[^>]*>", re.IGNORECASE), # Handles </script foo="bar">
4849
# Block other dangerous tags
4950
re.compile(r"<\s*iframe[^>]*>", re.IGNORECASE),
5051
re.compile(r"<\s*object[^>]*>", re.IGNORECASE),
5152
re.compile(r"<\s*embed[^>]*>", re.IGNORECASE),
5253
re.compile(r"<\s*link[^>]*>", re.IGNORECASE),
53-
re.compile(r"<\s*style[^>]*>.*?</\s*style\s*>", re.IGNORECASE | re.DOTALL),
54+
re.compile(r"<\s*style[^>]*>.*?</\s*style[^>]*>", re.IGNORECASE | re.DOTALL), # Also fix style tag
5455
# Block protocol handlers and event handlers
5556
re.compile(r"javascript:", re.IGNORECASE),
5657
re.compile(r"on\w+\s*=", re.IGNORECASE), # onclick, onerror, etc.

0 commit comments

Comments
 (0)