← 中文资源

简体中文版本

把威胁映射到 STRIDE 类别

依据描述中的主导信号,把每条威胁陈述归入 STRIDE 类别,无法识别的标记为未分类。

阅读英文原文

任务

按规则顺序逐条匹配关键词,命中第一个即归类;全部未命中的威胁标为 unclassified。

契约

  • 输入:JSON 对象:{ threats: string[] }
  • 输出:JSON 对象数组:[{ description, category }],保持输入顺序

样例

  1. 输入 {"threats":["An attacker spoofs a service token","A user escalates to admin","A log entry is deleted after an action"]} -> 期望 [{"description":"An attacker spoofs a service token","category":"spoofing"},{"description":"A user escalates to admin","category":"elevation-of-privilege"},{"description":"A log entry is deleted after an action","category":"repudiation"}]。每条陈述的措辞都点明了被破坏的属性。
  2. 输入 {"threats":["Traffic floods the login endpoint","An intern reads another tenant report"]} -> 期望 [{"description":"Traffic floods the login endpoint","category":"denial-of-service"},{"description":"An intern reads another tenant report","category":"information-disclosure"}]。洪泛属于可用性,跨租户读取属于信息泄露。

参考实现

function solve({ threats }) {
      const rules = [
        [/spoof|impersonat/i, 'spoofing'],
        [/tamper|modif/i, 'tampering'],
        [/repudiat|log (entry|record).*(delet|remov)|denies/i, 'repudiation'],
        [/disclos|leak|expos|reads another/i, 'information-disclosure'],
        [/denial|flood|dos|outage|exhaust/i, 'denial-of-service'],
        [/privilege|escalat|admin/i, 'elevation-of-privilege'],
      ];
      return threats.map((description) => {
        const rule = rules.find(([re]) => re.test(description));
        return { description, category: rule ? rule[1] : 'unclassified' };
      });
    }

为什么有效

把每个风险都当作泛泛而谈时,威胁建模就会卡住。STRIDE 类别迫使团队追问:系统的哪个属性真的被破坏了。

规则是定序的,第一个命中的信号生效;未命中的威胁不得被强行归类。