Files
unslothai--unsloth/tests/security/test_lint_workflow_triggers.py
T
wehub-resource-sync e93507a09c
Lockfile supply-chain audit / lockfile supply-chain audit (push) Has been cancelled
Windows Studio GGUF CI / GPU prebuilt resolves without Visual Studio (push) Has been cancelled
Windows Studio GGUF CI / setup.ps1 unit tests (VS 2026 / CMake guard) (push) Has been cancelled
Windows Studio GGUF CI / real-VS detection (VS 2022) (push) Has been cancelled
Windows Studio GGUF CI / real-VS detection (VS 2026) (push) Has been cancelled
Windows Studio GGUF CI / VC++ runtime detect + install round-trip (windows-2025-vs2026) (push) Has been cancelled
Windows Studio GGUF CI / VC++ runtime detect + install round-trip (windows-latest) (push) Has been cancelled
Windows Studio Update CI / Studio Updating Tests (push) Has been cancelled
Wheel CI / Wheel build + content sanity + import smoke (push) Has been cancelled
Lint CI / Source lint (Python + shell + YAML + JSON + safety nets) (push) Has been cancelled
MLX CI on Mac M1 / dispatch (push) Has been cancelled
Security audit / advisory audit (pip + npm + cargo) (push) Has been cancelled
Security audit / pip scan-packages :: extras (push) Has been cancelled
Security audit / pip scan-packages :: studio (push) Has been cancelled
Security audit / pip scan-packages :: hf-stack (push) Has been cancelled
Security audit / npm scan-packages (Studio frontend tarballs) (push) Has been cancelled
Security audit / workflow-trigger lint (pull_request_target / cache-poisoning) (push) Has been cancelled
Security audit / pytest tests/security (push) Has been cancelled
Security audit / npm provenance + new install-script diff (push) Has been cancelled
Studio API CI / Studio API & Auth Tests (push) Has been cancelled
Backend CI / (Python 3.10) (push) Has been cancelled
Backend CI / (Python 3.11) (push) Has been cancelled
Backend CI / (Python 3.12) (push) Has been cancelled
Backend CI / (Python 3.13) (push) Has been cancelled
Backend CI / Repo tests (CPU) (push) Has been cancelled
Frontend CI / Frontend build + bundle sanity (push) Has been cancelled
Studio GGUF CI / OpenAI, Anthropic API tests (push) Has been cancelled
Studio GGUF CI / Tool calling Tests (push) Has been cancelled
Studio GGUF CI / JSON, images (push) Has been cancelled
Mac Studio GGUF CI / OpenAI, Anthropic API tests (push) Has been cancelled
Mac Studio GGUF CI / Tool calling Tests (push) Has been cancelled
Mac Studio GGUF CI / JSON, images (push) Has been cancelled
Mac Studio Install Matrix CI / Install + load (macos-14) (push) Has been cancelled
Mac Studio Install Matrix CI / Install + load (macos-15) (push) Has been cancelled
Mac Studio Install Matrix CI / Install + load (macos-26) (push) Has been cancelled
Mac Studio Install Matrix CI / Install + load (macos-15-intel) (push) Has been cancelled
Mac Studio API CI / Studio API & Auth Tests (push) Has been cancelled
Mac Studio Install Matrix CI / Install + load (macos-26-intel) (push) Has been cancelled
Mac Studio UI CI / Chat UI Tests (push) Has been cancelled
Studio Tauri CI / Tauri Linux debug build (no codesign) (push) Has been cancelled
Mac Studio Update CI / Studio Updating Tests (push) Has been cancelled
Studio UI CI / Chat UI Tests (push) Has been cancelled
Windows Studio API CI / Studio API & Auth Tests (push) Has been cancelled
Windows Studio UI CI / Chat UI Tests (push) Has been cancelled
Studio Update CI / Studio Updating Tests (push) Has been cancelled
Core / Core (HF=default + TRL=default) (push) Has been cancelled
Core / Core (HF=4.57.6 + TRL<1) (push) Has been cancelled
Core / Core (HF=latest + TRL=latest) (push) Has been cancelled
Core / llama.cpp build + smoke (push) Has been cancelled
Windows Studio GGUF CI / OpenAI, Anthropic API tests (push) Has been cancelled
Windows Studio GGUF CI / Tool calling Tests (push) Has been cancelled
Windows Studio GGUF CI / JSON, images (push) Has been cancelled
Windows Studio GGUF CI / Studio install + inference without Visual Studio (push) Has been cancelled
Studio export capability / capability (macos-latest) (push) Has been cancelled
Studio export capability / capability (ubuntu-latest) (push) Has been cancelled
Studio export capability / capability (windows-latest) (push) Has been cancelled
Cross-platform parity / parity (macos-latest) (push) Has been cancelled
Cross-platform parity / parity (windows-latest) (push) Has been cancelled
Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
Studio load-orchestrator CI / test (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:59:56 +08:00

133 lines
4.0 KiB
Python

"""Regression tests for scripts/lint_workflow_triggers.py, guarding GHSA-g7cv-rxg3-hmpx vectors."""
from __future__ import annotations
import shutil
import subprocess
import sys
from pathlib import Path
import pytest
REPO_ROOT = Path(__file__).resolve().parents[2]
SCRIPT = REPO_ROOT / "scripts" / "lint_workflow_triggers.py"
def _run(workflows_dir: Path) -> subprocess.CompletedProcess:
return subprocess.run(
[sys.executable, str(SCRIPT), "--workflows-dir", str(workflows_dir)],
capture_output = True,
text = True,
)
def test_lint_passes_on_current_workflows():
"""The live `.github/workflows/` tree must pass the lint."""
live = REPO_ROOT / ".github" / "workflows"
proc = _run(live)
assert (
proc.returncode == 0
), f"live tree failed lint:\nstdout:\n{proc.stdout}\nstderr:\n{proc.stderr}"
def test_lint_rejects_pull_request_target(tmp_path):
"""Synthetic PR_TARGET trigger must produce rc=1 with a named finding."""
wf = tmp_path / "wf"
wf.mkdir()
(wf / "bad.yml").write_text(
"name: bad\n"
"on:\n"
" pull_request_target:\n"
" branches: [main]\n"
"jobs:\n"
" build:\n"
" runs-on: ubuntu-latest\n"
" steps:\n"
" - run: echo evil\n"
)
proc = _run(wf)
assert proc.returncode == 1
assert "BANNED trigger 'pull_request_target'" in proc.stderr
assert "GHSA-g7cv-rxg3-hmpx" in proc.stderr
def test_lint_rejects_unjustified_workflow_run(tmp_path):
"""`workflow_run` requires an explicit allow-comment in the YAML."""
wf = tmp_path / "wf"
wf.mkdir()
(wf / "chained.yml").write_text(
"name: chained\n"
"on:\n"
" workflow_run:\n"
" workflows: ['CI']\n"
" types: [completed]\n"
"jobs:\n"
" build:\n"
" runs-on: ubuntu-latest\n"
" steps:\n"
" - run: echo elevated\n"
)
proc = _run(wf)
assert proc.returncode == 1
assert "RESTRICTED trigger 'workflow_run'" in proc.stderr
def test_lint_allows_justified_workflow_run(tmp_path):
"""With the allow-comment, workflow_run is permitted."""
wf = tmp_path / "wf"
wf.mkdir()
(wf / "chained.yml").write_text(
"# lint:workflow_triggers-allow-workflow_run -- justified by ticket #1234\n"
"name: chained\n"
"on:\n"
" workflow_run:\n"
" workflows: ['CI']\n"
" types: [completed]\n"
"jobs:\n"
" build:\n"
" runs-on: ubuntu-latest\n"
" steps:\n"
" - run: echo elevated\n"
)
proc = _run(wf)
assert proc.returncode == 0, f"justified workflow_run rejected:\n{proc.stderr}"
def test_lint_rejects_shared_cache_key_between_pr_and_publish(tmp_path):
"""A cache key declared in both a PR-triggered workflow and the
publish workflow is the TanStack cache-poisoning vector."""
wf = tmp_path / "wf"
wf.mkdir()
# PR-triggered: writes a cache the publish job will also restore.
(wf / "pr-build.yml").write_text(
"name: pr-build\n"
"on:\n"
" pull_request:\n"
"jobs:\n"
" build:\n"
" runs-on: ubuntu-latest\n"
" steps:\n"
" - uses: actions/cache@v4\n"
" with:\n"
" path: node_modules\n"
" key: shared-cache-v1\n"
)
# Publish workflow with the IDENTICAL cache key (the attack pattern).
(wf / "release-desktop.yml").write_text(
"name: release-desktop\n"
"on:\n"
" workflow_dispatch:\n"
"jobs:\n"
" publish:\n"
" runs-on: ubuntu-latest\n"
" steps:\n"
" - uses: actions/cache@v4\n"
" with:\n"
" path: node_modules\n"
" key: shared-cache-v1\n"
)
proc = _run(wf)
assert proc.returncode == 1
assert "cache-key" in proc.stderr.lower() or "cache key" in proc.stderr.lower()
assert "shared-cache-v1" in proc.stderr