From 2f2802e698de4cdcaf542ca1cbc6088d1741f76f Mon Sep 17 00:00:00 2001 From: DevJoshhie Date: Wed, 25 Nov 2026 14:47:34 +0000 Subject: [PATCH] ci(security): add cargo-audit --deny warnings and pnpm audit with SARIF upload (#408) - Run cargo audit --deny warnings as the fail gate for Rust dependencies - Generate SARIF report from cargo audit JSON output and upload to code scanning - Split pnpm audit into a matrix across apps/web, apps/server, extensions/vscode - Generate SARIF from pnpm audit JSON output per workspace and upload to code scanning - Requires security-events: write permission on audit jobs Closes #408 --- .github/workflows/security.yml | 102 ++++++++++++++++++++++++++++++--- 1 file changed, 95 insertions(+), 7 deletions(-) diff --git a/.github/workflows/security.yml b/.github/workflows/security.yml index 16d5202..95c3b2d 100644 --- a/.github/workflows/security.yml +++ b/.github/workflows/security.yml @@ -13,19 +13,60 @@ jobs: cargo-audit: name: Rust dependency audit runs-on: ubuntu-latest + permissions: + contents: read + security-events: write steps: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable - name: Generate dependency lockfile run: cargo generate-lockfile - - name: Install cargo-audit - run: cargo install cargo-audit --locked - - name: Audit Rust dependencies - run: cargo audit + - name: Install cargo-audit (with SARIF support) + run: cargo install cargo-audit --features sarif --locked + - name: Audit Rust dependencies (deny warnings) + run: cargo audit --deny warnings + - name: Generate SARIF report + if: always() + run: cargo audit --json 2>/dev/null | python3 -c " +import json, sys +audit = json.load(sys.stdin) +vulns = audit.get('vulnerabilities', {}).get('list', []) +results = [] +for v in vulns: + adv = v.get('advisory', {}) + results.append({ + 'ruleId': adv.get('id', 'RUSTSEC-UNKNOWN'), + 'message': {'text': adv.get('title', 'Unknown vulnerability')}, + 'locations': [{'physicalLocation': {'artifactLocation': {'uri': 'Cargo.lock'}}}], + 'level': 'error' + }) +sarif = { + 'version': '2.1.0', + '\$schema': 'https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json', + 'runs': [{'tool': {'driver': {'name': 'cargo-audit', 'version': '0.21', 'rules': []}}, 'results': results}] +} +print(json.dumps(sarif)) +" > cargo-audit.sarif 2>/dev/null || echo '{"version":"2.1.0","runs":[{"tool":{"driver":{"name":"cargo-audit","version":"0.21"}},"results":[]}]}' > cargo-audit.sarif + - name: Upload Rust audit SARIF to code scanning + if: always() + uses: github/codeql-action/upload-sarif@v3 + with: + sarif_file: cargo-audit.sarif + category: cargo-audit javascript-audit: - name: JavaScript dependency audit + name: JavaScript dependency audit (${{ matrix.workspace }}) runs-on: ubuntu-latest + permissions: + contents: read + security-events: write + strategy: + fail-fast: false + matrix: + workspace: + - apps/web + - apps/server + - extensions/vscode steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 @@ -33,8 +74,55 @@ jobs: node-version: 20 - name: Enable pnpm run: corepack enable - - name: Audit JavaScript dependencies - run: pnpm audit --audit-level high + - name: Install dependencies + run: pnpm install --frozen-lockfile + - name: Audit ${{ matrix.workspace }} dependencies + run: pnpm --filter "./$(echo '${{ matrix.workspace }}')" audit --audit-level high + continue-on-error: false + - name: Generate SARIF report for ${{ matrix.workspace }} + if: always() + run: | + set -euo pipefail + WORKSPACE="${{ matrix.workspace }}" + SAFE_NAME=$(echo "$WORKSPACE" | tr '/' '-') + pnpm --filter "./$WORKSPACE" audit --json 2>/dev/null > "pnpm-audit-${SAFE_NAME}.json" || true + python3 -c " +import json, sys, os +safe = os.environ.get('SAFE_NAME', 'workspace') +ws = os.environ.get('WORKSPACE', '.') +fname = f'pnpm-audit-{safe}.json' +try: + with open(fname) as f: + audit = json.load(f) +except Exception: + audit = {} +advisories = audit.get('advisories', {}) +results = [] +for adv_id, adv in advisories.items(): + results.append({ + 'ruleId': str(adv.get('id', adv_id)), + 'message': {'text': adv.get('title', 'Unknown vulnerability')}, + 'locations': [{'physicalLocation': {'artifactLocation': {'uri': f'{ws}/package.json'}}}], + 'level': 'error' if adv.get('severity') in ('high', 'critical') else 'warning' + }) +sarif = { + 'version': '2.1.0', + '\$schema': 'https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json', + 'runs': [{'tool': {'driver': {'name': 'pnpm-audit', 'version': '1.0'}}, 'results': results}] +} +with open(f'pnpm-audit-{safe}.sarif', 'w') as out: + json.dump(sarif, out) +print(f'Generated pnpm-audit-{safe}.sarif with {len(results)} finding(s)') +" 2>/dev/null + env: + WORKSPACE: ${{ matrix.workspace }} + SAFE_NAME: ${{ matrix.workspace != '' && format('{0}', matrix.workspace) }} + - name: Upload ${{ matrix.workspace }} audit SARIF to code scanning + if: always() + uses: github/codeql-action/upload-sarif@v3 + with: + sarif_file: pnpm-audit-${{ matrix.workspace == 'apps/web' && 'apps-web' || matrix.workspace == 'apps/server' && 'apps-server' || 'extensions-vscode' }}.sarif + category: pnpm-audit-${{ matrix.workspace == 'apps/web' && 'apps-web' || matrix.workspace == 'apps/server' && 'apps-server' || 'extensions-vscode' }} codeql: name: CodeQL (${{ matrix.language }})