Sensitive Data Masker
Intelligent sensitive data detection and masking using Microsoft Presidio with SQLite + LRU cache storage.
Features
- - ✅ Intelligent detection - Microsoft Presidio (NLP + rules)
- ✅ Fast storage - SQLite + LRU cache
- ✅ Local restoration - 7-day temporary mapping table
- ✅ Auto cleanup - Expired entries removed automatically
- ✅ 100% local - No external API required
- ✅ OpenClaw Hook - Automatic masking on message received
How It Works
CODEBLOCK0
Detection Types
| Type | Examples | Masked As |
|---|
| PASSWORD | INLINECODE0 | INLINECODE1 |
| API_KEY |
sk-abcdefghijklmnop |
[API_KEY:xxx] |
|
TOKEN |
token=xyz123 |
[TOKEN:xxx] |
|
SECRET |
secret=abc+/== |
[SECRET:xxx] |
|
PRIVATE_KEY |
BEGIN RSA PRIVATE KEY |
[PRIVATE_KEY:xxx] |
|
DB_CONNECTION |
mongodb://user:pass@host |
[DB_CONNECTION:xxx] |
|
EMAIL_ADDRESS |
user@example.com |
[EMAIL_ADDRESS:xxx] |
|
PHONE_NUMBER |
13800138000 |
[PHONE_NUMBER:xxx] |
|
CREDIT_CARD |
4111111111111111 |
[CREDIT_CARD:xxx] |
|
PERSON | John Doe |
[PERSON:xxx] |
|
LOCATION | 123 Main St |
[LOCATION:xxx] |
|
URL |
https://example.com |
[URL:xxx] |
Installation
CODEBLOCK1
Usage Examples
User sends:
CODEBLOCK2
Masked (to API):
CODEBLOCK3
Mapping stored (7 days):
CODEBLOCK4
Local restoration (for task execution):
CODEBLOCK5
Configuration
File: INLINECODE22
CODEBLOCK6
Management Commands
CODEBLOCK7
Performance
| Operation | Latency |
|---|
| Hot query (cache) | < 0.1ms |
| Cold query (SQLite) |
~0.5ms |
| Write | < 2ms |
| Max records | 100,000+ |
Cache hit rate: > 90% typical
Security Features
- - ✅ File permissions: 600 (owner read/write only)
- ✅ SQLite transaction safety
- ✅ Auto-expiry cleanup
- ✅ LRU cache eviction
- ✅ Local storage only
- ✅ Optional encryption at rest
Architecture
Components
- 1. PresidioDetector - Microsoft Presidio integration
- SensitiveMappingStore - SQLite + LRU cache
- ChannelSensitiveMasker - Main masking logic
- OpenClaw Hook - Gateway integration
Database Schema
CODEBLOCK8
Files
CODEBLOCK9
Version History
v1.0.0 (2026-03-03)
- - Initial release
- Microsoft Presidio integration
- SQLite + LRU cache storage
- OpenClaw Hook support
- 7-day TTL mapping table
- Auto cleanup
Repository
Source: https://gitee.com/subline/onepeace/tree/develop/src/skills/sensitive-data-masker
License: MIT
Author: TK
Issues: https://gitee.com/subline/onepeace/issues
Credits
- - Microsoft Presidio - https://github.com/microsoft/presidio
- spaCy - https://spacy.io/
- OpenClaw - https://github.com/openclaw/openclaw
Related Skills
- -
ssh-batch-manager - Batch SSH key management - INLINECODE24 - Security hardening and audits
- INLINECODE25 - Create new skills
敏感数据掩码器
使用Microsoft Presidio结合SQLite + LRU缓存存储的智能敏感数据检测与掩码工具。
功能特性
- - ✅ 智能检测 - Microsoft Presidio(NLP + 规则引擎)
- ✅ 快速存储 - SQLite + LRU缓存
- ✅ 本地还原 - 7天临时映射表
- ✅ 自动清理 - 过期条目自动删除
- ✅ 100%本地化 - 无需外部API
- ✅ OpenClaw钩子 - 接收消息时自动掩码
工作原理
用户消息
↓
渠道插件(飞书/Telegram等)
↓
OpenClaw网关(message:received)
↓
敏感数据掩码器钩子 ← 在此拦截
↓
Presidio检测(NLP + 规则)
↓
SQLite + 缓存存储映射
↓
掩码后的消息
↓
发送至LLM API(安全)
↓
任务执行前还原
↓
使用原始数据执行
检测类型
| 类型 | 示例 | 掩码后显示 |
|---|
| PASSWORD | password=MySecret123 | [PASSWORD:xxx] |
| APIKEY |
sk-abcdefghijklmnop | [APIKEY:xxx] |
|
TOKEN | token=xyz123 | [TOKEN:xxx] |
|
SECRET | secret=abc+/== | [SECRET:xxx] |
|
PRIVATEKEY | BEGIN RSA PRIVATE KEY | [PRIVATEKEY:xxx] |
|
DBCONNECTION | mongodb://user:pass@host | [DBCONNECTION:xxx] |
|
EMAILADDRESS | user@example.com | [EMAILADDRESS:xxx] |
|
PHONENUMBER | 13800138000 | [PHONENUMBER:xxx] |
|
CREDITCARD | 4111111111111111 | [CREDITCARD:xxx] |
|
PERSON | 张三 | [PERSON:xxx] |
|
LOCATION | 北京市朝阳区 | [LOCATION:xxx] |
|
URL | https://example.com | [URL:xxx] |
安装指南
bash
安装依赖
pip install presidio-analyzer presidio-anonymizer
python3 -m spacy download zh
coreweb_sm
启用钩子
openclaw hooks enable sensitive-data-masker
验证安装
openclaw hooks check
使用示例
用户发送:
我的密码是MySecret123,邮箱是user@example.com
掩码后(发送至API):
我的密码是[PASSWORD:f2ae1ea6],邮箱是[EMAIL_ADDRESS:96770696]
存储的映射(保留7天):
json
{
f2ae1ea6: password=MySecret123,
96770696: user@example.com
}
本地还原(用于任务执行):
我的密码是MySecret123,邮箱是user@example.com
配置说明
文件路径: ~/.openclaw/data/sensitive-masker/config.json
json
{
enabled: true,
ttl_days: 7,
cache_size: 1000,
auto_cleanup: true,
cleanupintervalhours: 1,
log_enabled: true,
encrypt_storage: false,
presidio: {
language: zh,
entities: [PHONENUMBER, EMAILADDRESS, ...],
custom_patterns: true
}
}
管理命令
bash
测试掩码功能
python3 sensitive-masker.py test my password=123
查看统计信息
python3 sensitive-masker.py stats
清理过期数据
python3 sensitive-masker.py cleanup
清除所有映射
python3 sensitive-masker.py clear
性能指标
| 操作 | 延迟 |
|---|
| 热查询(缓存) | < 0.1ms |
| 冷查询(SQLite) |
~0.5ms |
| 写入操作 | < 2ms |
| 最大记录数 | 100,000+ |
缓存命中率: 典型场景 > 90%
安全特性
- - ✅ 文件权限:600(仅所有者读写)
- ✅ SQLite事务安全
- ✅ 自动过期清理
- ✅ LRU缓存淘汰机制
- ✅ 仅本地存储
- ✅ 可选静态加密
架构设计
组件构成
- 1. PresidioDetector - Microsoft Presidio集成
- SensitiveMappingStore - SQLite + LRU缓存
- ChannelSensitiveMasker - 核心掩码逻辑
- OpenClaw钩子 - 网关集成
数据库结构
sql
CREATE TABLE mappings (
mask_id TEXT PRIMARY KEY,
original TEXT NOT NULL,
data_type TEXT NOT NULL,
createdat TIMESTAMP DEFAULT CURRENTTIMESTAMP,
expires_at TIMESTAMP NOT NULL,
usage_count INTEGER DEFAULT 0
);
CREATE INDEX idxexpiresat ON mappings(expires_at);
CREATE INDEX idxdatatype ON mappings(data_type);
文件结构
sensitive-data-masker/
├── SKILL.md # 本文件(英文版)
├── SKILL.md # 中文版
├── sensitive-masker.py # 核心脚本
├── handler.js # OpenClaw钩子
├── masker-wrapper.py # Python封装器
├── DESIGN.md # 设计文档
├── README.md # 用户指南
├── RESEARCH-EXISTING-SOLUTIONS.md # 市场调研
└── _meta.json # 元数据
版本历史
v1.0.0(2026-03-03)
- - 初始版本发布
- Microsoft Presidio集成
- SQLite + LRU缓存存储
- OpenClaw钩子支持
- 7天TTL映射表
- 自动清理功能
仓库信息
源码地址: https://gitee.com/subline/onepeace/tree/develop/src/skills/sensitive-data-masker
许可证: MIT
作者: TK
问题反馈: https://gitee.com/subline/onepeace/issues
致谢
- - Microsoft Presidio - https://github.com/microsoft/presidio
- spaCy - https://spacy.io/
- OpenClaw - https://github.com/openclaw/openclaw
相关技能
- - ssh-batch-manager - 批量SSH密钥管理
- healthcheck - 安全加固与审计
- skill-creator - 创建新技能