SecureCode AI 是一個基於 RAG (Retrieval-Augmented Generation) 技術的程式碼審計工具。它結合了 Google Gemini 的強大語言理解能力與 OWASP Top 10 資安知識庫,能即時分析程式碼中的安全漏洞、評估時間複雜度,並提供自動重構建議。
- 🐛 資安漏洞檢測:自動識別 SQL Injection, XSS, Path Traversal 等常見漏洞 (Mapping to OWASP Top 10)。
- 📉 複雜度分析:計算程式碼的 Big O 時間複雜度,找出潛在的效能瓶頸。
- 🛠️ 自動重構建議:AI 自動生成修復後的安全程式碼片段,並附帶詳細改善說明。
- 💻 現代化 UI:基於 Streamlit 打造的響應式介面,支援語法高亮與動態視覺效果。
建議使用 Python 3.11 版本。
# 建立虛擬環境 (Optional but recommended)
python -m venv venv
# Windows
.\venv\Scripts\activate
# Mac/Linux
source venv/bin/activate
# 安裝相依套件
pip install -r requirements.txt請在專案根目錄建立一個 .env 檔案,並填入您的 Google Gemini API Key: GOOGLE_API_KEY=你的_GOOGLE_API_KEY_這裡 申請Google API(https://aistudio.google.com/app/apikey)
streamlit run app.py
📂 專案結構
Plaintext
SecureCode-AI/
├── knowledge_base # OWAS top10 2021/2025、CWE資料
├── app.py # Streamlit 前端介面主程式
├── check_models.py # 檢查有什麼模型在線
├── create_vector_db.py # 建立向量庫
├── data_ingestion.py # 從網路上下載OWAS top10 2021/2025 md檔案
├── fetch_cwe.py # 將CWE轉成MD格式
├── rag_engine.py # RAG 核心邏輯 (LangChain + Gemini + ChromaDB)
├── requirements.txt # 專案相依套件清單
├── .env # 環境變數 (請勿上傳此檔案)
├── .gitignore # Git 忽略清單
└── README.md # 專案說明文件python create_vector_db.py若knowledge_base無載好的md檔案,需先執行 data_ingestion.py 下載資料然後使用 fetch_cwe.py 將CWE轉為MD格式 再進行上述的 create_vector_db.py
python data_ingestion.py
python fetch_cwe.py.py
python create_vector_db.pyFrontend: Streamlit
LLM Orchestration: LangChain
Model: Google Gemini (via Google AI Studio)
Vector Database: ChromaDB
📝 License This project is licensed under the MIT License.