fercarballo/devsecops-pipeline
GitHub: fercarballo/devsecops-pipeline
在 CI 流水线中集成 SAST、SCA、DAST 三层安全扫描并按严重程度设置质量门禁的 DevSecOps 示例项目。
Stars: 0 | Forks: 0
# DevSecOps — 自动化安全 Pipeline
**安全左移(shift-left)** Pipeline,集成了三层自动分析作为 *quality gate*:**SAST**(静态代码分析)、**SCA**(依赖项漏洞分析)和 **DAST**(对运行中的应用程序进行动态测试)。

## 执行摘要
| | |
|---|---|
| **它是什么** | 在 CI pipeline 中实现安全控制的自动化,以便在集成之前对每个更改进行漏洞分析。 |
| **解决的问题** | 将安全视为年度审计会导致发现得太晚且成本高昂。这种方法能够在每次更改时检测出不安全的代码、存在漏洞的依赖项以及运行时的弱点。 |
| **方法** | 三个互补层(SAST + SCA + DAST),并按严重程度设置 quality gate:一个严重漏洞即可阻断集成。 |
| **结果** | 自动且早期地检测最常见的漏洞类别(OWASP Top 10),通过强化应用程序以通过所有 quality gate,并提供用于演示检测过程的示例。 |
| **技术栈** | Semgrep · npm audit · Vitest(自研 DAST) · OWASP ZAP(参考) · GitHub Actions |
## 三层安全
```
flowchart TB
subgraph P["Pipeline DevSecOps"]
SAST["SAST — Semgrep
analiza el CÓDIGO"] SCA["SCA — npm audit
analiza las DEPENDENCIAS"] DAST["DAST — pruebas dinámicas
analizan la APP CORRIENDO"] end SAST --> G{"¿Vulnerabilidad
grave?"} SCA --> G DAST --> G G -->|sí| B["❌ Bloquea la integración"] G -->|no| OK["✓ Integración permitida"] style B fill:#c0392b,color:#fff style OK fill:#1e7a4f,color:#fff ``` | 层 | 分析内容 | 工具 | 检测示例 | |---|---|---|---| | **SAST** | 源代码(静态) | Semgrep | 命令/SQL 注入、`eval`、硬编码的 secret | | **SCA** | 依赖树 | npm audit | 库中已知的 CVE | | **DAST** | 运行中的应用(动态) | 自研测试 + OWASP ZAP | 反射型 XSS、缺失的安全 header、访问控制 | ## 强化应用程序 + 漏洞示例 出于特定目的,该仓库包含两个不同的内容: - **`src/`** — 一个**安全**的应用程序:包含安全 header、HTML 转义(防 XSS)、无信息泄露且采用时间恒定比较的登录功能,以及对受保护资源的访问控制。它能通过所有的 quality gate。 - **`security/examples-insecure/`** — **故意的**漏洞代码片段,它们**不**是应用程序的一部分。它们的存在是为了证明 SAST 能够检测到它们: ``` $ semgrep --config security/semgrep-rules.yml security/examples-insecure/ ❯❯❱ node-command-injection exec() con entrada dinámica ❯❯❱ sql-injection-string-concat query por interpolación de string ❯❯❱ use-of-eval eval() de código arbitrario ❯❯❱ hardcoded-secret secreto hardcodeado 4 Code Findings ``` ## Quality gate 生效(双向验证) - **SAST:** 在 `src/` 上保持干净(quality gate 通过),而在示例代码中发现 4 个问题(证明具备检测能力)。 - **DAST:** 针对该应用程序的 8 项动态安全测试全部通过。 - **SCA:** 在开发过程中,quality gate **检测到了一个真实的漏洞**(测试依赖项中关于 esbuild 的安全公告)并阻断了集成——随后通过更新依赖项进行了修复。这正是 quality gate 的用武之地。 ## 结构 ``` src/ ├── server.ts # aplicación segura bajo prueba └── main.ts # arranque de la app tests/security.test.ts # DAST propio (pruebas dinámicas de seguridad) security/ ├── semgrep-rules.yml # reglas SAST (locales, deterministas) └── examples-insecure/ # anti-patrones para demostrar la detección scripts/sca-gate.mjs # gate SCA (falla en high/critical) .github/workflows/ ├── devsecops.yml # SAST + SCA + DAST (gates) └── zap-dast.yml # OWASP ZAP baseline (referencia, manual) ``` ## 使用方法 ``` npm install npm test # DAST propio (pruebas dinámicas de seguridad) npm run sca # gate SCA (npm audit → falla en high/critical) npm run typecheck # SAST(需要安装 semgrep,或通过 Docker): semgrep --config security/semgrep-rules.yml src/ --error # gate: limpio semgrep --config security/semgrep-rules.yml security/examples-insecure # detección ``` ## 技术文档 **[docs/DOCUMENTACION-TECNICA.md](docs/DOCUMENTACION-TECNICA.md)** 详细介绍了:什么是 DevSecOps 和左移(shift-left)、深入探讨这三个层、按严重程度设定的 quality gate 决策、应用程序的强化(OWASP Top 10)、OWASP ZAP 的作用以及扩展途径。 ## 完整套件 本仓库是涵盖端到端测试周期质量自动化套件的一部分,从基础到 SDET 角色特有的实践。 **基础** 1. [UI E2E 框架](https://github.com/fercarballo/playwright-e2e-framework-saucedemo) — Playwright · Page Object Model 2. [API 测试](https://github.com/fercarballo/api-testing-framework-restful-booker) — 使用 Zod 进行契约测试 3. [CI/CD Pipeline](https://github.com/fercarballo/qa-automation-cicd-pipeline) — GitHub Actions · quality gate 4. [稳定性与 Flakiness](https://github.com/fercarballo/flakiness-hunting-playwright) — 检测与消除 5. [视觉回归与契约测试](https://github.com/fercarballo/visual-and-contract-testing) — Playwright + Pact **高级 (SDET)** 6. [性能与负载测试](https://github.com/fercarballo/performance-testing-k6) — k6 · 将 threshold 作为 quality gate 7. [集成真实依赖](https://github.com/fercarballo/integration-testing-testcontainers) — Testcontainers · Postgres 8. **DevSecOps** — 本仓库 9. [QA 内部工具](https://github.com/fercarballo/qa-insights) — 测试影响分析 + flaky 检测 10. [AI 应用评估](https://github.com/fercarballo/llm-evals-harness) — LLM 测试 ## 许可证 MIT.
analiza el CÓDIGO"] SCA["SCA — npm audit
analiza las DEPENDENCIAS"] DAST["DAST — pruebas dinámicas
analizan la APP CORRIENDO"] end SAST --> G{"¿Vulnerabilidad
grave?"} SCA --> G DAST --> G G -->|sí| B["❌ Bloquea la integración"] G -->|no| OK["✓ Integración permitida"] style B fill:#c0392b,color:#fff style OK fill:#1e7a4f,color:#fff ``` | 层 | 分析内容 | 工具 | 检测示例 | |---|---|---|---| | **SAST** | 源代码(静态) | Semgrep | 命令/SQL 注入、`eval`、硬编码的 secret | | **SCA** | 依赖树 | npm audit | 库中已知的 CVE | | **DAST** | 运行中的应用(动态) | 自研测试 + OWASP ZAP | 反射型 XSS、缺失的安全 header、访问控制 | ## 强化应用程序 + 漏洞示例 出于特定目的,该仓库包含两个不同的内容: - **`src/`** — 一个**安全**的应用程序:包含安全 header、HTML 转义(防 XSS)、无信息泄露且采用时间恒定比较的登录功能,以及对受保护资源的访问控制。它能通过所有的 quality gate。 - **`security/examples-insecure/`** — **故意的**漏洞代码片段,它们**不**是应用程序的一部分。它们的存在是为了证明 SAST 能够检测到它们: ``` $ semgrep --config security/semgrep-rules.yml security/examples-insecure/ ❯❯❱ node-command-injection exec() con entrada dinámica ❯❯❱ sql-injection-string-concat query por interpolación de string ❯❯❱ use-of-eval eval() de código arbitrario ❯❯❱ hardcoded-secret secreto hardcodeado 4 Code Findings ``` ## Quality gate 生效(双向验证) - **SAST:** 在 `src/` 上保持干净(quality gate 通过),而在示例代码中发现 4 个问题(证明具备检测能力)。 - **DAST:** 针对该应用程序的 8 项动态安全测试全部通过。 - **SCA:** 在开发过程中,quality gate **检测到了一个真实的漏洞**(测试依赖项中关于 esbuild 的安全公告)并阻断了集成——随后通过更新依赖项进行了修复。这正是 quality gate 的用武之地。 ## 结构 ``` src/ ├── server.ts # aplicación segura bajo prueba └── main.ts # arranque de la app tests/security.test.ts # DAST propio (pruebas dinámicas de seguridad) security/ ├── semgrep-rules.yml # reglas SAST (locales, deterministas) └── examples-insecure/ # anti-patrones para demostrar la detección scripts/sca-gate.mjs # gate SCA (falla en high/critical) .github/workflows/ ├── devsecops.yml # SAST + SCA + DAST (gates) └── zap-dast.yml # OWASP ZAP baseline (referencia, manual) ``` ## 使用方法 ``` npm install npm test # DAST propio (pruebas dinámicas de seguridad) npm run sca # gate SCA (npm audit → falla en high/critical) npm run typecheck # SAST(需要安装 semgrep,或通过 Docker): semgrep --config security/semgrep-rules.yml src/ --error # gate: limpio semgrep --config security/semgrep-rules.yml security/examples-insecure # detección ``` ## 技术文档 **[docs/DOCUMENTACION-TECNICA.md](docs/DOCUMENTACION-TECNICA.md)** 详细介绍了:什么是 DevSecOps 和左移(shift-left)、深入探讨这三个层、按严重程度设定的 quality gate 决策、应用程序的强化(OWASP Top 10)、OWASP ZAP 的作用以及扩展途径。 ## 完整套件 本仓库是涵盖端到端测试周期质量自动化套件的一部分,从基础到 SDET 角色特有的实践。 **基础** 1. [UI E2E 框架](https://github.com/fercarballo/playwright-e2e-framework-saucedemo) — Playwright · Page Object Model 2. [API 测试](https://github.com/fercarballo/api-testing-framework-restful-booker) — 使用 Zod 进行契约测试 3. [CI/CD Pipeline](https://github.com/fercarballo/qa-automation-cicd-pipeline) — GitHub Actions · quality gate 4. [稳定性与 Flakiness](https://github.com/fercarballo/flakiness-hunting-playwright) — 检测与消除 5. [视觉回归与契约测试](https://github.com/fercarballo/visual-and-contract-testing) — Playwright + Pact **高级 (SDET)** 6. [性能与负载测试](https://github.com/fercarballo/performance-testing-k6) — k6 · 将 threshold 作为 quality gate 7. [集成真实依赖](https://github.com/fercarballo/integration-testing-testcontainers) — Testcontainers · Postgres 8. **DevSecOps** — 本仓库 9. [QA 内部工具](https://github.com/fercarballo/qa-insights) — 测试影响分析 + flaky 检测 10. [AI 应用评估](https://github.com/fercarballo/llm-evals-harness) — LLM 测试 ## 许可证 MIT.
标签:DAST, DevSecOps, GitHub Actions, MITM代理, SAST, 上游代理, 安全专业人员, 恶意软件分析, 盲注攻击, 自动化攻击, 自动笔记