threat-modeling

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Threat Modeling

威胁建模

Analyze systems for security threats using the STRIDE methodology. Produce data flow diagrams, identify trust boundaries, map attack surfaces, and assess risk.
使用STRIDE方法论分析系统的安全威胁,生成数据流图、识别信任边界、映射攻击面并评估风险。

When to Use

适用场景

  • Designing a new system or feature that handles sensitive data.
  • Reviewing architecture for security before implementation.
  • Conducting a security review or threat assessment.
  • Identifying trust boundaries and attack surfaces.
  • Prioritizing security work by risk (likelihood x impact).
  • 设计处理敏感数据的新系统或新功能
  • 开发实现前对架构进行安全评审
  • 开展安全审查或威胁评估
  • 识别信任边界和攻击面
  • 按照风险(发生概率×影响程度)优先级排序安全工作

Instructions

使用指南

STRIDE Methodology

STRIDE方法论

Analyze each component and data flow for six threat categories:
CategoryThreatProperty Violated
SpoofingPretending to be someone elseAuthentication
TamperingModifying data or codeIntegrity
RepudiationDenying an action occurredNon-repudiation
Information DisclosureExposing data to unauthorizedConfidentiality
Denial of ServiceMaking the system unavailableAvailability
Elevation of PrivilegeGaining unauthorized accessAuthorization
针对每个组件和数据流,从六大威胁类别展开分析:
类别威胁描述被破坏的安全属性
Spoofing(欺骗)伪装成其他合法主体身份认证(Authentication)
Tampering(篡改)恶意修改数据或代码完整性(Integrity)
Repudiation(抵赖)否认执行过某个操作不可否认性(Non-repudiation)
Information Disclosure(信息泄露)向未授权方暴露数据保密性(Confidentiality)
Denial of Service(拒绝服务)导致系统不可用可用性(Availability)
Elevation of Privilege(权限提升)获得未授权的访问权限权限控制(Authorization)

Step 1: Data Flow Diagram

步骤1:绘制数据流图

Map the system showing processes, data stores, data flows, and external entities:
                    Trust Boundary
                    +---------------------------------+
  [User Browser] ---|---> [Web Server] ---> [App Server] ---> [Database]
                    |         |                  |
                    |         v                  v
                    |    [Static Files]    [Cache (Redis)]
                    +---------------------------------+
                           |
                           v
                    [External Auth Provider]
Label each element:
  • Processes (circles/boxes): Web server, app server, background workers.
  • Data stores (parallel lines): Database, cache, file system, message queue.
  • Data flows (arrows): HTTP requests, database queries, API calls.
  • External entities (rectangles): Users, third-party services, admin.
  • Trust boundaries (dashed lines): Network segments, process boundaries.
梳理系统的进程、数据存储、数据流和外部实体:
                    Trust Boundary
                    +---------------------------------+
  [User Browser] ---|---> [Web Server] ---> [App Server] ---> [Database]
                    |         |                  |
                    |         v                  v
                    |    [Static Files]    [Cache (Redis)]
                    +---------------------------------+
                           |
                           v
                    [External Auth Provider]
给每个元素标注:
  • 进程(圆形/矩形):Web服务器、应用服务器、后台任务
  • 数据存储(平行线条):数据库、缓存、文件系统、消息队列
  • 数据流(箭头):HTTP请求、数据库查询、API调用
  • 外部实体(矩形):用户、第三方服务、管理员
  • 信任边界(虚线):网络分段、进程边界

Step 2: Identify Trust Boundaries

步骤2:识别信任边界

Trust boundaries exist where data crosses between different trust levels:
  • Internet to DMZ (user requests entering the network).
  • DMZ to internal network (web server to application server).
  • Application to database (app server to data store).
  • Service to service (between microservices).
  • User privilege levels (regular user vs admin).
Every trust boundary crossing is a potential attack point.
当数据在不同信任等级的区域间流转时,就存在信任边界:
  • 公网到DMZ区(用户请求进入内部网络)
  • DMZ区到内部网络(Web服务器到应用服务器)
  • 应用到数据库(应用服务器到数据存储)
  • 服务到服务(微服务之间的调用)
  • 用户权限等级(普通用户vs管理员)
每一处跨信任边界的流转都是潜在的攻击点。

Step 3: Apply STRIDE to Each Element

步骤3:对每个元素应用STRIDE分析

For each process, data store, and data flow, ask:
  • Spoofing: Can an attacker impersonate a legitimate entity?
  • Tampering: Can data be modified in transit or at rest?
  • Repudiation: Can a user deny performing an action?
  • Info Disclosure: Can sensitive data leak?
  • DoS: Can this component be overwhelmed or crashed?
  • Elevation: Can a user gain higher privileges?
针对每个进程、数据存储和数据流,思考以下问题:
  • 欺骗: 攻击者能否冒充合法实体?
  • 篡改: 传输中或静态存储的数据能否被恶意修改?
  • 抵赖: 用户能否否认自己执行过某个操作?
  • 信息泄露: 敏感数据是否存在泄露风险?
  • 拒绝服务: 该组件能否被打满资源或崩溃?
  • 权限提升: 用户能否获得更高的操作权限?

Step 4: Risk Assessment

步骤4:风险评估

Rate each threat using likelihood and impact:
RatingLikelihoodImpact
HighExploitable with public toolsData breach, full compromise
MediumRequires some skill or accessPartial data exposure, downtime
LowRequires insider access or luckMinor data exposure, degradation
Risk = Likelihood x Impact
Likelihood \ ImpactHighMediumLow
HighCriticalHighMedium
MediumHighMediumLow
LowMediumLowLow
通过发生概率和影响程度为每个威胁评级:
评级发生概率影响程度
利用公开工具即可发起攻击数据泄露、系统完全被接管
需要一定技术能力或访问权限部分数据暴露、服务 downtime
需要内部权限或特殊运气轻微数据暴露、服务性能下降
风险 = 发生概率 × 影响程度
发生概率 \ 影响程度
严重

Step 5: Mitigation Strategies

步骤5:制定缓解策略

For each identified threat, document a mitigation:
STRIDE CategoryCommon Mitigations
SpoofingMFA, certificate pinning, mutual TLS
TamperingDigital signatures, checksums, immutable audit logs
RepudiationAudit logging, tamper-evident logs, digital signatures
Information DisclosureEncryption (TLS, AES), access controls, data masking
Denial of ServiceRate limiting, auto-scaling, CDN, circuit breakers
Elevation of PrivilegeLeast privilege, input validation, sandboxing
为每个识别到的 threat 制定对应的缓解方案:
STRIDE 类别常见缓解措施
欺骗MFA、证书锁定、双向 TLS
篡改数字签名、校验和、不可篡改审计日志
抵赖审计日志、防篡改日志、数字签名
信息泄露加密(TLS、AES)、访问控制、数据脱敏
拒绝服务速率限制、自动扩缩容、CDN、熔断机制
权限提升最小权限原则、输入校验、沙箱隔离

Attack Surface Mapping

攻击面映射

Enumerate all entry points an attacker could use:
  • Network: Open ports, exposed services, public endpoints.
  • Application: API endpoints, file upload, search, user input fields.
  • Authentication: Login, password reset, session management.
  • Data: Database access, file storage, backups, logs.
  • Infrastructure: Cloud console, CI/CD pipeline, container registry.
  • Human: Phishing targets, social engineering, insider threats.
枚举攻击者可能利用的所有入口点:
  • 网络层: 开放端口、暴露的服务、公开端点
  • 应用层: API 端点、文件上传、搜索功能、用户输入字段
  • 认证层: 登录、密码重置、会话管理
  • 数据层: 数据库访问、文件存储、备份、日志
  • 基础设施层: 云控制台、CI/CD 流水线、容器镜像仓库
  • 人员层: 钓鱼目标、社会工程、内部威胁

Output Format

输出格式

Structure threat model output as:
undefined
威胁建模结果按以下结构组织:
undefined

Threat Model: [System Name]

Threat Model: [系统名称]

System Description

系统描述

Brief description of the system and its purpose.
简要说明系统及其用途。

Data Flow Diagram

数据流图

ASCII diagram showing components and trust boundaries.
展示组件和信任边界的ASCII图。

Assets

资产清单

List of valuable data and resources to protect.
需要保护的高价值数据和资源列表。

Threats

威胁列表

IDSTRIDEComponentThreatRiskMitigation
T1SLogin APICredential stuffingHighRate limiting, MFA
T2IDatabaseSQL injection leaks PIICriticalParameterized queries
IDSTRIDE所属组件威胁描述风险等级缓解措施
T1S登录API凭证撞库速率限制、MFA
T2I数据库SQL注入泄露PII严重参数化查询

Recommendations

优化建议

Prioritized list of security improvements.
undefined
按优先级排序的安全改进项列表。
undefined

Examples

示例

Example 1: Threat model a web application

示例1:Web应用威胁建模

User: Create a threat model for our e-commerce application.

Agent: Reads the architecture and codebase, then produces:
  1. Data flow diagram showing: browser -> CDN -> load balancer -> API servers
     -> database / cache / payment gateway. Trust boundaries at each hop.
  2. STRIDE analysis of each component:
     - Spoofing: session hijacking on API server (Medium risk).
     - Tampering: price manipulation in cart requests (High risk).
     - Info Disclosure: PII exposure in error messages (Medium risk).
     - DoS: no rate limiting on search endpoint (High risk).
  3. Risk-prioritized mitigation recommendations.
用户:为我们的电商应用生成威胁模型。

Agent:读取架构和代码库后,输出如下内容:
  1. 数据流图:浏览器 -> CDN -> 负载均衡 -> API 服务器
     -> 数据库 / 缓存 / 支付网关,每一跳都标注信任边界。
  2. 每个组件的STRIDE分析:
     - 欺骗:API服务器的会话劫持风险(中风险)。
     - 篡改:购物车请求中的价格可被篡改(高风险)。
     - 信息泄露:错误信息中暴露PII(中风险)。
     - 拒绝服务:搜索接口无速率限制(高风险)。
  3. 按风险优先级排序的缓解建议。

Example 2: Assess a microservices architecture

示例2:微服务架构安全评估

User: Review our microservices architecture for security threats.

Agent: Maps service communication patterns:
  - Identifies 12 services with 28 inter-service data flows.
  - Trust boundaries: public internet, API gateway, service mesh, database tier.
  - Key findings:
    - 3 services communicate over unencrypted HTTP internally (Tampering, Info Disclosure).
    - No mutual TLS between services (Spoofing).
    - Shared database credentials across services (Elevation of Privilege).
    - No circuit breakers — cascade failure risk (DoS).
  Recommends: service mesh with mTLS, per-service DB credentials, circuit breakers.
用户:评审我们的微服务架构的安全威胁。

Agent:梳理服务通信模式后输出:
  - 识别到12个服务,28条服务间数据流。
  - 信任边界:公网、API网关、服务网格、数据库层。
  - 核心发现:
    - 3个服务内部通过未加密HTTP通信(篡改、信息泄露风险)。
    - 服务之间无双向TLS(欺骗风险)。
    - 多个服务共享数据库凭证(权限提升风险)。
    - 无熔断机制,存在级联故障风险(拒绝服务)。
  建议:引入带mTLS的服务网格、按服务分配独立DB凭证、添加熔断机制。

Example 3: Pre-launch security review

示例3:上线前安全审查

User: We're launching next week. Do a threat model focused on the highest risks.

Agent: Focuses on critical-path components:
  - Payment flow: identifies missing webhook signature verification (Tampering, Critical).
  - User registration: no rate limiting (DoS, High), email enumeration (Info Disclosure).
  - Admin panel: accessible without VPN (Elevation of Privilege, Critical).
  - File uploads: no type validation (Injection via uploaded HTML, High).
  Produces a prioritized punch list:
    1. [Critical] Add webhook signature verification before processing payments.
    2. [Critical] Restrict admin panel to VPN or IP allowlist.
    3. [High] Add rate limiting to registration and login.
    4. [High] Validate file upload types and serve from separate domain.
用户:我们下周要上线,针对最高风险做威胁建模。

Agent:聚焦核心路径组件开展分析:
  - 支付流程:缺少webhook签名校验(篡改风险,严重)。
  - 用户注册:无速率限制(拒绝服务,高),可枚举邮箱(信息泄露)。
  - 管理后台:无需VPN即可访问(权限提升,严重)。
  - 文件上传:无类型校验(可上传HTML实现注入,高)。
  输出优先级整改清单:
    1. [严重] 处理支付前新增webhook签名校验。
    2. [严重] 管理后台仅允许VPN或IP白名单访问。
    3. [高] 注册和登录接口添加速率限制。
    4. [高] 校验文件上传类型,且通过独立域名提供上传文件访问。