[Security hardening] Add automated security audit workflow
Summary
- Add a dedicated Security Audit workflow for dependency and static-analysis checks.
- Audit committed hashed requirements on push, pull request, and manual dispatch so ordinary CI stays deterministic.
- Verify committed audit requirements are refreshed when dependency inputs change, while keeping live dependency resolution for the scheduled audit across the supported Python and OS matrix.
- Run Bandit for high-severity findings with a scoped baseline for the accepted shell-step B602 finding.
- Pin all repository GitHub Actions to full commit SHAs.
- Harden extension, preset, integration, and workflow downloads with bounded reads, strict HTTPS redirects, optional sha256 verification, bounded ZIP extraction, and source-path traversal guards.
Security context
This creates a repeatable CI baseline for dependency advisories and high-severity static-analysis issues while preserving a scheduled live-resolution signal for newly published dependency problems. It also closes similar supply-chain and archive-handling gaps found during follow-up review.
Closes #2438
Validation
- git diff --check
- uvx ruff check on all changed Python surfaces and tests
- uv run python -m pytest tests/test_download_security.py tests/test_extensions.py tests/test_presets.py tests/integrations/test_integration_catalog.py tests/test_security_workflow.py tests/test_upgrade.py -q
- uv run python -m pytest -q
- uv pip compile pyproject.toml --extra test --universal --generate-hashes --quiet --no-header --output-file
, compared with .github/security-audit-requirements.txt - uvx --from pip-audit==2.10.0 pip-audit --disable-pip --require-hashes -r .github/security-audit-requirements.txt --progress-spinner off
- uvx --from bandit==1.9.4 bandit -r src -lll --baseline .github/bandit-baseline.json
Addressed the Copilot feedback in the latest push:
- Dependency auditing now exports the locked runtime +
testextra dependency set withuv export --extra test --frozen --no-emit-project, then audits the generated requirements file. pip-auditand Bandit are pinned viauvx --from(pip-audit==2.10.0,bandit==1.9.4).- Removed the global Bandit
--skip B602; the existing shell execution call sites now use targeted# nosec B602suppressions with local context. - Added
CONTRIBUTING.mdsecurity-check commands so contributors can reproduce the workflow locally.
Local validation:
uv export --quiet --extra test --frozen --format requirements.txt --no-emit-project --output-file /tmp/spec-kit-audit-requirements.txt
uvx --from pip-audit==2.10.0 pip-audit -r /tmp/spec-kit-audit-requirements.txt --progress-spinner off
uvx --from bandit==1.9.4 bandit -r src -lll
git diff --check
Results: pip-audit reported no known vulnerabilities, Bandit reported no issues, and git diff --check passed.
Added automated regression coverage for the security workflow in tests/test_security_workflow.py.
The new tests statically verify that:
- dependency auditing exports the locked runtime +
testextra requirements before runningpip-audit; pip-auditand Bandit remain pinned viauvx --from;- Bandit does not use a global
--skip B602; CONTRIBUTING.mddocuments the same security commands.
Validation after this commit:
uv run python -m pytest tests/test_security_workflow.py -q
uv export --quiet --extra test --frozen --format requirements.txt --no-emit-project --output-file /tmp/spec-kit-audit-requirements.txt
uvx --from pip-audit==2.10.0 pip-audit -r /tmp/spec-kit-audit-requirements.txt --progress-spinner off
uvx --from bandit==1.9.4 bandit -r src -lll
git diff --check
All passed locally.
Please address Copilot feedback. If not applicable, please explain why. Note the shell step should indeed be ignored
Addressed the follow-up review in e1e8051:
- Removed
--frozenfrom the dependency export because this repo intentionally does not commituv.lock; the workflow and contributor docs now use the same clean-checkout-safe command. - Replaced source-level
# nosec B602suppressions with a CI-level Bandit baseline at.github/bandit-baseline.json. - Kept that baseline scoped to exactly one accepted finding:
B602inShellStep, matching the maintainer note that the shell step should be ignored. - Hardened the generic
run_commandhelper soshell=Trueis rejected instead of suppressed, which removes the similar non-shell-step B602 sink entirely. - Expanded
tests/test_security_workflow.pyto catch these regressions: no lockfile flags, pinned tools, no global--skip B602, one-entry Bandit baseline, no source# nosec B602, docs in sync, andrun_command(shell=True)rejection.
Validation:
uv export --quiet --extra test --format requirements.txt --no-emit-project --output-file /tmp/spec-kit-audit-requirements.txt
uvx --from pip-audit==2.10.0 pip-audit -r /tmp/spec-kit-audit-requirements.txt --progress-spinner off
uvx --from bandit==1.9.4 bandit -r src -lll --baseline .github/bandit-baseline.json
uv run python -m pytest tests/test_security_workflow.py tests/test_workflows.py -q
uvx ruff check src/
git diff --check
I also verified the uv export command in a temporary clean directory without uv.lock; it succeeds before running the audit.
One more small cleanup after re-review: pushed 6f1da27 to use uv pip compile pyproject.toml --extra test for the audit requirements instead of uv export.
Reason: it still audits the runtime + test extra dependency set, but it avoids both requiring and generating a project uv.lock, which makes the CI and CONTRIBUTING.md command cleaner for this repo.
Revalidated locally:
uv pip compile pyproject.toml --extra test --quiet --output-file /tmp/spec-kit-audit-requirements.txt
uvx --from pip-audit==2.10.0 pip-audit -r /tmp/spec-kit-audit-requirements.txt --progress-spinner off
uvx --from bandit==1.9.4 bandit -r src -lll --baseline .github/bandit-baseline.json
uv run python -m pytest tests/test_security_workflow.py -q
git diff --check
All passed.
Please address Copilot feedback
Addressed the latest Copilot review in 129d19e:
- Dependency audit now runs on the supported OS/Python matrix:
ubuntu-latestandwindows-latestacross Python3.11,3.12, and3.13. - The requirements output path in CI now uses
${{ runner.temp }}, and the contributor docs use a relativespec-kit-audit-requirements.txtpath instead of/tmp, so the commands are Windows-compatible. - The security workflow regression test now verifies GitHub Actions are pinned to full 40-character commit SHAs.
- The Bandit suppression guard now catches any
# nosecform, not only the exact# nosec B602spelling. - The dependency audit now compiles hashed requirements and runs
pip-audit --disable-pip --require-hashes, avoiding a second pip resolution step.
Validation:
uv run python -m pytest tests/test_security_workflow.py -q
uv pip compile pyproject.toml --extra test --python-version 3.11 --generate-hashes --quiet --output-file /tmp/spec-kit-audit-py311.txt
uv pip compile pyproject.toml --extra test --python-version 3.12 --generate-hashes --quiet --output-file /tmp/spec-kit-audit-py312.txt
uv pip compile pyproject.toml --extra test --python-version 3.13 --generate-hashes --quiet --output-file /tmp/spec-kit-audit-py313.txt
uvx --from pip-audit==2.10.0 pip-audit --disable-pip --require-hashes -r /tmp/spec-kit-audit-py311.txt --progress-spinner off
uvx --from pip-audit==2.10.0 pip-audit --disable-pip --require-hashes -r /tmp/spec-kit-audit-py312.txt --progress-spinner off
uvx --from pip-audit==2.10.0 pip-audit --disable-pip --require-hashes -r /tmp/spec-kit-audit-py313.txt --progress-spinner off
uvx --from bandit==1.9.4 bandit -r src -lll --baseline .github/bandit-baseline.json
git diff --check
All passed locally.
Addressed the latest Copilot review round in commit aa02062:
- Push/PR/manual dependency audits now use committed hashed requirements at
.github/security-audit-requirements.txtfor deterministic CI. - Scheduled audits still perform live resolution across the supported Python/OS matrix.
- CONTRIBUTING now runs pip-audit from the committed requirements file and documents how to refresh it without creating a root-level artifact.
- The security workflow tests now assert triggers, deterministic audit behavior, action SHA pins, hashed committed requirements, and the absence of
run_command(shell=...). - PR validation notes now match the Bandit baseline command used by CI.
Local validation passed:
git diff --checkuv run python -m pytest tests/test_security_workflow.py -quv run python -m pytest -quvx ruff check src tests/test_security_workflow.pyuvx --from pip-audit==2.10.0 pip-audit --disable-pip --require-hashes -r .github/security-audit-requirements.txt --progress-spinner offuvx --from bandit==1.9.4 bandit -r src -lll --baseline .github/bandit-baseline.json
The new GitHub workflow runs are currently waiting for fork PR approval (action_required).
Please address Copilot feedback
Added a follow-up hardening commit: 1f85b92.
This addresses the similar risk surfaces we discussed after the Copilot review:
- All repository workflows now pin third-party actions to full commit SHAs, guarded by
tests/test_github_workflows.py. - Extension/preset downloads now use bounded reads and optional catalog
sha256verification. - Extension/preset ZIP installs now use a shared safe extractor with traversal, Windows-drive, symlink, file-count, per-file-size, and total-size checks.
- Extension/preset/workflow catalog fetches now use strict HTTPS redirect handling for download/catalog paths.
- Extension command source files and manifest-declared paths now reject traversal before registration.
Local validation passed:
git diff --checkuvx ruff check src tests/test_download_security.py tests/test_github_workflows.py tests/test_registrar_path_traversal.py tests/test_extensions.py tests/test_presets.py tests/test_security_workflow.pyuv run python -m pytest tests/test_download_security.py tests/test_github_workflows.py tests/test_registrar_path_traversal.py tests/test_extensions.py tests/test_presets.py tests/test_workflows.py -quv run python -m pytest tests/test_security_workflow.py -quv run python -m pytest -q(2781 passed, 34 skipped)uvx --from pip-audit==2.10.0 pip-audit --disable-pip --require-hashes -r .github/security-audit-requirements.txt --progress-spinner offuvx --from bandit==1.9.4 bandit -r src -lll --baseline .github/bandit-baseline.json
The latest GitHub workflow runs are again waiting for fork PR approval (action_required).
Please address Copilot feedback. Thank you once again for working through all these reviews!
Addressed the latest Copilot review feedback in commit 4599155.
What changed:
- Reject Windows drive-relative paths such as C:secret.md in preset/extension command paths and ZIP member names.
- Use bounded reads for catalog JSON in extension, preset, and integration catalogs, plus remaining CLI download surfaces that still had raw response reads.
- Add a committed requirements sync check for PR/push runs when dependency inputs change, using GitHub-provided diff SHAs with a conservative fallback.
- Regenerate .github/security-audit-requirements.txt without the uv header so the workflow sync comparison is stable.
- Add regression coverage for max ZIP entries, total uncompressed ZIP size, bounded catalog reads, stale audit requirements checks, and a source scan preventing new bare resp.read()/response.read() calls under src/specify_cli.
Validation run locally:
- git diff --check
- uvx ruff check on all changed Python surfaces and new tests
- uv run python -m pytest tests/test_download_security.py tests/test_extensions.py tests/test_presets.py tests/integrations/test_integration_catalog.py tests/test_security_workflow.py tests/test_upgrade.py -q: 629 passed
- uv run python -m pytest -q: 2797 passed, 34 skipped
- uv pip compile ... --no-header compared cleanly against .github/security-audit-requirements.txt
- pip-audit on the committed requirements: no known vulnerabilities found
- Bandit with the committed baseline: no issues identified
I attempted to resolve the five Copilot threads directly, but the GitHub integration returned Resource not accessible by integration, so they will need to be marked resolved by someone with repository permissions.
Hi @mnriem — quick status update and a small ask.
Conflicts resolved (e869b19): rebased onto current main after the _utils.py / _assets.py / catalogs.py refactors. The hardening from this branch is preserved (notably run_command dropping shell= is now applied to the relocated function in _utils.py; read_response_limited kept).
Follow-on PR checks (b089f8b) — six guardrails so the hardening doesn't silently regress:
- ruff
S602/S604/S605(subprocess shell=True) inpyproject.toml, with one explicit# noqa: S602on the intentional shell step. - Bandit two-pass in
security.yml: HIGH+baseline blocking, MEDIUM non-blocking informational. - Bandit baseline diff check — fails PRs that grow
.github/bandit-baseline.jsonwithout asecurity-baseline-changelabel. New helper script. detect-secretssecret-scan job + committed.secrets.baseline(9 audited false positives: SHA pins, docs examples, test fixtures).shellcheck --severity=erroronscripts/bash/*.shinlint.yml.macos-latestadded to thedependency-auditmatrix insecurity.yml.
Tests: 2968 pass locally on the merged tree.
Ask: the four workflows (CodeQL, Lint, Test & Lint Python, Security Audit) are sitting in action_required on the latest commit. Could you click Approve and run workflows when you have a moment? Happy to split (2) into a separate PR if you'd rather review the conflict resolution first.
Should we reorient this PR and carve it up in smaller pieces? If not, please address Copilot feedback
Please address Copilot feedback
Updated on behalf of @PascalThuet by Codex (GPT-5).
Commit: ca4c545dab572a99ddad0af65caf8ff5aeb4ac3f
What changed:
- Addressed the latest Copilot workflow-catalog comment by routing fetch-time URL validation through the shared catalog validator /
is_https_or_localhost_httppredicate, so hostless URLs such ashttps:///workflow-catalog.jsonare rejected before fetch and after redirects. - Added regression coverage for direct hostless catalog URL validation and hostless redirect validation during
_fetch_single_catalog. - Merged current
origin/maininto the PR branch. The merge completed without manual conflicts.
Validation run locally:
uv run pytest tests/test_workflows.py tests/test_download_security.py tests/test_security_workflow.py -q-> 264 passeduvx ruff check src/specify_cli/workflows/catalog.py tests/test_workflows.py-> passedgit diff --check-> passed
GitHub now reports the PR as mergeable. gh pr checks currently reports no checks on the branch.
Please address Copilot feedback and rebase on upstream/main
Rebased the branch on current origin/main and resolved the remaining conflicts. Copilot feedback is addressed by rejecting hostless URLs consistently, clarifying HTTPS/loopback guidance, preserving strict redirect handling for authenticated and strict unauthenticated downloads, and keeping bounded-read tests aligned with real stream behavior.
Pushed commit 1f1b20c9e7544b67d7be067c45c7c63b3c75de45.
Local verification:
uvx ruff check ...passed.uv run pytest tests/test_download_security.py tests/test_github_http.py tests/test_authentication.py tests/test_upgrade.py tests/test_workflows.py tests/test_extensions.py tests/test_presets.py tests/integrations/test_integration_catalog.py tests/test_security_workflow.py tests/test_baseline_gates.py -qpassed: 1217 passed, 19 warnings from temporaryauth.jsonfixture permissions.
GitHub reports the PR as mergeable. No GitHub checks are currently reported for this branch.
Please address Copilot feedback and test & lint errors
Updated on behalf of @PascalThuet by Codex (GPT-5).
Commit: e3f0153fa90a00415ccfb871c9676fa6c9de7fcc
What changed:
- Clarified
open_url()redirect-handler documentation so it matches thestrict_redirects or redirect_validator is not Noneimplementation. - Removed the redundant Azure DevOps redirect validator;
_StripAuthOnRedirectalready applies the strict scheme guard. - Removed lingering
shell=arguments from_utils.run_command()after the explicitshell=Truerejection, clearing the new Bandit B602 findings without source suppressions. - Preserved the real
PATHin baseline-gate subprocess tests so Windows can findgit. - Regenerated
.github/security-audit-requirements.txtwith the CI compile command and updated.secrets.baselinefor the false positives surfaced by the secret scan.
Local validation:
uvx ruff check src/specify_cli/_utils.py src/specify_cli/authentication/http.py src/specify_cli/authentication/azure_devops.py tests/test_baseline_gates.pypassed.git diff --checkpassed.uvx --from bandit==1.9.4 bandit -r src -lll --baseline .github/bandit-baseline.jsonpassed.git ls-files -z -- ':!:.secrets.baseline' ':!:uv.lock' ':!:.github/security-audit-requirements.txt' | xargs -0 uvx --from detect-secrets==1.5.0 detect-secrets-hook --baseline .secrets.baselinepassed.GENERATED_REQUIREMENTS=/tmp/spec-kit-2442-security-audit-requirements.txt DEPENDENCY_DIFF_BASE=cedbf484d7a94b5566b24169c642ae48a3c81394 DEPENDENCY_DIFF_HEAD=HEAD python .github/scripts/check_security_requirements.pypassed.uvx --from pip-audit==2.10.0 pip-audit --disable-pip --require-hashes -r .github/security-audit-requirements.txt --progress-spinner offpassed.uv run pytest tests/test_authentication.py tests/test_baseline_gates.py tests/test_security_workflow.py -qpassed: 124 passed, 19 expected auth fixture permission warnings.
GitHub created new pull_request runs for e3f0153, but they are currently action_required, so they need maintainer approval before they will execute.