SybilGambleyyu/redactx

GitHub: SybilGambleyyu/redactx

一款零依赖的本地敏感信息脱敏工具,用于在将文本粘贴到 AI 工具或日志之前自动清除密钥、token 和 PII。

Stars: 0 | Forks: 0

# redactx **在将文本粘贴到 AI 工具或日志之前,对其中的密钥、token 和 PII 进行脱敏。** ``` pip install redactx # or: pip install git+https://github.com/SybilGambleyyu/redactx.git # 通过 pipe 传入 context pack ctxpack -b main | redactx > safe-pack.md # redact 文件 redactx .env.sample app.log -o clean.txt -s ``` 与 [ctxpack](https://github.com/SybilGambleyyu/ctxpack) 搭配使用效果极佳:先打包,粘贴前进行脱敏。 ## 可检测内容 | 类型 | 示例 | | --- | --- | | 云服务 / API 密钥 | AWS `AKIA…`、OpenAI `sk-…`、Stripe、Google `AIza…` | | Tokens | GitHub `ghp_` / `github_pat_`、Slack `xox…`、Bearer 标头 | | 凭据 | `PASSWORD=`、`API_KEY:`、`*_SECRET=…` 赋值语句 | | 密钥材料 | PEM 私钥、证书、JWTs | | URLs | `postgres://user:pass@…`、`https://user:pass@host` | | PII | 电子邮件地址(可通过 `--no-email` 保留) | ## 安装 ``` pip install redactx ``` 或从 GitHub 安装: ``` pip install git+https://github.com/SybilGambleyyu/redactx.git ``` 零运行时依赖。需要 Python 3.10+。 ## CLI ``` # CI: 如果 tracked files 中出现 secrets 则失败 redactx --check README.md src/**/* ``` ``` redactx [files...] [-o OUT] [--no-email] [-s] [-q] ``` | 标志 | 含义 | | --- | --- | | `-o FILE` | 将脱敏后的输出写入 FILE | | `--no-email` | 保留电子邮件地址 | | `-s` | 始终将统计信息输出到 stderr | | `-q` | 静默模式(不显示统计信息) | ## 库 ``` from redactx import redact result = redact(open("dump.txt").read()) print(result.text) print(result.counts) # {'github_token': 1, 'assignment_secret': 2, ...} ``` ## 设计 - **保守替换** — 保留键名,清除值。 - **可组合** — 使用 stdin/stdout,可与 ctxpack 在 pipeline 中协同工作。 - **无网络** — 纯本地正则表达式;您的文本永远不会离开本机。 ## 相关推荐 - [ctxpack](https://github.com/SybilGambleyyu/ctxpack) — 打包 git 变更以作为 AI 上下文 - [envmatch](https://github.com/SybilGambleyyu/envmatch) — 验证环境契约 ## 许可证 MIT
标签:Python, 开发辅助工具, 敏感信息脱敏, 数据隐私, 文档结构分析, 无后门, 日志处理, 瑞士军刀, 逆向工具