Skip to content

feat: Implement Automated Security Scanning and Vulnerability Management - #78

Merged
Lynndabel merged 8 commits into
ChianLojistics:mainfrom
Samuel1505:main
Aug 21, 2026
Merged

feat: Implement Automated Security Scanning and Vulnerability Management#78
Lynndabel merged 8 commits into
ChianLojistics:mainfrom
Samuel1505:main

Conversation

@Samuel1505

Copy link
Copy Markdown
Contributor

[Feature] Automated Security Scanning and Vulnerability Management

Closes #70

Overview

Adds continuous, automated security scanning (SAST, dependency, secret,
container, IaC, and DAST) plus an in-app vulnerability management system,
where security checks were previously manual and inconsistent.

SonarQube, Snyk, and Burp Suite from the original issue were intentionally
left out — they need paid accounts/tokens this repo doesn't have. Semgrep,
npm audit, and OWASP ZAP cover the same categories (SAST / dependency /
DAST) for free, with no external account required to run in CI. See
"Known gaps" in the docs below for the rest of what's out of scope here.

What's included

CI security scanning (.github/workflows/security-scan.yml) — runs on
push to main/develop, PRs into main, and daily on a schedule:

  • SAST — Semgrep, using the community p/security-audit, p/secrets,
    p/typescript, p/nodejsscan rulesets plus custom rules
    (.semgrep/security-rules.yaml) for hardcoded secrets, string-concatenated
    SQL, weak hashes (MD5/SHA1), and disabled TLS verification.
  • Dependency scannpm audit --audit-level=high across backend/ and
    frontend/ (matrix job), fails the build on high/critical findings.
  • Secret scan — Gitleaks over full git history, with an allowlist
    (.gitleaks.toml) for test fixtures and .env.example.
  • Container scan — Trivy against the built backend image.
  • IaC scan — Checkov over the Dockerfiles and docker-compose.yml
    (no Terraform directory exists yet to point it at).
  • DAST — OWASP ZAP baseline scan against the backend, brought up via
    docker compose (Postgres + Redis + backend) and health-checked before
    scanning. Runs on push/schedule only, not PRs, to keep PR CI fast.
  • SARIF output from Semgrep, Trivy, and Checkov uploads to the repo's
    Security tab via github/codeql-action/upload-sarif.
  • Every job optionally forwards its results into the vulnerability dashboard
    (POST /security/scans/ingest) when SECURITY_API_URL /
    SECURITY_SCAN_TOKEN secrets are configured — a no-op otherwise.
  • .github/dependabot.yml — weekly PRs for backend/frontend npm deps,
    the backend's Docker base image, and GitHub Actions versions.

Vulnerability management (backend/src/security/)

  • Vulnerability / SecurityEvent entities (entities/).
  • ScanResultParser normalizes SARIF (Semgrep/Trivy/ZAP), npm audit, and
    Gitleaks reports into a common shape, deduplicated by a fingerprint of
    (source, rule, affected component, location) — re-ingesting a known
    finding updates its details but never touches status/assigned_to, so
    triage state survives repeat scans.
  • VulnerabilityManagementService — ingest, list/get, assign, resolve,
    ignore, and a dashboard (open counts by severity/type, 30-day trend).
    Every state transition is recorded as a SecurityEvent for audit history.
  • SecurityAlertService — logs every CRITICAL finding and optionally POSTs
    a summary to SECURITY_ALERT_WEBHOOK_URL (e.g. a Slack incoming webhook).
  • SecurityController:
    • POST /security/scans/ingest — guarded by a shared-secret x-scan-token
      header (ScanIngestGuard), since CI posts here, not a logged-in user.
    • GET /security/dashboard, GET /security/vulnerabilities[/:id],
      POST /security/vulnerabilities/:id/{assign,resolve,ignore} — behind
      the existing JwtAuthGuard + RolesGuard(Role.ADMIN).
  • Wired into AppModule.

Docsdocs/SECURITY_SCANNING.md covers what each job checks, how to
enable CI→dashboard reporting and webhook alerts, local commands to run each
scanner, and known gaps. SECURITY_SCAN_TOKEN / SECURITY_ALERT_WEBHOOK_URL
added to .env.example.

Testing

  • 15 new unit tests (backend/src/security/**/*.spec.ts): SARIF severity
    mapping (CVSS score vs. level fallback), CVE extraction, fingerprint
    stability across re-scans, npm-audit/Gitleaks mapping, create-vs-update-
    on-ingest, critical-finding alerting, status preservation on re-scan,
    assign/resolve, and dashboard grouping — all passing.
  • tsc --noEmit clean for the new module.
  • Full existing backend test suite re-run: no regressions from this change
    (pre-existing failures in crypto/distributed-ledger specs are
    unrelated — ESM import issues and a private-property access, both present
    before this branch).
  • All new YAML (security-scan.yml, dependabot.yml, Semgrep rules)
    validated with a YAML parser.

Manual verification still needed

  • The CI workflow itself (Semgrep/Trivy/Checkov/ZAP/Gitleaks marketplace
    actions, docker-compose health-check timing) hasn't run in GitHub Actions
    yet — needs a live run on this PR to confirm each job passes end-to-end.
  • CI→dashboard reporting and the Slack alert webhook are exercised by unit
    tests only; wiring real secrets and confirming an ingested finding shows
    up in GET /security/dashboard against a deployed backend is a follow-up.

Adds the Vulnerability/SecurityEvent entities and a parser that normalizes
SARIF (Semgrep/Trivy/ZAP), npm-audit, and Gitleaks reports into a common
shape, deduplicated by a fingerprint of (source, rule, component, location)
so repeat scans update a finding instead of duplicating it.

Part of ChianLojistics#70.
VulnerabilityManagementService ingests parsed scan results (upserting by
fingerprint, preserving triage status on re-scan), exposes assign/resolve/
ignore lifecycle transitions, and aggregates a dashboard (open counts by
severity/type, 30-day trend). SecurityAlertService logs and optionally
webhooks (SECURITY_ALERT_WEBHOOK_URL) every CRITICAL finding.

Part of ChianLojistics#70.
SecurityController adds POST /security/scans/ingest (guarded by a shared
x-scan-token header via ScanIngestGuard, for CI rather than user sessions),
GET /security/dashboard, GET/POST /security/vulnerabilities* for listing,
assigning, resolving, and ignoring findings behind the existing admin JWT
guards. SecurityModule is registered in AppModule.

Part of ChianLojistics#70.
Parser tests cover SARIF severity mapping (security-severity score vs.
level fallback), CVE extraction, fingerprint stability across re-scans,
npm-audit and Gitleaks mapping, and empty-payload handling. Service tests
cover create-vs-update-on-ingest, critical-finding alerting, status
preservation on re-scan, assign/resolve, and dashboard grouping.

Part of ChianLojistics#70.
Runs SAST (Semgrep), dependency scanning (npm audit on backend and
frontend), secret scanning (Gitleaks), container scanning (Trivy on the
backend image), IaC scanning (Checkov), and OWASP ZAP baseline DAST against
the backend on push/PR/daily schedule. SARIF results upload to the GitHub
Security tab; each job optionally forwards results to
POST /security/scans/ingest when SECURITY_API_URL/SECURITY_SCAN_TOKEN
secrets are configured. Dependabot opens weekly PRs for backend/frontend
npm deps, the backend Docker base image, and GitHub Actions versions.

Closes ChianLojistics#70.
Custom Semgrep rules for hardcoded secrets, string-concatenated SQL, weak
hashes, and disabled TLS verification (layered on top of the p/security-audit
and p/secrets community rulesets in CI). Gitleaks allowlist excludes test
fixtures/.env.example from secret matches. ZAP baseline rules.tsv suppresses
two alerts that are expected noise for a cookieless JSON API.

Part of ChianLojistics#70.
Explains what each CI job checks, how to enable CI-to-dashboard reporting
and critical-finding webhook alerts, local commands to run each scanner,
and known gaps (no SonarQube/Snyk/Burp Suite - free equivalents used
instead; no Terraform directory yet for the IaC scan to target). Adds the
new SECURITY_SCAN_TOKEN/SECURITY_ALERT_WEBHOOK_URL env vars to .env.example.

Part of ChianLojistics#70.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] Automated Security Scanning and Vulnerability Management

2 participants