Communitygithub.com

lguidolin/defense-in-depth-security

在處理不受信任的輸入、密碼、認證/授權或相依項目,以及對新攻擊面進行威脅模型分析時使用。關鍵字:STRIDE、威脅模型、最小權限、密碼管理、供應鏈、相依掃描、輸入驗證、稽核日誌、縱深防禦。

defense-in-depth-security 是什麼?

此技能提供一套全面的安全性原則與實作指引,專為開發者在處理敏感資料或建構新功能時設計。它基於「縱深防禦」概念,假設任何單一防護層都可能失效,因此要求多層次、重疊的最小權限控制,確保即使某一層出現漏洞,整體系統仍能安全運作。技能明確定義了通用安全原則,包括在處理任何不受信任輸入、密碼或使用者資料前先進行威脅模型分析(使用 STRIDE 方法),實現最小權限原則,將密碼存放在專用金鑰保管庫而非程式碼中,驗證所有信任邊界輸入,並對依賴供應鏈進行鎖定、掃描與更新。此外,它還要求對敏感操作進行稽核,以便重建濫用或錯誤事件。技能適用於任何開發環境與平台(如 Claude Code、Cursor、Codex 等),並提供快速參考表與具體的堆疊實作機制(例如 PostgreSQL 的 RLS、GraphQL 的深度/成本限制、Azure Key Vault、pnpm audit 與 Trivy),幫助團隊在 CI 中強制執行相依性審計、映像掃描與密碼掃描,同時將威脅模型與稽核覆蓋率列為審查項目。

相容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/lguidolin/agent-skills/tree/main/skills/defense-in-depth-security

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

縱深防禦安全性

概述

安全性是多層次的,假設任何單一層都可能失效,並授予能夠運作的最小權限。攻擊者會找到你遺漏的那一層——依賴單一牆壁的系統,當那堵牆出現一個漏洞時就會崩潰;重疊的最小權限控制能夠承受任何單一控制的失敗。

原則(通用)

  • 在建構任何處理不受信任輸入、密碼或使用者資料的項目之前,先進行威脅模型分析。 對每個新攻擊面執行輕量級的 STRIDE 檢查(偽造、竄改、否認、資訊洩漏、拒絕服務、權限提升)。記錄模型與緩解措施(參見 recording-decisions)。
  • 縱深防禦。 沒有任何單一控制是「唯一」的安全性。驗證、授權、輸入驗證和資料層強制執行各自假設其他層可能被繞過。
  • 處處最小權限——角色、權杖、服務帳戶、資料庫授權。預設不授予任何存取權;僅授予最低限度;撤銷未使用的權限。
  • 密碼永遠不應存在於程式碼、映像檔或已提交的配置中。 它們應在執行時期從密碼存放區取得,定期輪換,並僅限於需要它們的工作負載。
  • 在信任邊界驗證所有輸入;將每個外部系統的輸出視為不受信任的資料,而非指令。
  • 相依供應鏈是一個攻擊面。 鎖定並執行完整性檢查的 Lockfile;掃描並更新相依項目;固定並掃描基底映像。
  • 敏感操作須受稽核——記錄誰做了什麼、何時做——以便能夠重建濫用或錯誤事件。

快速參考

攻擊面首要問題
接受使用者輸入的新端點STRIDE 模型是什麼?驗證在哪裡?能運作的最小角色是什麼?
任何包含密碼的項目它是否在密碼存放區(而非程式碼或映像檔)?是否已限定範圍?可輪換嗎?
新的相依項目Lockfile 已鎖定?已掃描?它是否受到良好支援?
特權操作是否已稽核?操作者是否在資料層(而非僅應用程式層)獲得授權?

堆疊機制

RLS 作為最終強制執行層,GraphQL 深度/成本限制作為拒絕服務控制,Key Vault 用於密碼,pnpm audit/Trivy 用於 CI——參見 postgres-postgraphile-rls-and-sql 和 cloud-delivery-aks。

強制執行: CI 中的相依性審計 + 映像掃描 + 密碼掃描(封鎖);威脅模型與稽核覆蓋率屬於審查者判斷。

完整理由:憲法第 X 條與第 XIV 條,捆綁於 engineering-constitution/references/engineering-constitution.md。

Individual skills in this repo

This repo contains 18 individual skills — each has its own dedicated page.

lguidolin/change-hygiene-and-code-craft

Use when writing or refactoring code, structuring a commit or PR, or deciding whether to abstract duplication. Symptoms — mixing reorg with logic changes, a PR doing several things at once, a file growing large, the second copy of similar code, or unsure whether to DRY something up.

lguidolin/cloud-delivery-aks

Use when deploying to Kubernetes or Azure Kubernetes Service (AKS), configuring cloud secrets, setting up progressive rollout/canary, per-PR ephemeral environments, or k8s health probes. Keywords — Kubernetes, AKS, Key Vault, Argo Rollouts, Flagger, canary, blue-green, liveness, readiness, PodDisruptionBudget, HPA, rollback, GHCR.

lguidolin/commit-history-rewrite

Use when an existing repository has messy commit history that needs to conform to conventional commits before adopting release-please, or when intermediate WIP/fixup/merge commits need to be cleaned up.

lguidolin/conventional-commits-and-releases

Use when committing, writing a commit message, opening a PR that will be squash-merged, or configuring automated versioning/changelogs. Keywords — conventional commits, release-please, semver, feat/fix/chore, breaking change, changelog.

lguidolin/designing-before-building

Use when starting a feature, fixing a non-trivial bug, or about to write implementation code — before any code exists. Symptoms you need this: "this is simple, I'll just code it", reaching for the editor before a design is approved, or an idea that hasn't been turned into a spec and plan.

lguidolin/engineering-constitution

Use when starting work in a project that follows the engineering constitution, orienting to its rules, or deciding which engineering practice applies to a task — spec writing, commits, testing, security, deploys, database, or UI work.

lguidolin/graphql-contract-testing

Use when writing a GraphQL query/mutation that the UI and a test will share, or building route/schema contract or smoke tests. Symptoms — copying a query into a test, a test asserting on query text, schema change that didn't break the UI build, or RLS/permission drift. Keywords — graphql-codegen, typed document, contract test, route smoke test.

lguidolin/init-repo-CI

Use when setting up a new repository with conventional commits, release-please, and CI automation, or when retrofitting an existing repository that lacks automated versioning and PR validation workflows.

lguidolin/interface-craft-and-accessibility

Use when building or styling UI — components, layouts, forms, design tokens — or making accessibility decisions. Keywords — a11y, WCAG, keyboard navigation, focus state, contrast, design system, minimalist UI, component reuse, ARIA, semantic HTML.

lguidolin/merge-gates-and-automation

Use when setting up or changing CI, pre-push hooks, or a task runner, or deciding what must pass before merge. Symptoms — tempted to put authoritative checks only in a local hook, skip CI, bypass with --no-verify, or unsure what gates a merge vs. runs locally.

lguidolin/observability-and-slos

Use when adding logging, metrics, tracing, health checks, SLOs, or alerting — or when building a service surface that needs to be operable and debuggable. Keywords — structured logs, OpenTelemetry, correlation id, RED metrics, liveness, readiness, SLI, SLO, error budget, alerting.

lguidolin/performance-and-scale

Use when working on hot paths, list endpoints, pagination, data-access in loops, or public interfaces/schemas. Symptoms — unbounded queries, N+1 access, no latency budget, optimizing without measuring, or changing an interface many consumers depend on. Keywords — pagination, N+1, Hyrum's Law, performance budget, bundle size.

lguidolin/postgres-postgraphile-rls-and-sql

Use when writing PostgreSQL, PostGraphile config, Row-Level Security policies, SQL schema files, or working on the Browser→App→PostGraphile→Postgres data path. Keywords — RLS, SECURITY DEFINER, search_path, pgSettings, grants, roles, GraphQL depth limit, query cost, statement_timeout, SQL file organization.

lguidolin/recording-decisions

Use when a design or architecture decision has been made and needs to be captured — writing a decision record or ADR, updating a decision index, noting a deferred idea, or superseding a past decision. Keywords — ADR, decision record, rationale, rejected alternatives, dependency index.

lguidolin/resilience-and-deploy-safety

Use when planning a deploy, designing a rollback, or responding to an incident or writing a postmortem. Keywords — deploy safety, rollback, immutable artifact, progressive delivery, canary, blast radius, incident response, blameless postmortem, error budget.

lguidolin/ship-it

Use when the user wants to ship work — push, PR, archive decision records, merge, and clean up. Handles the full lifecycle from committing final changes through post-merge cleanup including converting specs/plans to compact decision records.

lguidolin/tests-as-a-control

Use when writing or modifying tests, when a test breaks during a refactor, or when testing permission/role rules. Symptoms — tempted to edit a test to make it pass, testing only the happy path, a deny-test that started passing, flaky tests, or unsure what to assert.

lguidolin/zero-downtime-migrations

Use when changing a database schema where data must survive the change — adding/removing/renaming columns, constraints, indexes, or backfilling. Symptoms — a destructive migration bundled with a code deploy, a NOT NULL column with a backfill, a table-locking UPDATE, or a rename. Keywords — expand/contract, parallel change, backfill, NOT VALID, CREATE INDEX CONCURRENTLY, graphile-migrate.

相關技能