vehlo-code-scanner 0.1.4__tar.gz → 0.1.6__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. {vehlo_code_scanner-0.1.4 → vehlo_code_scanner-0.1.6}/.gitignore +2 -1
  2. {vehlo_code_scanner-0.1.4 → vehlo_code_scanner-0.1.6}/PKG-INFO +9 -2
  3. {vehlo_code_scanner-0.1.4 → vehlo_code_scanner-0.1.6}/README.md +7 -0
  4. {vehlo_code_scanner-0.1.4 → vehlo_code_scanner-0.1.6}/pyproject.toml +1 -1
  5. {vehlo_code_scanner-0.1.4 → vehlo_code_scanner-0.1.6}/src/vcs/api/app.py +9 -4
  6. {vehlo_code_scanner-0.1.4 → vehlo_code_scanner-0.1.6}/src/vcs/api/routes/findings.py +8 -5
  7. {vehlo_code_scanner-0.1.4 → vehlo_code_scanner-0.1.6}/src/vcs/api/schemas.py +9 -2
  8. {vehlo_code_scanner-0.1.4 → vehlo_code_scanner-0.1.6}/src/vcs/api/services/ingest.py +30 -3
  9. {vehlo_code_scanner-0.1.4 → vehlo_code_scanner-0.1.6}/src/vcs/client/api.py +3 -0
  10. {vehlo_code_scanner-0.1.4 → vehlo_code_scanner-0.1.6}/src/vcs/models/finding.py +12 -1
  11. {vehlo_code_scanner-0.1.4 → vehlo_code_scanner-0.1.6}/src/vcs/scanner/models.py +28 -3
  12. vehlo_code_scanner-0.1.6/src/vcs/snippets.py +57 -0
  13. {vehlo_code_scanner-0.1.4 → vehlo_code_scanner-0.1.6}/src/vcs/__init__.py +0 -0
  14. {vehlo_code_scanner-0.1.4 → vehlo_code_scanner-0.1.6}/src/vcs/api/__init__.py +0 -0
  15. {vehlo_code_scanner-0.1.4 → vehlo_code_scanner-0.1.6}/src/vcs/api/auth.py +0 -0
  16. {vehlo_code_scanner-0.1.4 → vehlo_code_scanner-0.1.6}/src/vcs/api/deps.py +0 -0
  17. {vehlo_code_scanner-0.1.4 → vehlo_code_scanner-0.1.6}/src/vcs/api/routes/__init__.py +0 -0
  18. {vehlo_code_scanner-0.1.4 → vehlo_code_scanner-0.1.6}/src/vcs/api/routes/analytics.py +0 -0
  19. {vehlo_code_scanner-0.1.4 → vehlo_code_scanner-0.1.6}/src/vcs/api/routes/auth.py +0 -0
  20. {vehlo_code_scanner-0.1.4 → vehlo_code_scanner-0.1.6}/src/vcs/api/routes/groups.py +0 -0
  21. {vehlo_code_scanner-0.1.4 → vehlo_code_scanner-0.1.6}/src/vcs/api/routes/health.py +0 -0
  22. {vehlo_code_scanner-0.1.4 → vehlo_code_scanner-0.1.6}/src/vcs/api/routes/ingest.py +0 -0
  23. {vehlo_code_scanner-0.1.4 → vehlo_code_scanner-0.1.6}/src/vcs/api/routes/overview.py +0 -0
  24. {vehlo_code_scanner-0.1.4 → vehlo_code_scanner-0.1.6}/src/vcs/api/routes/repos.py +0 -0
  25. {vehlo_code_scanner-0.1.4 → vehlo_code_scanner-0.1.6}/src/vcs/api/routes/scans.py +0 -0
  26. {vehlo_code_scanner-0.1.4 → vehlo_code_scanner-0.1.6}/src/vcs/api/routes/tokens.py +0 -0
  27. {vehlo_code_scanner-0.1.4 → vehlo_code_scanner-0.1.6}/src/vcs/api/services/__init__.py +0 -0
  28. {vehlo_code_scanner-0.1.4 → vehlo_code_scanner-0.1.6}/src/vcs/api/services/auto_resolve.py +0 -0
  29. {vehlo_code_scanner-0.1.4 → vehlo_code_scanner-0.1.6}/src/vcs/api/session.py +0 -0
  30. {vehlo_code_scanner-0.1.4 → vehlo_code_scanner-0.1.6}/src/vcs/cli/__init__.py +0 -0
  31. {vehlo_code_scanner-0.1.4 → vehlo_code_scanner-0.1.6}/src/vcs/cli/admin.py +0 -0
  32. {vehlo_code_scanner-0.1.4 → vehlo_code_scanner-0.1.6}/src/vcs/cli/app.py +0 -0
  33. {vehlo_code_scanner-0.1.4 → vehlo_code_scanner-0.1.6}/src/vcs/cli/output.py +0 -0
  34. {vehlo_code_scanner-0.1.4 → vehlo_code_scanner-0.1.6}/src/vcs/cli/scan_command.py +0 -0
  35. {vehlo_code_scanner-0.1.4 → vehlo_code_scanner-0.1.6}/src/vcs/client/__init__.py +0 -0
  36. {vehlo_code_scanner-0.1.4 → vehlo_code_scanner-0.1.6}/src/vcs/config.py +0 -0
  37. {vehlo_code_scanner-0.1.4 → vehlo_code_scanner-0.1.6}/src/vcs/db.py +0 -0
  38. {vehlo_code_scanner-0.1.4 → vehlo_code_scanner-0.1.6}/src/vcs/enums.py +0 -0
  39. {vehlo_code_scanner-0.1.4 → vehlo_code_scanner-0.1.6}/src/vcs/fingerprint.py +0 -0
  40. {vehlo_code_scanner-0.1.4 → vehlo_code_scanner-0.1.6}/src/vcs/models/__init__.py +0 -0
  41. {vehlo_code_scanner-0.1.4 → vehlo_code_scanner-0.1.6}/src/vcs/models/api_token.py +0 -0
  42. {vehlo_code_scanner-0.1.4 → vehlo_code_scanner-0.1.6}/src/vcs/models/base.py +0 -0
  43. {vehlo_code_scanner-0.1.4 → vehlo_code_scanner-0.1.6}/src/vcs/models/finding_history.py +0 -0
  44. {vehlo_code_scanner-0.1.4 → vehlo_code_scanner-0.1.6}/src/vcs/models/group.py +0 -0
  45. {vehlo_code_scanner-0.1.4 → vehlo_code_scanner-0.1.6}/src/vcs/models/organization.py +0 -0
  46. {vehlo_code_scanner-0.1.4 → vehlo_code_scanner-0.1.6}/src/vcs/models/repo.py +0 -0
  47. {vehlo_code_scanner-0.1.4 → vehlo_code_scanner-0.1.6}/src/vcs/models/scan.py +0 -0
  48. {vehlo_code_scanner-0.1.4 → vehlo_code_scanner-0.1.6}/src/vcs/models/user.py +0 -0
  49. {vehlo_code_scanner-0.1.4 → vehlo_code_scanner-0.1.6}/src/vcs/scanner/__init__.py +0 -0
  50. {vehlo_code_scanner-0.1.4 → vehlo_code_scanner-0.1.6}/src/vcs/scanner/parser.py +0 -0
  51. {vehlo_code_scanner-0.1.4 → vehlo_code_scanner-0.1.6}/src/vcs/scanner/runner.py +0 -0
  52. {vehlo_code_scanner-0.1.4 → vehlo_code_scanner-0.1.6}/src/vcs/services/__init__.py +0 -0
  53. {vehlo_code_scanner-0.1.4 → vehlo_code_scanner-0.1.6}/src/vcs/services/provisioning.py +0 -0
  54. {vehlo_code_scanner-0.1.4 → vehlo_code_scanner-0.1.6}/src/vcs/services/tokens.py +0 -0
  55. {vehlo_code_scanner-0.1.4 → vehlo_code_scanner-0.1.6}/src/vcs/storage/__init__.py +0 -0
  56. {vehlo_code_scanner-0.1.4 → vehlo_code_scanner-0.1.6}/src/vcs/storage/memory.py +0 -0
  57. {vehlo_code_scanner-0.1.4 → vehlo_code_scanner-0.1.6}/src/vcs/storage/s3.py +0 -0
  58. {vehlo_code_scanner-0.1.4 → vehlo_code_scanner-0.1.6}/src/vcs/worker/__init__.py +0 -0
  59. {vehlo_code_scanner-0.1.4 → vehlo_code_scanner-0.1.6}/src/vcs/worker/celery_app.py +0 -0
  60. {vehlo_code_scanner-0.1.4 → vehlo_code_scanner-0.1.6}/src/vcs/worker/db.py +0 -0
  61. {vehlo_code_scanner-0.1.4 → vehlo_code_scanner-0.1.6}/src/vcs/worker/tasks.py +0 -0
@@ -49,5 +49,6 @@ dashboard/dist/
49
49
  .ash/
50
50
  .claude-fuel/
51
51
 
52
- # Local Claude context (deployment/operational notes — not public)
52
+ # Local context files (deployment/operational notes — not public)
53
53
  CLAUDE.local.md
54
+ *.local.md
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.4
1
+ Metadata-Version: 2.5
2
2
  Name: vehlo-code-scanner
3
- Version: 0.1.4
3
+ Version: 0.1.6
4
4
  Summary: Multi-tenant security scanning platform wrapping Amazon Security Helper
5
5
  Project-URL: Homepage, https://github.com/Vehlo-CyberSec/vehlo-code-scanner
6
6
  Project-URL: Repository, https://github.com/Vehlo-CyberSec/vehlo-code-scanner
@@ -199,3 +199,10 @@ tests/ # Unit + integration tests
199
199
  pytest
200
200
  pytest --cov=vcs --cov-report=term-missing
201
201
  ```
202
+
203
+ ## Current state
204
+
205
+ Two open issues:
206
+
207
+ - **#7** — review issues tied to specific scans
208
+ - **#11** — `docker-compose.yml` has an uncommitted change to review and land
@@ -171,3 +171,10 @@ tests/ # Unit + integration tests
171
171
  pytest
172
172
  pytest --cov=vcs --cov-report=term-missing
173
173
  ```
174
+
175
+ ## Current state
176
+
177
+ Two open issues:
178
+
179
+ - **#7** — review issues tied to specific scans
180
+ - **#11** — `docker-compose.yml` has an uncommitted change to review and land
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "vehlo-code-scanner"
3
- version = "0.1.4"
3
+ version = "0.1.6"
4
4
  description = "Multi-tenant security scanning platform wrapping Amazon Security Helper"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.12"
@@ -76,7 +76,7 @@ def _mount_dashboard(app: FastAPI) -> None:
76
76
  dist = os.environ.get("VCS_DASHBOARD_DIR")
77
77
  if not dist:
78
78
  return
79
- root = Path(dist)
79
+ root = Path(dist).resolve()
80
80
  index = root / "index.html"
81
81
  if not index.is_file():
82
82
  return
@@ -87,7 +87,12 @@ def _mount_dashboard(app: FastAPI) -> None:
87
87
 
88
88
  @app.get("/{full_path:path}", include_in_schema=False)
89
89
  def spa(full_path: str) -> FileResponse:
90
- candidate = root / full_path
91
- if full_path and candidate.is_file():
92
- return FileResponse(candidate)
90
+ # full_path comes straight from the URL. An absolute value
91
+ # ("////etc/passwd" -> "///etc/passwd") makes ``root / full_path``
92
+ # discard root, and ".." segments (incl. "..%2f") walk out of it, so
93
+ # resolve first and only serve files that stay inside the build.
94
+ if full_path:
95
+ candidate = (root / full_path).resolve()
96
+ if candidate.is_relative_to(root) and candidate.is_file():
97
+ return FileResponse(candidate)
93
98
  return FileResponse(index)
@@ -3,8 +3,8 @@
3
3
  from datetime import datetime, timezone
4
4
  from typing import Optional
5
5
 
6
- from fastapi import APIRouter, Depends, HTTPException
7
- from pydantic import BaseModel
6
+ from fastapi import APIRouter, Depends, HTTPException, Query
7
+ from pydantic import BaseModel, Field
8
8
  from sqlalchemy.orm import Session
9
9
 
10
10
  from vcs.api.deps import get_scoped_db
@@ -20,7 +20,7 @@ router = APIRouter(prefix="/api/v1")
20
20
  class FindingStatusUpdate(BaseModel):
21
21
  """Request body for PATCH /api/v1/findings/{id}."""
22
22
  status: str
23
- note: str | None = None
23
+ note: str | None = Field(default=None, max_length=2_000)
24
24
 
25
25
 
26
26
  ALLOWED_STATUSES = {"open", "resolved", "false_positive", "accepted_risk"}
@@ -38,6 +38,9 @@ def _finding_to_response(finding: Finding) -> FindingResponse:
38
38
  rule_description=finding.rule_description,
39
39
  file_path=finding.file_path,
40
40
  line_number=finding.line_number,
41
+ end_line=finding.end_line,
42
+ code_snippet=finding.code_snippet,
43
+ context_snippet=finding.context_snippet,
41
44
  first_seen_at=finding.first_seen_at.isoformat(),
42
45
  last_seen_at=finding.last_seen_at.isoformat(),
43
46
  resolved_at=finding.resolved_at.isoformat() if finding.resolved_at else None,
@@ -50,8 +53,8 @@ def list_findings(
50
53
  status: Optional[str] = None,
51
54
  scanner: Optional[str] = None,
52
55
  repo_name: Optional[str] = None,
53
- page: int = 1,
54
- per_page: int = 50,
56
+ page: int = Query(default=1, ge=1),
57
+ per_page: int = Query(default=50, ge=1, le=200),
55
58
  db: Session = Depends(get_scoped_db),
56
59
  ) -> FindingListResponse:
57
60
  """List findings with optional filters."""
@@ -2,7 +2,7 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
- from pydantic import BaseModel
5
+ from pydantic import BaseModel, Field
6
6
 
7
7
 
8
8
  class FindingPayload(BaseModel):
@@ -14,6 +14,9 @@ class FindingPayload(BaseModel):
14
14
  rule_description: str
15
15
  file_path: str
16
16
  line_number: int | None = None
17
+ end_line: int | None = None
18
+ code_snippet: str | None = None
19
+ context_snippet: str | None = None
17
20
 
18
21
 
19
22
  class ScanIngestRequest(BaseModel):
@@ -31,7 +34,8 @@ class ScanIngestRequest(BaseModel):
31
34
  finding_count_high: int = 0
32
35
  finding_count_medium: int = 0
33
36
  finding_count_low: int = 0
34
- findings: list[FindingPayload] = []
37
+ # Bounded so one push can't write an unbounded amount of data.
38
+ findings: list[FindingPayload] = Field(default=[], max_length=10_000)
35
39
  raw_results: dict = {}
36
40
 
37
41
 
@@ -58,6 +62,9 @@ class FindingResponse(BaseModel):
58
62
  rule_description: str
59
63
  file_path: str
60
64
  line_number: int | None = None
65
+ end_line: int | None = None
66
+ code_snippet: str | None = None
67
+ context_snippet: str | None = None
61
68
  first_seen_at: str
62
69
  last_seen_at: str
63
70
  resolved_at: str | None = None
@@ -13,7 +13,7 @@ from __future__ import annotations
13
13
 
14
14
  import uuid
15
15
  from dataclasses import dataclass
16
- from datetime import datetime, timezone
16
+ from datetime import UTC, datetime
17
17
 
18
18
  from sqlalchemy.orm import Session
19
19
 
@@ -23,6 +23,7 @@ from vcs.fingerprint import compute_fingerprint
23
23
  from vcs.models.finding import Finding
24
24
  from vcs.models.repo import Repo
25
25
  from vcs.models.scan import Scan
26
+ from vcs.snippets import sanitize_snippets
26
27
 
27
28
 
28
29
  @dataclass
@@ -88,7 +89,7 @@ def create_pending_scan(
88
89
  Attributed to ``group_id`` (the authenticated token's group); there is no
89
90
  hidden default tenant. Findings are processed later by ``finalize_scan``.
90
91
  """
91
- now = datetime.now(timezone.utc)
92
+ now = datetime.now(UTC)
92
93
 
93
94
  repo = _get_or_create_repo(
94
95
  db,
@@ -128,7 +129,7 @@ def finalize_scan(
128
129
 
129
130
  Moves the scan ``pending`` -> ``processing`` -> ``completed``.
130
131
  """
131
- now = datetime.now(timezone.utc)
132
+ now = datetime.now(UTC)
132
133
  scan.status = ScanStatus.PROCESSING
133
134
  db.flush()
134
135
 
@@ -141,6 +142,20 @@ def finalize_scan(
141
142
  fingerprint = compute_fingerprint(f.rule_id, f.file_path, str(repo_id))
142
143
  incoming_fingerprints.add(fingerprint)
143
144
 
145
+ # Authoritative masking/truncation — the CLI applies the same rules
146
+ # at parse time, but pushed payloads cannot be trusted to have.
147
+ code_snippet, context_snippet = sanitize_snippets(
148
+ f.scanner, f.rule_id, f.code_snippet, f.context_snippet
149
+ )
150
+ # Distinguish "no snippet data" (old client, or scanner without
151
+ # snippets) from real values, so an old-client push doesn't wipe
152
+ # previously stored snippets during rollout.
153
+ has_snippet_fields = (
154
+ f.code_snippet is not None
155
+ or f.context_snippet is not None
156
+ or f.end_line is not None
157
+ )
158
+
144
159
  existing = (
145
160
  db.query(Finding)
146
161
  .filter_by(repo_id=repo_id, fingerprint=fingerprint)
@@ -150,6 +165,13 @@ def finalize_scan(
150
165
  if existing:
151
166
  existing.last_seen_scan_id = scan.id
152
167
  existing.last_seen_at = now
168
+ # Refresh location from the latest scan — code (and therefore
169
+ # line numbers and snippets) drifts between scans.
170
+ existing.line_number = f.line_number
171
+ if has_snippet_fields:
172
+ existing.end_line = f.end_line
173
+ existing.code_snippet = code_snippet
174
+ existing.context_snippet = context_snippet
153
175
  if existing.status == FindingStatus.RESOLVED:
154
176
  existing.status = FindingStatus.OPEN
155
177
  existing.resolved_at = None
@@ -167,6 +189,11 @@ def finalize_scan(
167
189
  rule_description=f.rule_description,
168
190
  file_path=f.file_path,
169
191
  line_number=f.line_number,
192
+ end_line=f.end_line if has_snippet_fields else None,
193
+ code_snippet=code_snippet if has_snippet_fields else None,
194
+ context_snippet=(
195
+ context_snippet if has_snippet_fields else None
196
+ ),
170
197
  fingerprint=fingerprint,
171
198
  first_seen_at=now,
172
199
  last_seen_at=now,
@@ -65,6 +65,9 @@ class VCSClient:
65
65
  "rule_description": f.rule_description,
66
66
  "file_path": f.file_path,
67
67
  "line_number": f.line_number,
68
+ "end_line": f.end_line,
69
+ "code_snippet": f.code_snippet,
70
+ "context_snippet": f.context_snippet,
68
71
  }
69
72
  for f in result.findings
70
73
  ],
@@ -3,7 +3,14 @@
3
3
  import uuid
4
4
  from datetime import datetime
5
5
 
6
- from sqlalchemy import DateTime, ForeignKey, Integer, String, UniqueConstraint
6
+ from sqlalchemy import (
7
+ DateTime,
8
+ ForeignKey,
9
+ Integer,
10
+ String,
11
+ Text,
12
+ UniqueConstraint,
13
+ )
7
14
  from sqlalchemy.dialects.postgresql import UUID
8
15
  from sqlalchemy.orm import Mapped, mapped_column, relationship
9
16
 
@@ -52,6 +59,10 @@ class Finding(UUIDMixin, TimestampMixin, Base):
52
59
  )
53
60
  file_path: Mapped[str] = mapped_column(String(1024), nullable=False)
54
61
  line_number: Mapped[int | None] = mapped_column(Integer, nullable=True)
62
+ end_line: Mapped[int | None] = mapped_column(Integer, nullable=True)
63
+ # Already truncated and secret-masked at parse time (scanner/models.py).
64
+ code_snippet: Mapped[str | None] = mapped_column(Text, nullable=True)
65
+ context_snippet: Mapped[str | None] = mapped_column(Text, nullable=True)
55
66
  fingerprint: Mapped[str] = mapped_column(
56
67
  String(255), nullable=False, index=True
57
68
  )
@@ -6,6 +6,7 @@ from dataclasses import dataclass, field
6
6
  from typing import Any
7
7
 
8
8
  from vcs.fingerprint import compute_fingerprint
9
+ from vcs.snippets import sanitize_snippets
9
10
 
10
11
  SARIF_LEVEL_TO_SEVERITY = {
11
12
  "error": "high",
@@ -14,6 +15,10 @@ SARIF_LEVEL_TO_SEVERITY = {
14
15
  "none": "info",
15
16
  }
16
17
 
18
+ def _snippet_text(container: dict[str, Any]) -> str | None:
19
+ text = (container.get("snippet") or {}).get("text")
20
+ return text or None
21
+
17
22
 
18
23
  @dataclass
19
24
  class ParsedFinding:
@@ -25,6 +30,9 @@ class ParsedFinding:
25
30
  rule_description: str
26
31
  file_path: str
27
32
  line_number: int | None
33
+ end_line: int | None = None
34
+ code_snippet: str | None = None
35
+ context_snippet: str | None = None
28
36
 
29
37
  def fingerprint(self, repo_id: str) -> str:
30
38
  """Compute a stable fingerprint for deduplication."""
@@ -39,15 +47,32 @@ class ParsedFinding:
39
47
  location = result.get("locations", [{}])[0]
40
48
  physical = location.get("physicalLocation", {})
41
49
  artifact = physical.get("artifactLocation", {})
42
- region = physical.get("region", {})
50
+ region = physical.get("region", {}) or {}
51
+ context = physical.get("contextRegion") or {}
52
+
53
+ scanner = result.get("properties", {}).get("scanner_name", "unknown")
54
+ rule_id = result.get("ruleId", "unknown")
55
+
56
+ # Mask secret-rule snippets before they leave the scanning machine.
57
+ # The server re-applies the same rules (vcs/snippets.py) — this
58
+ # parse-time pass means the secret never even enters the payload.
59
+ code_snippet, context_snippet = sanitize_snippets(
60
+ scanner,
61
+ rule_id,
62
+ _snippet_text(region),
63
+ _snippet_text(context),
64
+ )
43
65
 
44
66
  return cls(
45
- scanner=result.get("properties", {}).get("scanner_name", "unknown"),
67
+ scanner=scanner,
46
68
  severity=severity,
47
- rule_id=result.get("ruleId", "unknown"),
69
+ rule_id=rule_id,
48
70
  rule_description=result.get("message", {}).get("text", ""),
49
71
  file_path=artifact.get("uri", ""),
50
72
  line_number=region.get("startLine"),
73
+ end_line=region.get("endLine"),
74
+ code_snippet=code_snippet,
75
+ context_snippet=context_snippet,
51
76
  )
52
77
 
53
78
 
@@ -0,0 +1,57 @@
1
+ """Snippet masking and truncation, shared by the CLI parser and ingest.
2
+
3
+ The CLI applies this at parse time so secrets never leave the scanning
4
+ machine inside finding fields — but the server CANNOT trust that: any token
5
+ holder can POST arbitrary payloads. `finalize_scan` therefore re-applies
6
+ the same rules, making the server the authoritative masking layer.
7
+ """
8
+
9
+ from __future__ import annotations
10
+
11
+ SNIPPET_REDACTED = "[snippet redacted: rule detects hardcoded secrets]"
12
+
13
+ # Bound row size; SARIF context regions are occasionally whole files.
14
+ MAX_SNIPPET_CHARS = 1_000
15
+ MAX_CONTEXT_CHARS = 4_000
16
+
17
+ # Scanners that exclusively emit secret findings.
18
+ _SECRET_SCANNERS = frozenset({"detect-secrets", "gitleaks"})
19
+ # bandit's hardcoded-password family.
20
+ _BANDIT_SECRET_RULES = frozenset({"b105", "b106", "b107"})
21
+ # Substring markers for everything else (semgrep generic.secrets.*, checkov
22
+ # CKV_SECRET_*, gitleaks-style rule ids…). Over-masking is the safe failure
23
+ # direction, so the list is deliberately broad.
24
+ _SECRET_RULE_MARKERS = (
25
+ "secret",
26
+ "password",
27
+ "credential",
28
+ "private-key",
29
+ "token",
30
+ "api-key",
31
+ "api_key",
32
+ "apikey",
33
+ )
34
+
35
+
36
+ def is_secret_rule(scanner: str, rule_id: str) -> bool:
37
+ """Whether a finding's snippet would BE the secret it detects."""
38
+ if scanner in _SECRET_SCANNERS:
39
+ return True
40
+ rid = rule_id.lower()
41
+ if rid in _BANDIT_SECRET_RULES:
42
+ return True
43
+ return any(marker in rid for marker in _SECRET_RULE_MARKERS)
44
+
45
+
46
+ def sanitize_snippets(
47
+ scanner: str,
48
+ rule_id: str,
49
+ code_snippet: str | None,
50
+ context_snippet: str | None,
51
+ ) -> tuple[str | None, str | None]:
52
+ """Mask secret-rule snippets and truncate the rest. Idempotent."""
53
+ if is_secret_rule(scanner, rule_id):
54
+ return SNIPPET_REDACTED, None
55
+ code = code_snippet[:MAX_SNIPPET_CHARS] if code_snippet else None
56
+ context = context_snippet[:MAX_CONTEXT_CHARS] if context_snippet else None
57
+ return code, context