diff --git a/.bandit b/.bandit new file mode 100644 index 0000000..18fd68f --- /dev/null +++ b/.bandit @@ -0,0 +1,5 @@ +# Traditional SAST config (bandit). Run: bandit -r src -c .bandit +exclude_dirs: [".venv", "tests", "node_modules", "dist", "build", "secfoo-design-system"] + +# git clone via subprocess — argv list, no shell, URL validated upstream +skips: ["B404", "B603", "B607"] diff --git a/pyproject.toml b/pyproject.toml index 890113b..f403244 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -25,12 +25,10 @@ classifiers = [ ] dependencies = [ "typer>=0.12", - # typer 0.12.x's rich help renderer and Enum-option handling call into - # click.Parameter internals (make_metavar(), Choice default validation) - # that click 8.2 changed the signature/strictness of -- pinning below - # 8.2 keeps `secfoo --help` and any Enum-typed --option with a default - # from crashing. Safe to drop once typer is upgraded past this pair. - "click<8.2", + # click 8.3.3+ fixes PYSEC-2026-2132 (click.edit command injection). + # typer 0.12+ works with click 8.3.x — the old <8.2 pin was for a typer + # 0.12.x / click 8.2 API mismatch that no longer applies at current versions. + "click>=8.3.3,<9", "rich>=13.0", "fastapi>=0.110", "uvicorn[standard]>=0.29", @@ -48,7 +46,7 @@ dependencies = [ ] [project.optional-dependencies] -dev = ["pytest>=8.0", "httpx>=0.27", "ruff>=0.4"] +dev = ["pytest>=8.0", "httpx>=0.27", "ruff>=0.4", "bandit>=1.8", "pip-audit>=2.7"] build = ["pyinstaller>=6.0"] [project.scripts] diff --git a/src/secfoo/agents/gemini.py b/src/secfoo/agents/gemini.py index 71b8d76..d4a0604 100644 --- a/src/secfoo/agents/gemini.py +++ b/src/secfoo/agents/gemini.py @@ -28,7 +28,10 @@ def build_command(self, prompt: str, *, workdir: Path) -> list[str]: # auto-approved write access, and we'd rather a blocked tool call # show up as a lower-quality report than silently grant it edit # rights. - return [self.binary, "-p", prompt, "--output-format", "json"] + # --skip-trust: secfoo always runs headless against arbitrary + # targets (cloned repos, user paths) — without this, Gemini CLI + # exits immediately in non-interactive mode on an untrusted cwd. + return [self.binary, "-p", prompt, "--output-format", "json", "--skip-trust"] def extract_report(self, stdout: str) -> str: try: diff --git a/src/secfoo/cli.py b/src/secfoo/cli.py index e76559b..effb5c2 100644 --- a/src/secfoo/cli.py +++ b/src/secfoo/cli.py @@ -1051,7 +1051,7 @@ def vendor_mermaid( console.print(f"Downloading {url} ...") try: - with urllib.request.urlopen(url, timeout=60) as response: # noqa: S310 -- pinned https CDN + with urllib.request.urlopen(url, timeout=60) as response: # noqa: S310 # nosec B310 -- pinned https CDN URL for mermaid bundle payload = response.read() except (urllib.error.URLError, TimeoutError) as exc: err_console.print(f"[red]Download failed:[/] {exc}") diff --git a/src/secfoo/cloud.py b/src/secfoo/cloud.py index 12ceeb4..2bcb563 100644 --- a/src/secfoo/cloud.py +++ b/src/secfoo/cloud.py @@ -90,7 +90,7 @@ def _request(url: str, *, api_key: str, payload: dict | None = None) -> dict: headers["Content-Type"] = "application/json" request = urllib.request.Request(url, data=data, headers=headers) try: - with urllib.request.urlopen(request, timeout=REQUEST_TIMEOUT_SECONDS) as response: # noqa: S310 -- portal_url is user-configured, same trust model as MCP server URLs in settings.py + with urllib.request.urlopen(request, timeout=REQUEST_TIMEOUT_SECONDS) as response: # noqa: S310 # nosec B310 -- user-configured portal URL, same trust as MCP settings return json.loads(response.read().decode("utf-8")) except urllib.error.HTTPError as exc: detail = exc.read().decode("utf-8", errors="replace") diff --git a/src/secfoo/osv.py b/src/secfoo/osv.py index a712d84..a6876f9 100644 --- a/src/secfoo/osv.py +++ b/src/secfoo/osv.py @@ -77,7 +77,7 @@ def query_osv(ecosystem: str, package: str, version: str) -> list[dict]: OSV_API_URL, data=body, headers={"Content-Type": "application/json"}, method="POST" ) try: - with urllib.request.urlopen(request, timeout=REQUEST_TIMEOUT_SECONDS) as response: # noqa: S310 -- fixed, hardcoded public API URL, not user input + with urllib.request.urlopen(request, timeout=REQUEST_TIMEOUT_SECONDS) as response: # noqa: S310 # nosec B310 -- hardcoded public OSV.dev API URL data = json.loads(response.read().decode("utf-8")) except urllib.error.HTTPError as exc: detail = exc.read().decode("utf-8", errors="replace") diff --git a/src/secfoo/storage/repository.py b/src/secfoo/storage/repository.py index 48b1a7f..914be64 100644 --- a/src/secfoo/storage/repository.py +++ b/src/secfoo/storage/repository.py @@ -596,7 +596,7 @@ def update_assessment(self, assessment_id: int, **fields: object) -> None: raise ValueError(f"Unknown assessment field(s): {sorted(unknown)}") set_clause = ", ".join(f"{k} = ?" for k in fields) + ", updated_at = ?" params = [*fields.values(), _now(), assessment_id] - self._conn.execute(f"UPDATE assessments SET {set_clause} WHERE id = ?", params) + self._conn.execute(f"UPDATE assessments SET {set_clause} WHERE id = ?", params) # nosec B608 -- column names from _ASSESSMENT_UPDATE_FIELDS whitelist above self._conn.commit() def get_assessment(self, assessment_id: int) -> AssessmentRecord | None: @@ -782,7 +782,7 @@ def update_exception(self, exception_id: int, **fields: object) -> None: raise ValueError(f"Unknown exception field(s): {sorted(unknown)}") set_clause = ", ".join(f"{k} = ?" for k in fields) + ", updated_at = ?" params = [*fields.values(), _now(), exception_id] - self._conn.execute(f"UPDATE exceptions SET {set_clause} WHERE id = ?", params) + self._conn.execute(f"UPDATE exceptions SET {set_clause} WHERE id = ?", params) # nosec B608 -- column names from allowed whitelist above self._conn.commit() def get_exception(self, exception_id: int) -> ExceptionRecord | None: @@ -1070,7 +1070,7 @@ def update_threat_acceptance(self, acceptance_id: int, **fields: object) -> None raise ValueError(f"Unknown threat acceptance field(s): {sorted(unknown)}") set_clause = ", ".join(f"{k} = ?" for k in fields) + ", updated_at = ?" params = [*fields.values(), _now(), acceptance_id] - self._conn.execute(f"UPDATE threat_acceptances SET {set_clause} WHERE id = ?", params) + self._conn.execute(f"UPDATE threat_acceptances SET {set_clause} WHERE id = ?", params) # nosec B608 -- column names from allowed whitelist above self._conn.commit() def delete_threat_acceptance(self, acceptance_id: int) -> None: @@ -1179,7 +1179,7 @@ def close_stale_sast_findings( placeholders = ",".join("?" * len(seen_fingerprints)) query = ( "UPDATE sast_findings SET status = 'closed', closed_in_run_id = ?, closed_at = ? " - f"WHERE project_id = ? AND status = 'open' AND fingerprint NOT IN ({placeholders})" + f"WHERE project_id = ? AND status = 'open' AND fingerprint NOT IN ({placeholders})" # nosec B608 -- placeholders are ? binds, not user SQL ) params: list[object] = [run_id, closed_at, project_id, *seen_fingerprints] else: diff --git a/src/secfoo/targets/github.py b/src/secfoo/targets/github.py index 261316c..1910c3c 100644 --- a/src/secfoo/targets/github.py +++ b/src/secfoo/targets/github.py @@ -27,7 +27,14 @@ def clone_shallow(url: str, *, timeout: int = 600) -> Iterator[Path]: timeout=timeout, ) except subprocess.CalledProcessError as exc: - raise TargetResolutionError(f"git clone failed for {url}: {exc.stderr}") from exc + stderr = exc.stderr or "" + if "No space left on device" in stderr: + raise TargetResolutionError( + f"git clone failed for {url}: disk full — free space on your " + f"system drive (or clone the repo locally and pass the directory " + f"as --target instead of a GitHub URL). Original error: {stderr}" + ) from exc + raise TargetResolutionError(f"git clone failed for {url}: {stderr}") from exc except subprocess.TimeoutExpired as exc: raise TargetResolutionError(f"git clone timed out after {timeout}s for {url}") from exc yield tmp_dir diff --git a/tests/test_agents/test_gemini.py b/tests/test_agents/test_gemini.py index 60ba550..b8aa4ed 100644 --- a/tests/test_agents/test_gemini.py +++ b/tests/test_agents/test_gemini.py @@ -9,6 +9,7 @@ def test_build_command_no_yolo_flag(tmp_path): adapter = GeminiAdapter() cmd = adapter.build_command("hi", workdir=tmp_path) assert "--yolo" not in cmd + assert "--skip-trust" in cmd assert "--output-format" in cmd assert "json" in cmd diff --git a/tests/test_targets/test_github.py b/tests/test_targets/test_github.py index ad1dd3a..caaac50 100644 --- a/tests/test_targets/test_github.py +++ b/tests/test_targets/test_github.py @@ -52,3 +52,18 @@ def fake_run(cmd, **kwargs): with pytest.raises(TargetResolutionError): with clone_shallow("https://github.com/org/nope"): pass + + +def test_clone_shallow_surfaces_disk_full_with_actionable_message(monkeypatch): + def fake_run(cmd, **kwargs): + raise subprocess.CalledProcessError( + returncode=128, + cmd=cmd, + stderr="error: unable to create file foo.ts: No space left on device", + ) + + monkeypatch.setattr("secfoo.targets.github.subprocess.run", fake_run) + + with pytest.raises(TargetResolutionError, match="disk full"): + with clone_shallow("https://github.com/org/repo"): + pass