Skip to content

Personal AI, On Personal Devices

Python

ci: add security SAST workflow (bandit, pip-audit, semgrep) (#1006)

clawdovil-agent-bv0efac3e8e744
diff --git a/.github/workflows/security-sast.yml b/.github/workflows/security-sast.yml
new file mode 100644
index 00000000..91bccd42
--- /dev/null
+++ b/.github/workflows/security-sast.yml
@@ -0,0 +1,100 @@
+name: security-sast
+
+# Static application-security testing for Python code and locked dependencies.
+on:
+ push:
+ branches: [main]
+ pull_request:
+ workflow_dispatch:
+
+permissions:
+ contents: read
+
+jobs:
+ bandit:
+ name: Bandit (high severity and confidence)
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v7
+ - uses: actions/setup-python@v7
+ with:
+ python-version: "3.12"
+ - run: python -m pip install "bandit==1.9.4"
+ # Existing intentional shell execution is annotated at the call sites.
+ # -lll -iii gates only HIGH severity and HIGH confidence findings.
+ - name: Reject high/high findings
+ run: bandit -r src/openjarvis -lll -iii -f screen
+
+ pip-audit:
+ name: pip-audit (${{ matrix.profile }}, Linux/Python 3.12)
+ runs-on: ubuntu-latest
+ strategy:
+ fail-fast: false
+ matrix:
+ profile: [core, server, desktop, voice, inference-cloud, inference-litellm]
+ steps:
+ - uses: actions/checkout@v7
+ - uses: actions/setup-python@v7
+ with:
+ python-version: "3.12"
+ - uses: astral-sh/[email protected]
+ with:
+ version: "0.12.19"
+ - run: python -m pip install "pip-audit==2.10.1"
+ # uv.lock contains all optional dependencies. Export each supported
+ # installed profile with hashes so pip-audit checks its exact versions.
+ - name: Export locked dependencies
+ env:
+ PROFILE: ${{ matrix.profile }}
+ run: |
+ if [ "$PROFILE" = core ]; then
+ uv export --locked --no-dev --no-emit-project --no-header > requirements.txt
+ else
+ uv export --locked --no-dev --no-emit-project --no-header --extra "$PROFILE" > requirements.txt
+ fi
+ test -s requirements.txt
+ # Existing advisories remain report-only. A failed export or incomplete
+ # audit still fails the job, and the JSON report is retained for review.
+ - name: Audit pinned dependencies
+ run: |
+ set +e
+ pip-audit -r requirements.txt --disable-pip --require-hashes --strict \
+ --progress-spinner off --format json --output pip-audit.json
+ audit_exit=$?
+ set -e
+ if [ ! -s pip-audit.json ]; then
+ echo "pip-audit did not produce a report (exit $audit_exit)" >&2
+ exit 1
+ fi
+ python - <<'PY'
+ import json
+
+ with open("pip-audit.json", encoding="utf-8") as report_file:
+ report = json.load(report_file)
+ dependencies = report["dependencies"]
+ if not dependencies:
+ raise SystemExit("pip-audit reported no dependencies")
+ vulnerable = sum(bool(dependency["vulns"]) for dependency in dependencies)
+ print(f"Audited {len(dependencies)} packages; {vulnerable} have known advisories")
+ PY
+ if [ "$audit_exit" -ne 0 ] && [ "$audit_exit" -ne 1 ]; then
+ exit "$audit_exit"
+ fi
+ - name: Upload audit report
+ if: always()
+ uses: actions/upload-artifact@v7
+ with:
+ name: pip-audit-${{ matrix.profile }}
+ path: pip-audit.json
+ if-no-files-found: ignore
+
+ semgrep:
+ name: Semgrep (rules)
+ runs-on: ubuntu-latest
+ container:
+ image: semgrep/semgrep
+ steps:
+ - uses: actions/checkout@v7
+ - name: Run Semgrep (audit ruleset)
+ continue-on-error: true
+ run: semgrep --config=p/python --config=p/security-audit --error --skip-unknown-extensions src/openjarvis
diff --git a/src/openjarvis/connectors/whatsapp.py b/src/openjarvis/connectors/whatsapp.py
index 0494de08..3280a2bc 100644
--- a/src/openjarvis/connectors/whatsapp.py
+++ b/src/openjarvis/connectors/whatsapp.py
@@ -277,7 +277,8 @@ class WhatsAppConnector(BaseConnector):
return None
content = "\n".join(lines)
- doc_id = f"whatsapp:{hashlib.sha1(path.name.encode()).hexdigest()[:16]}"
+ path_hash = hashlib.sha1(path.name.encode(), usedforsecurity=False)
+ doc_id = f"whatsapp:{path_hash.hexdigest()[:16]}"
return Document(
doc_id=doc_id,
diff --git a/src/openjarvis/evals/scorers/lifelong_agent_scorer.py b/src/openjarvis/evals/scorers/lifelong_agent_scorer.py
index ba1f53e4..c95273d6 100644
--- a/src/openjarvis/evals/scorers/lifelong_agent_scorer.py
+++ b/src/openjarvis/evals/scorers/lifelong_agent_scorer.py
@@ -479,9 +479,11 @@ def _hash_table_state(rows: List[List[Any]]) -> str:
row_hashes = []
for row in rows:
concat = ",".join(str(v) if v is not None else "NULL" for v in row)
- row_hashes.append(hashlib.md5(concat.encode()).hexdigest())
+ row_hashes.append(
+ hashlib.md5(concat.encode(), usedforsecurity=False).hexdigest()
+ )
row_hashes.sort()
- return hashlib.md5("".join(row_hashes).encode()).hexdigest()
+ return hashlib.md5("".join(row_hashes).encode(), usedforsecurity=False).hexdigest()
def _compare_table_states(
diff --git a/src/openjarvis/security/subprocess_sandbox.py b/src/openjarvis/security/subprocess_sandbox.py
index 9ed6ff52..58e35fb6 100644
--- a/src/openjarvis/security/subprocess_sandbox.py
+++ b/src/openjarvis/security/subprocess_sandbox.py
@@ -95,7 +95,8 @@ def run_sandboxed(
try:
proc = subprocess.Popen(
command,
- shell=True,
+ # This API explicitly runs caller-provided shell commands.
+ shell=True, # nosec B602
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
diff --git a/src/openjarvis/tools/shell_exec.py b/src/openjarvis/tools/shell_exec.py
index 513fb169..44bca542 100644
--- a/src/openjarvis/tools/shell_exec.py
+++ b/src/openjarvis/tools/shell_exec.py
@@ -178,7 +178,8 @@ class ShellExecTool(BaseTool):
try:
result = subprocess.run(
command,
- shell=True,
+ # This tool executes shell commands after its confirmation gate.
+ shell=True, # nosec B602
capture_output=True,
text=True,
timeout=timeout,