360 Secure SkillHub
360 安全技能中心

TOTP

使用 otplib 生成 TOTP 密钥与二维码,并在执行敏感操作(读取 .env、openclaw.json、网关重启、备份删除、关键配置变更等)前校验用户提供的 6 位动态口令;窗口 2(约 1 分钟容差),校验通过才继续,失败则拒绝。

diegofcornejo
diegofcornejo
热度 63.65
最近更新 2026-10-01 03:31:50
分类:安全依赖:代码执行 / 读写文件应用场景:自动化脚本 / 工作流 / DevOps

安装技能

复制下面的话术发给你的 Agent,它会通过 secure-skills 检索并安装该技能。

执行命令安装此 skill: npx secure-skills-cli add totp
Metadata
name
totp
description
TOTP-based OTP verification for sensitive operations (env vars, gateway restarts, backup deletions, critical config changes). Uses otplib with window:2 (1 minute tolerance).
metadata
{"openclaw":{"requires":{"env":["TOTP_SECRET"],"bins":["node"]},"primaryEnv":"TOTP_SECRET","emoji":"🔐"}}

TOTP Verification Skill

Secure OTP verification using TOTP (Time-based One-Time Password) for sensitive operations.

Purpose

Protect access to:

  • .env variables
  • openclaw.json configuration
  • Gateway restarts
  • Backup deletions
  • Critical configuration changes
  • External API key operations

Setup

  1. Install dependencies:

    npm install
    
  2. Generate secret and QR:

    npm run generate
    

    Optionally pass service and account name:

    node scripts/generate-secret.js MyService myuser
    
  3. Send the QR image (qr.png) to the user, then delete it immediately:

    rm qr.png
    
  4. Set TOTP_SECRET in .env:

    TOTP_SECRET=YOUR_BASE32_SECRET_HERE
    
  5. Configure Google Authenticator/Authy with the generated secret or QR.

Usage

When a sensitive operation is requested:

  1. Agent: "Please provide your OTP"
  2. User: Provides 6-digit code from authenticator app
  3. Agent: Runs verification:
    TOTP_SECRET=$TOTP_SECRET node scripts/verify.js 123456
    
  4. If valid (exit 0): Proceed with operation
  5. If invalid (exit 1): Deny access

Files

  • scripts/generate-secret.js - Generate new TOTP secret and QR
  • scripts/verify.js - Verify OTP tokens (window:2 = 1 minute tolerance)
  • SKILL.md - This documentation

Security Notes

  • Window: 2 (1 minute tolerance) for time drift
  • Algorithm: SHA1
  • Digits: 6
  • Period: 30 seconds
  • Secret: Base32 encoded, stored in .env as TOTP_SECRET

Integration

This skill should be integrated into the agent's decision flow when:

  1. User requests .env variables
  2. User requests openclaw.json contents
  3. User requests gateway restart
  4. User requests backup deletion
  5. Any operation marked as "critical"