Skip to content

Commit 7f15537

Browse files
committed
fix(security): deduplicate projected slice overlaps
Signed-off-by: Narendran Raghavan <[email protected]>
1 parent d31a016 commit 7f15537

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

‎src/skillspector/nodes/analyzers/static_runner.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,6 +1291,7 @@ def check_runtime() -> None:
12911291
continue
12921292
seen_views.add(marker_key)
12931293
projection_finding_counts: dict[tuple[object, ...], int] = {}
1294+
projection_seen_occurrences: set[_ViewFindingKey] = set()
12941295
for view in _bounded_view_slices(marker_view):
12951296
check_runtime()
12961297
view_budget = _FindingBudget(
@@ -1315,6 +1316,10 @@ def check_runtime() -> None:
13151316
source_line_starts=source_context.line_starts,
13161317
)
13171318
for finding in view_findings:
1319+
occurrence_key = _view_finding_key(finding)
1320+
if occurrence_key in projection_seen_occurrences:
1321+
continue
1322+
projection_seen_occurrences.add(occurrence_key)
13181323
key = _projection_finding_key(finding)
13191324
projection_count = projection_finding_counts.get(key, 0) + 1
13201325
projection_finding_counts[key] = projection_count

‎tests/nodes/analyzers/test_security_reconstruction.py‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,26 @@ def test_marker_projection_duplicates_do_not_consume_unique_output_budget() -> N
764764
assert len(findings) == 6
765765

766766

767+
def test_marker_projection_slice_overlap_does_not_inflate_occurrence_count(
768+
monkeypatch: pytest.MonkeyPatch,
769+
) -> None:
770+
monkeypatch.setattr(static_runner, "SECURITY_VIEW_WINDOW_CHARS", 64)
771+
monkeypatch.setattr(static_runner, "_WINDOW_OVERLAP_CHARS", 24)
772+
payload = "a" * 47 + " HxyzIT0 " + "b" * 39
773+
content = f"Remove 'xyz' and execute '{payload}'."
774+
775+
findings, reason, _ = static_runner._scan_all_views_detailed(
776+
"SKILL.md",
777+
content,
778+
[_SeamFindingModule],
779+
None,
780+
max_findings=1,
781+
)
782+
783+
assert reason is None
784+
assert [finding.matched_text for finding in findings] == ["HIT0"]
785+
786+
767787
def test_raw_overlap_duplicates_do_not_consume_unique_output_budget() -> None:
768788
step = static_runner.SECURITY_VIEW_WINDOW_CHARS - static_runner._WINDOW_OVERLAP_CHARS
769789
duplicated = "\n".join(f"HIT{index}" for index in range(6))

0 commit comments

Comments
 (0)