Skip to content
Open
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
243 changes: 138 additions & 105 deletions .github/workflows/malware-pr-guard.yml
Original file line number Diff line number Diff line change
@@ -1,114 +1,147 @@
name: Security & Malware PR Guard
# BE-089 | Automated Dependency Vulnerability Gatekeeper
#
# Blocks pull requests and deploys that introduce:
# • npm/pnpm packages with High or Critical CVEs (pnpm audit)
# • Known-vulnerable packages not yet in PNPM lockfile (Snyk)
# • Lockfile tampering / missing integrity hashes (pnpm install --frozen-lockfile)
#
# The job runs on every PR targeting `main` and on every push to `main`.
# It is intentionally NOT `continue-on-error` so a finding hard-blocks merge.

name: Dependency Vulnerability Gatekeeper

on:
pull_request_target:
types: [opened, reopened, synchronize]

pull_request:
branches: ["main"]
paths:
# Re-run whenever dependencies or workflow itself change.
- "package.json"
- "pnpm-lock.yaml"
- "**/package.json"
- "**/pnpm-lock.yaml"
- ".github/workflows/malware-pr-guard.yml"
push:
branches: ["main"]
paths:
- "package.json"
- "pnpm-lock.yaml"
- "**/package.json"
- "**/pnpm-lock.yaml"

# Principle of least privilege: only read access is needed to audit deps.
permissions:
pull-requests: write
issues: write
contents: read
# `security-events: write` is needed only for the optional SARIF upload step.
security-events: write

jobs:
inspect-pr:
name: Scan PR for Malware & Malicious Indicators
# ---------------------------------------------------------------------------
# 1. Lockfile integrity — verify that pnpm-lock.yaml is consistent with
# package.json and that all integrity hashes are present.
# ---------------------------------------------------------------------------
lockfile-integrity:
name: Lockfile integrity check
runs-on: ubuntu-latest
steps:
- name: Checkout (no credentials)
uses: actions/checkout@v4
with:
persist-credentials: false

- name: Set up pnpm
uses: pnpm/action-setup@v4
with:
version: 9

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
cache: "pnpm"

- name: Verify lockfile is consistent (frozen install)
# --frozen-lockfile aborts if pnpm-lock.yaml would be mutated.
# This catches "package.json updated but lockfile not committed".
run: pnpm install --frozen-lockfile --ignore-scripts

# ---------------------------------------------------------------------------
# 2. pnpm audit — block on any High or Critical CVE in the dependency tree.
# ---------------------------------------------------------------------------
pnpm-audit:
name: pnpm audit (High/Critical CVEs)
runs-on: ubuntu-latest
needs: lockfile-integrity
steps:
- name: Inspect PR files and diff
uses: actions/github-script@v7
- name: Checkout (no credentials)
uses: actions/checkout@v4
with:
persist-credentials: false

- name: Set up pnpm
uses: pnpm/action-setup@v4
with:
version: 9

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
cache: "pnpm"

- name: Install dependencies (frozen)
run: pnpm install --frozen-lockfile --ignore-scripts

- name: Run pnpm audit
# --audit-level=high exits non-zero for High and Critical findings only.
# Moderate/Low findings are reported but do not fail the build.
run: pnpm audit --audit-level=high
# If you need to manage exceptions, use a .nsprc / .auditrc allowlist
# or add `--ignore <advisory-id>` with a companion comment referencing
# the ticket that tracks the upgrade.

# ---------------------------------------------------------------------------
# 3. Snyk — deeper SCA that also catches transitive and license issues.
# Requires the SNYK_TOKEN secret to be set in repo/org settings.
# ---------------------------------------------------------------------------
snyk:
name: Snyk vulnerability scan
runs-on: ubuntu-latest
needs: lockfile-integrity
steps:
- name: Checkout (no credentials)
uses: actions/checkout@v4
with:
persist-credentials: false

- name: Set up pnpm
uses: pnpm/action-setup@v4
with:
version: 9

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
cache: "pnpm"

- name: Install dependencies (frozen)
run: pnpm install --frozen-lockfile --ignore-scripts

- name: Run Snyk to check for vulnerabilities
uses: snyk/actions/node@master
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
with:
# Block on High and Critical; Snyk maps this to --severity-threshold=high
args: --severity-threshold=high --all-projects
continue-on-error: false

- name: Upload Snyk SARIF report to GitHub Security tab
# Upload even when Snyk finds issues so reviewers can inspect findings.
if: always()
uses: github/codeql-action/upload-sarif@v3
with:
script: |
const pull_number = context.payload.pull_request.number;
const owner = context.repo.owner;
const repo = context.repo.repo;

// Fetch changed files
const files = await github.paginate(github.rest.pulls.listFiles, {
owner,
repo,
pull_number,
per_page: 100,
});

const violations = [];

// 1. Check file names & paths
const suspiciousFontRegex = /(fa-solid.*|\.lik$|\.woff2?$|\.eot$|\.ttf$)/i;
const binaryRegex = /\.(exe|dll|so|dylib|bin)$/i;

for (const file of files) {
const filename = file.filename;

// Check .vscode tasks
if (filename === '.vscode/tasks.json') {
violations.push(`File '.vscode/tasks.json' is prohibited (potential automatic folderOpen task execution).`);
}

// Check suspicious fonts / lik files
if (suspiciousFontRegex.test(filename)) {
violations.push(`Suspicious font or binary file '${filename}' added/modified.`);
}

// Check setup.js / dist/setup.js
if (filename.endsWith('setup.js')) {
violations.push(`Suspicious setup file '${filename}' detected.`);
}

// Check standalone binaries
if (binaryRegex.test(filename)) {
violations.push(`Binary executable file '${filename}' is prohibited.`);
}

// Check patches / diffs for specific indicators
const patch = file.patch || '';

// Known malicious signatures
if (patch.includes('rmcej%otb%') || patch.includes('Cot%3T=sthP') || patch.includes('_$__1e42')) {
violations.push(`Known malicious signature pattern detected in '${filename}'.`);
}

// Check .vscode/settings.json for allowAutomaticTasks
if (filename === '.vscode/settings.json' && /task\.allowAutomaticTasks/i.test(patch)) {
violations.push(`Prohibited setting 'task.allowAutomaticTasks' detected in '${filename}'.`);
}

// Check package.json for preinstall / postinstall hooks
if (filename.endsWith('package.json') && /"(preinstall|postinstall)"/i.test(patch)) {
violations.push(`Prohibited lifecycle hook (preinstall/postinstall) added to '${filename}'.`);
}

// Check config files for suspicious eval/exec/obfuscation
if (/\.(config\.(js|ts|mjs|cjs|mts))$/i.test(filename)) {
if (/eval\(|atob\(|Buffer\.from\(.*base64/i.test(patch)) {
violations.push(`Obfuscated or dynamic evaluation payload detected in '${filename}'.`);
}
}

// Check for suspicious curl/wget pipes
if (/curl\s+.*\|\s*(bash|sh|node)|wget\s+.*\|\s*(bash|sh|node)/i.test(patch)) {
violations.push(`Remote shell execution pipe (curl/wget | sh) detected in '${filename}'.`);
}
}

if (violations.length > 0) {
const violationList = violations.map(v => `- ⚠️ ${v}`).join('\n');
const comment = `### ⛔ Pull Request Rejected: Security Policy Violation\n\nThis pull request has been automatically closed because it violates the repository's supply-chain security policy:\n\n${violationList}\n\nPlease review your changes and remove any prohibited files, scripts, or indicators.`;

await github.rest.issues.createComment({
owner,
repo,
issue_number: pull_number,
body: comment,
});

await github.rest.pulls.update({
owner,
repo,
pull_number,
state: 'closed',
});

core.setFailed(`PR #${pull_number} was closed due to ${violations.length} security violation(s).`);
} else {
core.info(`PR #${pull_number} passed all malware and security checks.`);
}
sarif_file: snyk.sarif
# This step is best-effort: if Snyk didn't produce a sarif file (e.g.
# the token is not configured) we don't want to mask the real error.
continue-on-error: true
89 changes: 73 additions & 16 deletions .github/workflows/secret-scan.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,85 @@
name: Secret Scanning
# BE-089 | Secret & Credential Leak Detection
#
# Runs Gitleaks on every pull request and every push to `main` to detect
# accidentally committed secrets: private keys, API tokens, passwords,
# connection strings, seed phrases, and similar credentials.
#
# Configuration lives in .gitleaks.toml at the repository root.
# The job is NOT `continue-on-error`; a finding hard-blocks merge.

name: Secret Scan (Gitleaks)

on:
push:
branches: [ "**" ]
pull_request:
branches: [ "**" ]
branches: ["main"]
push:
branches: ["main"]
# Allow manual triggering for ad-hoc audits.
workflow_dispatch:

# Read-only: Gitleaks only inspects the checked-out source tree.
permissions:
contents: read
# Write access to the Security tab so Gitleaks SARIF is surfaced there.
security-events: write

jobs:
gitleaks:
name: Gitleaks Secret Scan
name: Gitleaks secret detection
runs-on: ubuntu-latest
steps:
- name: Checkout code
- name: Checkout full history
uses: actions/checkout@v4
with:
# Full clone so Gitleaks can inspect the complete commit history,
# not just the HEAD snapshot. This catches secrets that were added
# and "deleted" in a later commit but are still in git history.
fetch-depth: 0
- name: Install Gitleaks
run: |
wget -q https://github.com/gitleaks/gitleaks/releases/download/v8.18.2/gitleaks_8.18.2_linux_x64.tar.gz
tar -zxvf gitleaks_8.18.2_linux_x64.tar.gz
sudo mv gitleaks /usr/local/bin/
- name: Run gitleaks detect on PR
persist-credentials: false

# -----------------------------------------------------------------------
# For pull requests, Gitleaks compares only the commits in the PR branch
# against the base branch rather than re-scanning the entire history.
# For pushes to main it scans the diff introduced by the push.
# -----------------------------------------------------------------------
- name: Run Gitleaks (PR diff)
if: github.event_name == 'pull_request'
run: gitleaks detect --source . --gitleaks-ignore-path .gitleaksignore --verbose --redact
- name: Run gitleaks detect on push
if: github.event_name == 'push'
run: gitleaks detect --source . --gitleaks-ignore-path .gitleaksignore --verbose --redact
uses: gitleaks/gitleaks-action@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# GITLEAKS_LICENSE is required for org-level repos on the paid plan.
# Leave unset for public repos and personal accounts.
GITLEAKS_LICENSE: ${{ secrets.GITLEAKS_LICENSE }}
with:
# Scan only the commits added in this PR.
args: >-
detect
--config=.gitleaks.toml
--log-opts="${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }}"
--report-format=sarif
--report-path=gitleaks-report.sarif
--exit-code=1
--verbose

- name: Run Gitleaks (push / full scan)
if: github.event_name != 'pull_request'
uses: gitleaks/gitleaks-action@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITLEAKS_LICENSE: ${{ secrets.GITLEAKS_LICENSE }}
with:
args: >-
detect
--config=.gitleaks.toml
--report-format=sarif
--report-path=gitleaks-report.sarif
--exit-code=1
--verbose

- name: Upload Gitleaks SARIF to GitHub Security tab
# Upload findings even on failure so the Security tab lists them.
if: always()
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: gitleaks-report.sarif
continue-on-error: true
Loading
Loading