Oh distributed security design review

From openharmonyinsight/openharmony-skills · View interactive version

Oh distributed security design review is an AI agent skill from the GitHub repository openharmonyinsight/openharmony-skills. OpenHarmony分布式系统安全代码检视专用技能。当用户要求"检视代码安全实现"、"代码安全审查"、"安全代码review"或类似的分布式系统代码安全检视请求时触发。此技能提供18条OpenHarmony分布式业务安全设计规则的详细检视指导,涵盖授权控制、状态机、数据传输、权限管理、可信关系等安全领域。使用此技能可在通用网络安全规则基础上,针对OpenHarmony分布式系统进行专项安全检视。

How to use this skill

Skill file

Code Review Skill for OpenHarmony Distributed System Security

Overview

本技能提供OpenHarmony分布式业务安全代码检视的专业指导,包含18条安全设计规则和对应的检视要点。当检视分布式系统代码安全性时,在通用网络安全规则基础上,使用这些规则进行加强检视。

Trigger Phrases

Code Review Workflow

Step 1: Understand the Code Context

首先理解代码的业务场景和所在模块:

  1. 识别关键模块: 确定代码是否涉及以下模块
  1. 识别业务类型: 判断是否涉及以下安全敏感业务
  1. 确定角色: 识别代码是主体侧(客户端)还是客体侧(服务端)

Step 2: Load Security Rules

根据代码涉及的业务类型,加载security_rules.md中对应的规则:

快速索引关键词:

Step 3: Review Against Security Rules

对每个适用的安全规则,执行以下检视:

  1. 定位相关代码: 使用Grep搜索关键模式

```

Grep patterns examples:

```

  1. 检查实现细节:
  1. 记录发现:

Step 4: Apply General Security Best Practices

除了OpenHarmony特定规则外,还需检查通用安全实践:

  1. 输入验证: 所有外部输入是否经过验证
  2. 错误处理: 敏感操作是否有适当的错误处理
  3. 日志安全: 是否记录了敏感信息
  4. 资源管理: 是否有资源泄漏风险

Step 5: Generate Review Report

生成结构化的安全检视报告,包含:

  1. 执行摘要: 发现的严重安全问题数量和等级
  2. 违规清单: 按严重程度排序的违规项
  3. 规则映射: 每个问题对应的安全规则
  4. 修复建议: 具体的代码修改建议

Common Violation Patterns

Pattern 1: Client-controlled Authorization (违反规则1)

Bad Example:

// 客体侧直接使用主体侧传入的标志控制弹框
void handleAuthRequest(bool showPopup) {
    if (!showPopup) {
        // 直接跳过授权弹框
        grantAccess();
    }
}

Correct Approach:

// 客体侧独立决策是否需要授权
void handleAuthRequest() {
    if (isSystemBusinessAndRegistered()) {
        // 已注册的免授权业务
        grantAccess();
    } else {
        // 默认必须弹框
        showAuthorizationDialog();
    }
}

Pattern 2: Plaintext Sensitive Data (违反规则3)

Bad Example:

// 明文传输PIN码
message.pin_code = userPin;
sendToRemote(message);

Correct Approach:

// 加密后传输
encryptedPin = encryptPin(userPin, sessionKey);
message.encrypted_pin = encryptedPin;
sendToRemote(message);

Pattern 3: Custom Trust Verification (违反规则8)

Bad Example:

// 自行比对账号信息判断可信关系
bool isTrusted() {
    return localAccount == remoteAccount;
}

Correct Approach:

// 依赖HiChain查询
bool isTrusted() {
    CredentialType type = HiChain.queryCredentialType(remoteDevice);
    return type == CredentialType.SAME_ACCOUNT;
}

Pattern 4: Insecure Switch Defaults (违反规则14)

Bad Example:

// 默认值放通
bool enableSecurityCheck = true;  // 默认启用

Correct Approach:

// 默认值禁用
bool enableSecurityCheck = false;  // 默认禁用,需显式启用

Security Rule Categories

1. Authorization & Authentication

2. Data Protection

3. Trust Management

4. State Machine & Process Control

5. Resource Management

6. Code Quality

Example Review Session

User request: "检视这段分布式设备管理代码的安全性"

Review process:

  1. Load security rules → Read security_rules.md
  2. Identify relevant rules → Rules 1, 2, 7, 8, 9, 11 (设备管理相关)
  3. Search code patterns → Grep for authorization, trust, state machine
  4. Check each rule:
  1. Generate report → 列出违规点和修复建议

Tips

  1. Start with keywords: 使用security_rules.md中的关键词快速定位可疑代码
  2. Check both sides: 分布式业务需要同时检查主体侧和客体侧代码
  3. Verify complete flows: 跟踪完整的业务流程,不要只检查单个函数
  4. Consider edge cases: 检查错误处理、超时、重试等边界场景
  5. Review logging: 确保日志中不泄露敏感信息

Resources

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.