英雄之旅安全评估 API——神话框架与 SMB 网络安全的结合

发布: (2025年12月12日 GMT+8 12:45)
6 min read
原文: Dev.to

Source: Dev.to

我构建的内容

Hero’s Journey Security Assessment API 将企业级安全评估转化为面向小型和中型企业的叙事驱动体验。SMB 不再面对令人生畏的合规清单,而是通过一次神话之旅——从“冒险的召唤”到“带着灵药归来”——在构建真实的安全成熟度的同时前进。

问题

美国超过 3300 万家小型企业面临与企业相同的网络威胁(勒索软件、商业邮件诈骗、供应链攻击),但缺乏安全专业知识。现有框架如 NIST CSF 关注合规,而非生存。身兼 IT 部门的店主并不需要一本 400 页的框架——他们需要的是一本指南。

解决方案

将英雄之旅——一种通用的叙事结构——映射到安全运营。每个故事阶段都对应一个 API 端点,用于跟踪进度、为控制项打分,并生成通俗易懂的报告。

安全框架集成

每个旅程阶段对应具体的安全控制(例如,“冒险的召唤” → 资产清单,“跨越门槛” → 多因素认证/备份验证)。MVP 展示了评估工作流;在生产环境中实现时会通过 evidencefindings 字段与实际安全工具集成。这确保了叙事框架不仅是比喻,而是通向真实安全实践的结构化入口。

旅程阶段

  • 冒险的召唤 – 初始安全意识,资产清单
  • 跨越门槛 – 实施首批防护控制
  • 考验、盟友、敌人 – 持续的安全挑战与合作伙伴
  • 考验 – 事件响应准备
  • 带着灵药归来 – 达到安全成熟度,知识已记录

API 文档

  • 基础 URL: https://xdwe-j0cr-uydc.n7e.xano.io/api:wi5rBx5S
  • Swagger 文档: 查看完整文档
  • 速率限制: 由 Xano 平台基础设施管理。演示版已禁用身份验证;生产环境将通过 Xano 内置的用户认证启用 JWT 身份验证。

关键端点

开始新旅程

POST /assessments
Content-Type: application/json
{
  "business_name": "Acme Retail",
  "vertical": "retail",
  "employee_count": 25
}

Response

{
  "business_id": 1,
  "assessment_id": 1,
  "stages": [
    {"stage_name": "call_to_adventure", "score": 0},
    {"stage_name": "crossing_the_threshold", "score": 0},
    {"stage_name": "tests_allies_enemies", "score": 0},
    {"stage_name": "the_ordeal", "score": 0},
    {"stage_name": "return_with_elixir", "score": 0}
  ]
}

生成叙事报告

GET /generate_assessment_report?assessment_id=1

Response

{
  "business": {
    "name": "Acme Retail",
    "vertical": "retail",
    "employee_count": 25
  },
  "narrative_summary": {
    "hero_name": "Acme Retail",
    "current_chapter": "call_to_adventure",
    "stages_completed": 1,
    "overall_score": 75,
    "journey_status": "Apprentice"
  },
  "journey_stages": [...],
  "report_generated_at": 1765346205738
}

旅程状态阈值

  • 新手 – 刚刚开始 (score 

如何自行尝试

  1. 使用 POST /assessments 创建新旅程
  2. 使用 PATCH /journey_stage/{id} 更新阶段分数
  3. 使用 GET /generate_assessment_report 生成叙事报告

我使用的 AI 提示

旅程开始端点提示

Create an API that:

1. Accepts inputs: business_name (text), vertical (text), employee_count (integer)
2. Creates a new business record with those values
3. Creates a new assessment record linked to that business with:
   - current_stage: "call_to_adventure"
   - status: "in_progress"
   - started_at: current timestamp
4. Creates 5 journey_stage records for this assessment:
   - "call_to_adventure" (score: 0)
   - "crossing_the_threshold" (score: 0)
   - "tests_allies_enemies" (score: 0)
   - "the_ordeal" (score: 0)
   - "return_with_elixir" (score: 0)
5. Returns the assessment ID, business ID, and list of journey stages created

报告生成端点提示

Create an API that:

1. Takes assessment_id from the URL path parameter
2. Fetches the assessment record to verify it exists
3. Fetches the business record linked to this assessment
4. Fetches all journey_stage records for this assessment
5. Calculates overall progress:
   - Count stages with score > 0 as "completed"
   - Calculate average score across all stages
6. Generates a narrative summary object with:
   - hero_name: the business name
   - current_chapter: the current_stage from assessment
   - stages_completed: count of stages with score > 0
   - overall_score: average of all stage scores
   - journey_status: "beginning" if avg = 60
7. Returns business info, assessment info, all journey stages, the narrative summary, and timestamp

我如何改进 AI 生成的代码

初始 AI 输出

Xano Logic Assistant 生成了坚实的基础:

  • 具有正确关系的数据库模式(business → assessment → journey_stages)
  • 所有表的 CRUD 端点
  • 用于自定义逻辑的基本函数堆栈

人工改进

  1. 身份验证配置 – 将关键端点改为演示公开,同时保留生产就绪的身份验证设置。

  2. 错误处理 – 添加前置条件以验证评估和企业在处理前是否存在:

    {
      "precondition": "$assessment != null",
      "error_type": "not_found",
      "error": "Assessment not found."
    }
  3. 叙事逻辑 – 用显式条件检查替代导致语法错误的管道过滤器:

    {
      "conditional": {
        "if": "$stage.score > 0",
        "then": {
          "var.update": "stages_completed_count",
          "value": "$stages_completed_count + 1"
        }
      }
    }
  4. 旅程状态阈值 – 将状态标签更新为更符合叙事的术语:新手、学徒、守护者、英雄。

  5. 可维护性设计 – 旅程阶段存储为数据库记录,而非硬编码。可以在不修改代码的情况下添加新阶段;评分阈值和状态标签是可配置变量,使框架具有可扩展性和适应性。

我在 Xano 的体验

有效之处

  • Logic Assistant 节省了大量时间,通过从纯英文描述生成可运行代码。
  • 多步骤工作流
Back to Blog

相关文章

阅读更多 »