Skip to content

Commit 050425a

Browse files
committed
fix: skip ignored SAST findings in blocking logic
Signed-off-by: lelia <2418071+lelia@users.noreply.github.com>
1 parent f68ab29 commit 050425a

2 files changed

Lines changed: 25 additions & 5 deletions

File tree

socket_basics/core/connector/normalizer.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from typing import Any, Dict, List, Tuple
1212
import logging
1313
import os
14+
from ..config import alert_matches_sast_ignore_override
1415

1516
logger = logging.getLogger(__name__)
1617

@@ -38,6 +39,17 @@ def _normalize_alert(a: Dict[str, Any], connector: Any | None = None, default_ge
3839
a['severity'] = a['severity'].lower()
3940
# Minimal normalization: lowercase severity and ensure action exists
4041

42+
# Honor local SAST ignore overrides before deriving actions from severity.
43+
try:
44+
if connector and hasattr(connector, 'config') and hasattr(connector.config, 'get_sast_ignore_overrides'):
45+
for override in connector.config.get_sast_ignore_overrides():
46+
if alert_matches_sast_ignore_override(a, override):
47+
logger.debug("Alert matched sast_ignore_overrides entry %s", override)
48+
a['action'] = 'ignore'
49+
return a
50+
except Exception:
51+
logger.debug('Failed to check SAST ignore overrides for alert', exc_info=True)
52+
4153
# Check if this alert's rule is in the disabled rules list for any language
4254
# If so, set action to 'ignore' regardless of severity
4355
try:

socket_basics/socket_basics.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,18 @@
5454
logger = logging.getLogger(__name__)
5555

5656

57+
def count_blocking_alerts(results: Dict[str, Any]) -> int:
58+
"""Count alerts that should fail the run."""
59+
blocking_alerts = 0
60+
for comp in results.get('components', []):
61+
for alert in comp.get('alerts', []):
62+
if (alert.get('action') or '').strip().lower() == 'ignore':
63+
continue
64+
if alert.get('severity') in ['high', 'critical']:
65+
blocking_alerts += 1
66+
return blocking_alerts
67+
68+
5769
class SecurityScanner:
5870
"""Main security scanning orchestrator using dynamic connectors"""
5971

@@ -456,11 +468,7 @@ def main():
456468
logger.info(f"Total alerts: {total_alerts}")
457469

458470
# Exit with non-zero code if high/critical issues found
459-
high_critical_alerts = 0
460-
for comp in results.get('components', []):
461-
for alert in comp.get('alerts', []):
462-
if alert.get('severity') in ['high', 'critical']:
463-
high_critical_alerts += 1
471+
high_critical_alerts = count_blocking_alerts(results)
464472

465473
exit_code = 1 if high_critical_alerts > 0 else 0
466474
if high_critical_alerts > 0:

0 commit comments

Comments
 (0)