-
Notifications
You must be signed in to change notification settings - Fork 0
fix(vuln): semgrep config auto→p/default (metrics-off 비호환 해소) #66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -51,7 +51,10 @@ class ScanVulnerabilityRequest: | |
| output_path: str | Path | ||
| sarif_output_path: str | Path | None = None | ||
| semgrep_binary: str = "semgrep" | ||
| semgrep_config: str = "auto" | ||
| # NOT "auto": the runner forces --metrics=off for privacy, and semgrep | ||
| # rejects `auto` config when metrics are off ("Cannot create auto config | ||
| # when metrics are off"). A pinned registry pack runs without telemetry. | ||
| semgrep_config: str = "p/default" | ||
| timeout_seconds: int = 300 | ||
| path_policy: str = "redacted" | ||
|
|
||
|
|
@@ -143,7 +146,9 @@ class CatalogScanRequest: | |
| scan_run_id: str | ||
| cache_root: str | Path | None = None | ||
| semgrep_binary: str = "semgrep" | ||
| semgrep_config: str = "auto" | ||
| # "p/default", not "auto": auto is incompatible with the runner's forced | ||
| # --metrics=off (see ScanVulnerabilityRequest). | ||
| semgrep_config: str = "p/default" | ||
| timeout_seconds: int = 1800 | ||
| path_policy: str = "redacted" | ||
|
Comment on lines
+149
to
153
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 동일하게 # "p/default", not "auto": auto is incompatible with the runner's forced
# --metrics=off (see ScanVulnerabilityRequest).
semgrep_config: str = "p/default"
timeout_seconds: int = 1800
path_policy: str = "redacted"
def __post_init__(self) -> None:
if self.semgrep_config == "auto":
raise ValueError(
"semgrep_config='auto' is incompatible with --metrics=off"
) |
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,45 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| """Regression guard: semgrep `auto` config is incompatible with `--metrics=off`. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| The Semgrep-compatible runner forces ``--metrics=off`` for privacy, and semgrep | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| rejects the ``auto`` config when metrics are off ("Cannot create auto config when | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| metrics are off"). So the vuln-scan defaults must NOT be ``auto`` — a live catalog | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| scan would fail every tick otherwise. This test pins that coupling. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from __future__ import annotations | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from pathlib import Path | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from security_scanner.runtime.vulnerability_scan import ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CatalogScanRequest, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ScanVulnerabilityRequest, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from security_scanner.scanners.semgrep_compatible import SemgrepCompatibleRunner | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| _UNIT = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Path(__file__).resolve().parents[1] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| / "deploy" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| / "systemd" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| / "user" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| / "security-scanner-personal-vuln-scan.service" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def test_runner_forces_metrics_off(): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cmd = SemgrepCompatibleRunner().build_command(Path("."), sarif_path="o.sarif") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert "--metrics=off" in cmd | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def test_scan_request_default_config_is_not_auto(): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert ScanVulnerabilityRequest(root=".", output_path="o").semgrep_config != "auto" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def test_catalog_request_default_config_is_not_auto(): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| req = CatalogScanRequest(artifact_dir="a", scan_run_id="r") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert req.semgrep_config != "auto" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+33
to
+39
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def test_vuln_scan_unit_does_not_use_auto_config(): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| text = _UNIT.read_text(encoding="utf-8") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert "--semgrep-config" in text | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert "--semgrep-config auto" not in text | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SemgrepCompatibleRunner는 항상
--metrics=off를 강제하므로,semgrep_config가"auto"로 설정되면 무조건 실패하게 됩니다. 사용자가 CLI나 API를 통해 명시적으로"auto"를 전달할 경우, 불필요한 서브프로세스 실행 없이 즉시 에러를 발생시키도록__post_init__에서 방어적 유효성 검증(defensive validation)을 추가하는 것이 좋습니다.