Security Checker
Security scan Python skills before publishing to ensure code safety.
Quick Start
CODEBLOCK0
Examples:
CODEBLOCK1
What It Checks
Dangerous Imports
Detects imports that could be used maliciously:
- -
os - System-level operations - INLINECODE1 - Command execution
- INLINECODE2 - File operations
- INLINECODE3 - Network operations
- INLINECODE4 /
requests - HTTP requests
Why dangerous? These imports enable system command execution, file manipulation, and network access that could be exploited.
Dangerous Functions
Detects potentially unsafe function calls:
- -
os.system() - Executes shell commands - INLINECODE7 ,
subprocess.run(), subprocess.Popen() - Command execution - INLINECODE10 - Executes arbitrary code
- INLINECODE11 - Executes arbitrary code
Why dangerous? These can execute arbitrary commands or code, leading to remote code execution vulnerabilities.
Hardcoded Secrets
Detects tokens, keys, and passwords:
- - API keys
- Auth tokens (including ClawHub tokens)
- Passwords
- Private keys
- JWT-like tokens
Why dangerous? Secrets leaked in published code can be stolen and abused.
Unsafe File Operations
Detects risky file access patterns:
- - Absolute file paths outside expected directories
- Parent directory traversal (
..) - Writing to system directories
Why dangerous? Could lead to unintended file access, data loss, or system modification.
Usage Pattern: Pre-Publish Checklist
Before publishing any skill:
CODEBLOCK2
Interpretation of Results
✅ "No security issues found"
Code appears safe. Proceed with publishing.
⚠️ "Warning" (Yellow)
Potentially risky pattern detected. Review the specific line and decide:
- - Is it legitimate? Document why in code comments or SKILL.md
- Can it be avoided? Refactor to safer alternatives
- Is it necessary? Clearly document the risk and purpose
🔴 "Possible hardcoded secret"
Secret detected. Before publishing:
- - Remove the secret
- Use environment variables instead: INLINECODE13
- Document required env variables in SKILL.md
- Never commit real secrets
Examples
Legitimate os module usage (documented)
CODEBLOCK3
Scan result: ⚠️ Warning about os import
Action: Document safe usage pattern in code comments
Hardcoded secret (must fix)
CODEBLOCK4
Scan result: 🔴 Possible hardcoded secret
Action: Remove and use environment variable:
CODEBLOCK5
Safe pattern (no issues)
CODEBLOCK6
Scan result: ✅ No issues
Best Practices
- 1. Always scan before publishing - Make it part of your workflow
- Review warnings manually - The scanner can't judge context
- Use environment variables for secrets - Never hardcode
- Prefer json over eval - Safe parsing vs code execution
- Document necessary risks - If dangerous code is required, explain why
- Minimize dangerous imports - Only use what's truly necessary
- Keep code simple - Complex code is harder to audit
Integration with Development Workflow
Before committing to repo
CODEBLOCK7
Automated pre-publish check
CODEBLOCK8
Limitations
This scanner:
- - Can't judge context - Some dangerous code may be legitimate
- Static analysis only - Doesn't execute code
- Python-focused - Other languages need different tools
- Basic patterns - Sophisticated obfuscation may evade detection
Complement with:
- - Manual code review
- Testing in isolated environment
- Reading through all code before publishing
- Using additional tools:
bandit, INLINECODE15
Trust Building
Publishing skills that pass security scans builds trust in the community:
- - Users know you care about safety
- Your reputation improves
- Skills get adopted more readily
- ClawHub may highlight safe skills
Examples of Published Skills (All Scanned)
CODEBLOCK9
All three skills passed security scans before publishing to ClawHub.
安全检查器
在发布Python技能前进行安全检查,确保代码安全。
快速开始
bash
security_scan.py <文件或目录>
示例:
bash
扫描单个Python文件
security
scan.py scripts/myscript.py
扫描整个技能目录
security_scan.py /path/to/skill-folder
扫描多个技能
security_scan.py skills/
检查内容
危险导入
检测可能被恶意使用的导入:
- - os - 系统级操作
- subprocess - 命令执行
- shutil - 文件操作
- socket - 网络操作
- urllib / requests - HTTP请求
为何危险? 这些导入支持系统命令执行、文件操作和网络访问,可能被利用。
危险函数
检测潜在不安全的函数调用:
- - os.system() - 执行Shell命令
- subprocess.call()、subprocess.run()、subprocess.Popen() - 命令执行
- eval() - 执行任意代码
- exec() - 执行任意代码
为何危险? 这些函数可执行任意命令或代码,导致远程代码执行漏洞。
硬编码密钥
检测令牌、密钥和密码:
- - API密钥
- 认证令牌(包括ClawHub令牌)
- 密码
- 私钥
- JWT类令牌
为何危险? 发布代码中泄露的密钥可能被盗用和滥用。
不安全的文件操作
检测有风险的文件访问模式:
- - 预期目录之外的绝对文件路径
- 父目录遍历(..)
- 写入系统目录
为何危险? 可能导致意外文件访问、数据丢失或系统修改。
使用模式:发布前检查清单
发布任何技能前:
bash
1. 运行安全检查
security_scan.py /path/to/skill
2. 审查所有警告
如果出现警告,修复代码或说明为何安全
3. 修复后重新扫描
security_scan.py /path/to/skill
4. 仅当扫描通过后才发布
clawhub publish /path/to/skill --slug my-skill ...
结果解读
✅ 未发现安全问题
代码看起来安全。可以继续发布。
⚠️ 警告(黄色)
检测到潜在风险模式。审查具体行并决定:
- - 是否合理? 在代码注释或SKILL.md中说明原因
- 能否避免? 重构为更安全的替代方案
- 是否必要? 明确记录风险和目的
🔴 可能包含硬编码密钥
检测到密钥。发布前:
- - 移除密钥
- 改用环境变量:os.getenv(API_KEY)
- 在SKILL.md中记录所需的环境变量
- 切勿提交真实密钥
示例
合理的os模块使用(已记录)
python
import os # 仅用于path.join() - 安全的文件路径构建
workspace = os.path.join(os.path.expanduser(~), .openclaw, workspace)
扫描结果: ⚠️ 关于os导入的警告
操作: 在代码注释中记录安全使用模式
硬编码密钥(必须修复)
python
API_KEY = sk-1234567890abcdef # 不要这样做
扫描结果: 🔴 可能包含硬编码密钥
操作: 移除并使用环境变量:
python
APIKEY = os.getenv(MYSKILLAPIKEY)
在SKILL.md中记录:需要MYSKILLAPI_KEY环境变量
安全模式(无问题)
python
仅用于本地数据的JSON存储
data = {notes: [], metadata: {}}
with open(data.json, w) as f:
json.dump(data, f)
扫描结果: ✅ 无问题
最佳实践
- 1. 发布前始终扫描 - 将其纳入工作流程
- 手动审查警告 - 扫描器无法判断上下文
- 使用环境变量存储密钥 - 切勿硬编码
- 优先使用json而非eval - 安全解析 vs 代码执行
- 记录必要的风险 - 如果需要危险代码,解释原因
- 最小化危险导入 - 仅使用真正必要的内容
- 保持代码简洁 - 复杂代码更难审计
与开发工作流集成
提交到仓库前
bash
预提交钩子概念
python3 /path/to/security_scan.py scripts/
if [ $? -ne 0 ]; then
echo ❌ 安全检查失败。提交前请修复问题。
exit 1
fi
自动化发布前检查
bash
#!/bin/bash
publish-safe.sh
SKILL_PATH=$1
echo 🔒 正在运行安全检查...
python3 /path/to/securityscan.py $SKILLPATH
if [ $? -ne 0 ]; then
echo ❌ 无法发布:安全检查失败
exit 1
fi
echo ✅ 安全检查通过
clawhub publish $SKILL_PATH
局限性
本扫描器:
- - 无法判断上下文 - 某些危险代码可能是合理的
- 仅进行静态分析 - 不执行代码
- 专注于Python - 其他语言需要不同工具
- 基础模式检测 - 复杂的混淆可能逃避检测
补充措施:
- - 手动代码审查
- 在隔离环境中测试
- 发布前通读所有代码
- 使用其他工具:bandit、safety
建立信任
发布通过安全检查的技能有助于在社区中建立信任:
- - 用户知道您关心安全
- 您的声誉得到提升
- 技能更容易被采纳
- ClawHub可能推荐安全技能
已发布技能示例(均已扫描)
bash
research-assistant
security_scan.py /home/ubuntu/.openclaw/workspace/skills/research-assistant
✅ 全部通过
task-runner
security_scan.py /home/ubuntu/.openclaw/workspace/skills/task-runner
✅ 全部通过
security-checker
security_scan.py /home/ubuntu/.openclaw/workspace/skills/security-checker
✅ 全部通过
所有三个技能在发布到ClawHub前均已通过安全检查。