Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .bandit
Original file line number Diff line number Diff line change
@@ -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"]
12 changes: 5 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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]
Expand Down
5 changes: 4 additions & 1 deletion src/secfoo/agents/gemini.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion src/secfoo/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down
2 changes: 1 addition & 1 deletion src/secfoo/cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion src/secfoo/osv.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
8 changes: 4 additions & 4 deletions src/secfoo/storage/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
9 changes: 8 additions & 1 deletion src/secfoo/targets/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tests/test_agents/test_gemini.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
15 changes: 15 additions & 0 deletions tests/test_targets/test_github.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading