nguyenchaukiet290905/guardagent

GitHub: nguyenchaukiet290905/guardagent

GuardAgent 是一个轻量级 AI 安全学习项目,通过基于规则的安全引擎检测 Prompt Injection 攻击和敏感 API Key 泄露。

Stars: 0 | Forks: 0

# 🛡️ GuardAgent ## 概述 GuardAgent 是一个极简的 AI Security 学习项目,专注于保护 AI 应用程序免受常见安全威胁的侵害。 当前的实现提供了一个简单的基于规则的安全引擎,能够检测: - Prompt Injection 攻击 - 敏感 API Key 泄露 本项目作为 AI Security 学习路线图的一部分,正在逐步开发中。 ## 功能 - ✅ Prompt Injection 检测 - ✅ API Key 泄露检测 - ✅ 基于规则的检测引擎 - ✅ 基于 Regex 的模式匹配 ## 项目结构 ``` guardagent/ │ ├── app/ │ ├── __init__.py │ └── security_engine.py │ ├── tests/ │ ├── __init__.py │ └── test_security_engine.py │ ├── logs/ ├── notes/ │ ├── README.md ├── requirements.txt └── .gitignore ``` ## 安全引擎 当前功能 ``` detect_leakage(text: str) -> bool detect_injection(text: str) -> bool ``` ### Prompt Injection 检测 该引擎检测常见的越狱关键词,例如: - ignore previous instructions - system prompt - developer message - forget all previous ### 敏感数据泄露检测 该引擎使用 Regular Expressions 检测 OpenAI API Keys。 Regex 模式: ``` sk-[a-zA-Z0-9]{48} ``` ## 示例 ``` from app.security_engine import ( detect_injection, detect_leakage, ) detect_injection( "Ignore previous instructions." ) detect_leakage( "sk-abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGH1234" ) ``` ## 技术栈 | 技术 | 用途 | |------------|---------| | Python 3.13+ | 核心编程语言 | | Regular Expressions | API Key 检测 | | 基于规则的逻辑 | Prompt Injection 检测 | ## 威胁模型 | 威胁 | 检测方法 | |---------|------------------| | Prompt Injection | 关键词匹配 | | API Key 泄露 | Regular Expression | ## 路线图 - [x] Prompt Injection 检测 - [x] API Key 泄露检测 - [ ] FastAPI 集成 - [ ] Pydantic 验证 - [ ] 结构化 JSON 日志 - [ ] 使用 Pytest 进行自动化测试 - [ ] Docker 支持 ## 运行 克隆仓库 ``` git clone https://github.com//guardagent.git ``` 进入项目 ``` cd guardagent ``` 运行应用程序 ``` python app/security_engine.py ``` ## 未来改进 - FastAPI REST API - JSON 结构化日志 - 安全的异常处理 - Docker 容器 - 自动化安全测试 ## 作者 **Nguyen Kiet** IT 学生 – 胡志明市工业与贸易大学 (HUIT) AI Security 学习项目 (2026)
标签:API密钥保护, Python, 云计算, 人工智能安全, 合规性, 提示注入, 数据泄露防护, 无后门, 网络探测, 规则引擎, 集群管理