Skip to content

Commit e7ae82a

Browse files
authored
chore(detectors): Use new group type for Query Injection Issues (#94540)
this pr replaces the group type that is being created by the query injection detectors. the previous group type contains issues that we don't want to show users as we have updated the detectors since, and creating a new group type is the most straightforward way to achieve that.
1 parent d716511 commit e7ae82a

File tree

6 files changed

+34
-16
lines changed

6 files changed

+34
-16
lines changed

src/sentry/api/endpoints/project_performance_issue_settings.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
from sentry.api.bases.project import ProjectEndpoint, ProjectSettingPermission
1212
from sentry.auth.superuser import superuser_has_permission
1313
from sentry.issues.grouptype import (
14-
DBQueryInjectionVulnerabilityGroupType,
1514
GroupType,
1615
PerformanceConsecutiveDBQueriesGroupType,
1716
PerformanceConsecutiveHTTPQueriesGroupType,
@@ -26,6 +25,7 @@
2625
PerformanceSlowDBQueryGroupType,
2726
PerformanceUncompressedAssetsGroupType,
2827
ProfileFunctionRegressionType,
28+
QueryInjectionVulnerabilityGroupType,
2929
)
3030
from sentry.performance_issues.performance_detection import get_merged_settings
3131

@@ -91,7 +91,7 @@ class ConfigurableThresholds(Enum):
9191
ConfigurableThresholds.HTTP_OVERHEAD.value: PerformanceHTTPOverheadGroupType,
9292
InternalProjectOptions.TRANSACTION_DURATION_REGRESSION.value: PerformanceP95EndpointRegressionGroupType,
9393
InternalProjectOptions.FUNCTION_DURATION_REGRESSION.value: ProfileFunctionRegressionType,
94-
ConfigurableThresholds.DB_QUERY_INJECTION.value: DBQueryInjectionVulnerabilityGroupType,
94+
ConfigurableThresholds.DB_QUERY_INJECTION.value: QueryInjectionVulnerabilityGroupType,
9595
}
9696
"""
9797
A mapping of the management settings to the group type that the detector spawns.

src/sentry/issues/grouptype.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,7 @@ class PerformanceStreamedSpansGroupTypeExperimental(GroupType):
502502
default_priority = PriorityLevel.LOW
503503

504504

505+
# Experimental Group Type for Query Injection Vulnerability
505506
@dataclass(frozen=True)
506507
class DBQueryInjectionVulnerabilityGroupType(GroupType):
507508
type_id = 1020
@@ -515,6 +516,19 @@ class DBQueryInjectionVulnerabilityGroupType(GroupType):
515516
default_priority = PriorityLevel.MEDIUM
516517

517518

519+
@dataclass(frozen=True)
520+
class QueryInjectionVulnerabilityGroupType(PerformanceGroupTypeDefaults, GroupType):
521+
type_id = 1021
522+
slug = "query_injection_vulnerability"
523+
description = "Potential Query Injection Vulnerability"
524+
category = GroupCategory.PERFORMANCE.value
525+
category_v2 = GroupCategory.DB_QUERY.value
526+
enable_auto_resolve = False
527+
enable_escalation_detection = False
528+
noise_config = NoiseConfig(ignore_limit=5)
529+
default_priority = PriorityLevel.MEDIUM
530+
531+
518532
# 2000 was ProfileBlockingFunctionMainThreadType
519533
@dataclass(frozen=True)
520534
class ProfileFileIOGroupType(GroupType):

src/sentry/performance_issues/detectors/query_injection_detector.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import hashlib
44
from typing import Any
55

6-
from sentry.issues.grouptype import DBQueryInjectionVulnerabilityGroupType
6+
from sentry.issues.grouptype import QueryInjectionVulnerabilityGroupType
77
from sentry.issues.issue_occurrence import IssueEvidence
88
from sentry.models.organization import Organization
99
from sentry.models.project import Project
@@ -85,7 +85,7 @@ def visit_span(self, span: Span) -> None:
8585
)
8686

8787
self.stored_problems[fingerprint] = PerformanceProblem(
88-
type=DBQueryInjectionVulnerabilityGroupType,
88+
type=QueryInjectionVulnerabilityGroupType,
8989
fingerprint=fingerprint,
9090
op=op,
9191
desc=issue_description[:MAX_EVIDENCE_VALUE_LENGTH],
@@ -138,4 +138,4 @@ def is_span_eligible(cls, span: Span) -> bool:
138138
def _fingerprint(self, description: str) -> str:
139139
signature = description.encode("utf-8")
140140
full_fingerprint = hashlib.sha1(signature).hexdigest()
141-
return f"1-{DBQueryInjectionVulnerabilityGroupType.type_id}-{full_fingerprint}"
141+
return f"1-{QueryInjectionVulnerabilityGroupType.type_id}-{full_fingerprint}"

src/sentry/performance_issues/detectors/sql_injection_detector.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from collections.abc import Sequence
66
from typing import Any
77

8-
from sentry.issues.grouptype import DBQueryInjectionVulnerabilityGroupType
8+
from sentry.issues.grouptype import QueryInjectionVulnerabilityGroupType
99
from sentry.issues.issue_occurrence import IssueEvidence
1010
from sentry.models.organization import Organization
1111
from sentry.models.project import Project
@@ -164,7 +164,7 @@ def visit_span(self, span: Span) -> None:
164164
)
165165

166166
self.stored_problems[fingerprint] = PerformanceProblem(
167-
type=DBQueryInjectionVulnerabilityGroupType,
167+
type=QueryInjectionVulnerabilityGroupType,
168168
fingerprint=fingerprint,
169169
op=op,
170170
desc=issue_description[:MAX_EVIDENCE_VALUE_LENGTH],
@@ -233,4 +233,4 @@ def is_event_eligible(cls, event: dict[str, Any], project: Project | None = None
233233
def _fingerprint(self, description: str) -> str:
234234
signature = description.encode("utf-8")
235235
full_fingerprint = hashlib.sha1(signature).hexdigest()
236-
return f"1-{DBQueryInjectionVulnerabilityGroupType.type_id}-{full_fingerprint}"
236+
return f"1-{QueryInjectionVulnerabilityGroupType.type_id}-{full_fingerprint}"

tests/sentry/performance_issues/test_query_injection_detector.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import pytest
66

7-
from sentry.issues.grouptype import DBQueryInjectionVulnerabilityGroupType
7+
from sentry.issues.grouptype import QueryInjectionVulnerabilityGroupType
88
from sentry.performance_issues.detectors.query_injection_detector import QueryInjectionDetector
99
from sentry.performance_issues.performance_detection import (
1010
get_detection_settings,
@@ -32,8 +32,9 @@ def test_query_injection_detection_in_query_params(self):
3232
problems = self.find_problems(injection_event)
3333
assert len(problems) == 1
3434
problem = problems[0]
35-
assert problem.type == DBQueryInjectionVulnerabilityGroupType
36-
assert problem.fingerprint == "1-1020-1c333b3c472df81fde8a61cdfae24c86676bd582"
35+
36+
assert problem.type == QueryInjectionVulnerabilityGroupType
37+
assert problem.fingerprint == "1-1021-1c333b3c472df81fde8a61cdfae24c86676bd582"
3738
assert problem.op == "db"
3839
assert (
3940
problem.desc

tests/sentry/performance_issues/test_sql_injection_detector.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import pytest
66

7-
from sentry.issues.grouptype import DBQueryInjectionVulnerabilityGroupType
7+
from sentry.issues.grouptype import QueryInjectionVulnerabilityGroupType
88
from sentry.performance_issues.detectors.sql_injection_detector import SQLInjectionDetector
99
from sentry.performance_issues.performance_detection import (
1010
get_detection_settings,
@@ -32,8 +32,9 @@ def test_sql_injection_detection_in_query_params(self):
3232
problems = self.find_problems(injection_event)
3333
assert len(problems) == 1
3434
problem = problems[0]
35-
assert problem.type == DBQueryInjectionVulnerabilityGroupType
36-
assert problem.fingerprint == "1-1020-20e736601b897f6698ef6bca5082d27f5fa765e4"
35+
36+
assert problem.type == QueryInjectionVulnerabilityGroupType
37+
assert problem.fingerprint == "1-1021-20e736601b897f6698ef6bca5082d27f5fa765e4"
3738
assert problem.op == "db"
3839
assert (
3940
problem.desc
@@ -49,8 +50,10 @@ def test_sql_injection_detection_in_body(self):
4950
problems = self.find_problems(injection_event)
5051
assert len(problems) == 1
5152
problem = problems[0]
52-
assert problem.type == DBQueryInjectionVulnerabilityGroupType
53-
assert problem.fingerprint == "1-1020-da364c9819759827b8401d54783b2462683d461a"
53+
54+
assert problem.type == QueryInjectionVulnerabilityGroupType
55+
assert problem.fingerprint == "1-1021-da364c9819759827b8401d54783b2462683d461a"
56+
5457
assert problem.op == "db"
5558
assert (
5659
problem.desc

0 commit comments

Comments
 (0)